aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2010-09-13 19:59:09 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2010-09-13 19:59:09 (GMT)
commitf6af17aa58701cdb579cca52ac83edf289e118e7 (patch)
treeea202347120a614d0e8ee7be23b97d1e81789648 /src
parent24e4e98dbea3952e0a0c02fd940ffbe14df5acb6 (diff)
downloadfluxbox_paul-f6af17aa58701cdb579cca52ac83edf289e118e7.zip
fluxbox_paul-f6af17aa58701cdb579cca52ac83edf289e118e7.tar.bz2
code simplification
Diffstat (limited to 'src')
-rw-r--r--src/fluxbox.cc84
1 files changed, 28 insertions, 56 deletions
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index fbffc92..aabdb04 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -530,37 +530,30 @@ void Fluxbox::ungrab() {
530*/ 530*/
531void Fluxbox::setupConfigFiles() { 531void Fluxbox::setupConfigFiles() {
532 532
533 bool create_init = false, create_keys = false, create_menu = false,
534 create_apps = false, create_overlay = false, create_windowmenu = false;
535
536 string dirname = getDefaultDataFilename(""); 533 string dirname = getDefaultDataFilename("");
537 string init_file = getDefaultDataFilename(m_RC_INIT_FILE);
538 string keys_file = getDefaultDataFilename("keys");
539 string menu_file = getDefaultDataFilename("menu");
540 string apps_file = getDefaultDataFilename("apps");
541 string overlay_file = getDefaultDataFilename("overlay");
542 string windowmenu_file = getDefaultDataFilename("windowmenu");
543
544 struct stat buf;
545 534
546 // is file/dir already there? 535 // is file/dir already there?
547 if (! stat(dirname.c_str(), &buf)) { 536 const bool create_dir = FbTk::FileUtil::isDirectory(dirname.c_str());
548 537
549 // check if anything with those name exists, if not create new 538 struct CFInfo {
550 if (stat(init_file.c_str(), &buf)) 539 bool create_file;
551 create_init = true; 540 const char* default_name;
552 if (stat(keys_file.c_str(), &buf)) 541 const std::string filename;
553 create_keys = true; 542 } cfiles[] = {
554 if (stat(menu_file.c_str(), &buf)) 543 { create_dir, DEFAULT_INITFILE, getDefaultDataFilename(m_RC_INIT_FILE) },
555 create_menu = true; 544 { create_dir, DEFAULTKEYSFILE, getDefaultDataFilename("keys") },
556 if (stat(apps_file.c_str(), &buf)) 545 { create_dir, DEFAULTMENU, getDefaultDataFilename("menu") },
557 create_apps = true; 546 { create_dir, DEFAULT_APPSFILE, getDefaultDataFilename("apps") },
558 if (stat(overlay_file.c_str(), &buf)) 547 { create_dir, DEFAULT_OVERLAY, getDefaultDataFilename("overlay") },
559 create_overlay = true; 548 { create_dir, DEFAULT_WINDOWMENU, getDefaultDataFilename("windowmenu") }
560 if (stat(windowmenu_file.c_str(), &buf)) 549 };
561 create_windowmenu = true; 550 const size_t nr_of_cfiles = sizeof(cfiles)/sizeof(CFInfo);
562 551
563 } else { 552 if (create_dir) { // check if anything with those name exists, if not create new
553 for (size_t i = 0; i < nr_of_cfiles; ++i) {
554 cfiles[i].create_file = access(cfiles[i].filename.c_str(), F_OK);
555 }
556 } else{
564 fbdbg<<"Creating dir: " << dirname.c_str() << endl; 557 fbdbg<<"Creating dir: " << dirname.c_str() << endl;
565 _FB_USES_NLS; 558 _FB_USES_NLS;
566 // create directory with perm 700 559 // create directory with perm 700
@@ -572,35 +565,14 @@ void Fluxbox::setupConfigFiles() {
572 cerr<<endl; 565 cerr<<endl;
573 return; 566 return;
574 } 567 }
575
576 //mark creation of files
577 create_init = create_keys = create_menu = create_apps = create_overlay =
578 create_windowmenu = true;
579 } 568 }
580 569
581 570 // copy default files if needed
582 // copy key configuration 571 for (size_t i = 0; i < nr_of_cfiles; ++i) {
583 if (create_keys) 572 if (cfiles[i].create_file) {
584 FbTk::FileUtil::copyFile(DEFAULTKEYSFILE, keys_file.c_str()); 573 FbTk::FileUtil::copyFile(cfiles[i].default_name, cfiles[i].filename.c_str());
585 574 }
586 // copy menu configuration 575 }
587 if (create_menu)
588 FbTk::FileUtil::copyFile(DEFAULTMENU, menu_file.c_str());
589
590 // copy apps file
591 if (create_apps)
592 FbTk::FileUtil::copyFile(DEFAULT_APPSFILE, apps_file.c_str());
593
594 // copy overlay file
595 if (create_overlay)
596 FbTk::FileUtil::copyFile(DEFAULT_OVERLAY, overlay_file.c_str());
597
598 // copy init file
599 if (create_init)
600 FbTk::FileUtil::copyFile(DEFAULT_INITFILE, init_file.c_str());
601
602 if (create_windowmenu)
603 FbTk::FileUtil::copyFile(DEFAULT_WINDOWMENU, windowmenu_file.c_str());
604 576
605#define CONFIG_VERSION 13 577#define CONFIG_VERSION 13
606 FbTk::Resource<int> config_version(m_resourcemanager, 0, 578 FbTk::Resource<int> config_version(m_resourcemanager, 0,
@@ -609,7 +581,7 @@ void Fluxbox::setupConfigFiles() {
609 // configs are out of date, so run fluxbox-update_configs 581 // configs are out of date, so run fluxbox-update_configs
610 582
611 string commandargs = realProgramName("fluxbox-update_configs"); 583 string commandargs = realProgramName("fluxbox-update_configs");
612 commandargs += " -rc " + init_file; 584 commandargs += " -rc " + cfiles[0].filename;
613 585
614#ifdef HAVE_GETPID 586#ifdef HAVE_GETPID
615 // add the fluxbox pid so fbuc can have us reload rc if necessary 587 // add the fluxbox pid so fbuc can have us reload rc if necessary