~paulbrianstewart/ubuntu/oneiric/tellico/852247-Formatting-Fix

« back to all changes in this revision

Viewing changes to src/configdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-31 19:33:05 UTC
  • mfrom: (0.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080131193305-9l01m5gfhykl6pkl
Tags: 1.3-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: build-dep on kdepim-dev
  - debian/control: drop versioned python from tellico-data suggests
  - debian/rules: call dh_icons

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "gui/combobox.h"
29
29
#include "gui/previewdialog.h"
30
30
#include "newstuff/dialog.h"
 
31
#include "../tellico_debug.h"
31
32
 
32
33
#include <klineedit.h>
33
34
#include <klocale.h>
59
60
#include <qvbox.h>
60
61
#include <qhbox.h>
61
62
#include <qfileinfo.h>
 
63
#include <qradiobutton.h>
 
64
#include <qvbuttongroup.h>
62
65
 
63
66
namespace {
64
67
  static const int CONFIG_MIN_WIDTH = 640;
99
102
ConfigDialog::ConfigDialog(QWidget* parent_, const char* name_/*=0*/)
100
103
    : KDialogBase(IconList, i18n("Configure Tellico"), Help|Ok|Apply|Cancel|Default,
101
104
                  Ok, parent_, name_, true, false)
102
 
    , m_modifying(false) {
 
105
    , m_modifying(false)
 
106
    , m_okClicked(false) {
103
107
  setupGeneralPage();
104
108
  setupPrintingPage();
105
109
  setupTemplatePage();
163
167
}
164
168
 
165
169
void ConfigDialog::slotOk() {
 
170
  m_okClicked = true;
166
171
  slotApply();
167
172
  accept();
 
173
  m_okClicked = false;
168
174
}
169
175
 
170
176
void ConfigDialog::slotApply() {
192
198
  QFrame* frame = addPage(i18n("General"), i18n("General Options"), pix);
193
199
  QVBoxLayout* l = new QVBoxLayout(frame, KDialog::marginHint(), KDialog::spacingHint());
194
200
 
195
 
  m_cbWriteImagesInFile = new QCheckBox(i18n("&Include images in data file"), frame);
196
 
  QWhatsThis::add(m_cbWriteImagesInFile, i18n("If checked, all images will be included in the data file, "
197
 
                                              "rather than saved separately in the Tellico data directory. "
198
 
                                              "Saving a lot of images in the data file cause Tellico to "
199
 
                                              "run more slowly."));
200
 
  l->addWidget(m_cbWriteImagesInFile);
201
 
  connect(m_cbWriteImagesInFile, SIGNAL(clicked()), SLOT(slotModified()));
202
 
 
203
201
  m_cbOpenLastFile = new QCheckBox(i18n("&Reopen file at startup"), frame);
204
202
  QWhatsThis::add(m_cbOpenLastFile, i18n("If checked, the file that was last open "
205
203
                                         "will be re-opened at program start-up."));
212
210
  l->addWidget(m_cbShowTipDay);
213
211
  connect(m_cbShowTipDay, SIGNAL(clicked()), SLOT(slotModified()));
214
212
 
 
213
  QButtonGroup* imageGroup = new QVButtonGroup(i18n("Image Storage Options"), frame);
 
214
  m_rbImageInFile = new QRadioButton(i18n("Store images in data file"), imageGroup);
 
215
  m_rbImageInAppDir = new QRadioButton(i18n("Store images in common application directory"), imageGroup);
 
216
  m_rbImageInLocalDir = new QRadioButton(i18n("Store images in directory relative to data file"), imageGroup);
 
217
  QWhatsThis::add(imageGroup, i18n("Images may be saved in the data file itself, which can "
 
218
                                   "cause Tellico to run slowly, stored in the Tellico "
 
219
                                   "application directory, or stored in a directory in the "
 
220
                                   "same location as the data file."));
 
221
  l->addWidget(imageGroup);
 
222
  connect(imageGroup, SIGNAL(clicked(int)), SLOT(slotModified()));
 
223
 
215
224
  QVGroupBox* formatGroup = new QVGroupBox(i18n("Formatting Options"), frame);
216
225
  l->addWidget(formatGroup);
217
226
 
565
574
 
566
575
void ConfigDialog::readGeneralConfig() {
567
576
  m_cbShowTipDay->setChecked(Config::showTipOfDay());
568
 
  m_cbWriteImagesInFile->setChecked(Config::writeImagesInFile());
569
577
  m_cbOpenLastFile->setChecked(Config::reopenLastFile());
 
578
  switch(Config::imageLocation()) {
 
579
    case Config::ImagesInFile: m_rbImageInFile->setChecked(true); break;
 
580
    case Config::ImagesInAppDir: m_rbImageInAppDir->setChecked(true); break;
 
581
    case Config::ImagesInLocalDir: m_rbImageInLocalDir->setChecked(true); break;
 
582
  }
570
583
 
571
584
  bool autoCapitals = Config::autoCapitalization();
572
585
  m_cbCapitalize->setChecked(autoCapitals);
623
636
      // there's weird layout bug if it's not hidden
624
637
      cw->hide();
625
638
    }
 
639
    kapp->processEvents();
626
640
  }
627
641
 
628
642
  if(m_sourceListView->childCount() == 0) {
637
651
void ConfigDialog::saveConfiguration() {
638
652
  Config::setShowTipOfDay(m_cbShowTipDay->isChecked());
639
653
 
640
 
  Config::setWriteImagesInFile(m_cbWriteImagesInFile->isChecked());
 
654
  int imageLocation;
 
655
  if(m_rbImageInFile->isChecked()) {
 
656
    imageLocation = Config::ImagesInFile;
 
657
  } else if(m_rbImageInAppDir->isChecked()) {
 
658
    imageLocation = Config::ImagesInAppDir;
 
659
  } else {
 
660
    imageLocation = Config::ImagesInLocalDir;
 
661
  }
 
662
  Config::setImageLocation(imageLocation);
641
663
  Config::setReopenLastFile(m_cbOpenLastFile->isChecked());
642
664
 
643
665
  Config::setAutoCapitalization(m_cbCapitalize->isChecked());
674
696
  }
675
697
  m_removedConfigWidgets.clear();
676
698
 
677
 
  KConfig* config = KGlobal::config();
 
699
  KConfig* masterConfig = KGlobal::config();
678
700
 
679
701
  bool reloadFetchers = false;
680
702
  int count = 0; // start group numbering at 0
687
709
    m_newStuffConfigWidgets.removeRef(cw);
688
710
    QString group = QString::fromLatin1("Data Source %1").arg(count);
689
711
    // in case we later change the order, clear the group now
690
 
    config->deleteGroup(group);
691
 
    KConfigGroupSaver saver(config, group);
692
 
    config->writeEntry("Name", item->text(0));
693
 
    config->writeEntry("Type", item->fetchType());
694
 
    config->writeEntry("UpdateOverwrite", item->updateOverwrite());
695
 
    cw->saveConfig(config);
 
712
    masterConfig->deleteGroup(group);
 
713
    KConfigGroup configGroup(masterConfig, group);
 
714
    configGroup.writeEntry("Name", item->text(0));
 
715
    configGroup.writeEntry("Type", item->fetchType());
 
716
    configGroup.writeEntry("UpdateOverwrite", item->updateOverwrite());
 
717
    cw->saveConfig(configGroup);
696
718
    item->setNewSource(false);
697
719
    // in case the ordering changed
698
720
    item->setConfigGroup(group);
699
721
    reloadFetchers = true;
700
722
  }
701
723
  // now update total number of sources
702
 
  config->setGroup("Data Sources");
703
 
  config->writeEntry("Sources Count", count);
 
724
  KConfigGroup sourceGroup(masterConfig, "Data Sources");
 
725
  sourceGroup.writeEntry("Sources Count", count);
704
726
  // and purge old config groups
705
727
  QString group = QString::fromLatin1("Data Source %1").arg(count);
706
 
  while(config->hasGroup(group)) {
707
 
    config->deleteGroup(group);
 
728
  while(masterConfig->hasGroup(group)) {
 
729
    masterConfig->deleteGroup(group);
708
730
    ++count;
709
731
    group = QString::fromLatin1("Data Source %1").arg(count);
710
732
  }
711
733
 
712
 
  config->sync();
 
734
  masterConfig->sync();
713
735
  Config::writeConfig();
714
736
 
715
737
  QString s = m_sourceListView->selectedItem() ? m_sourceListView->selectedItem()->text(0) : QString();
716
738
  if(reloadFetchers) {
717
739
    Fetch::Manager::self()->loadFetchers();
718
740
    Controller::self()->updatedFetchers();
719
 
    // reload fetcher items
720
 
    readFetchConfig();
721
 
    if(!s.isEmpty()) {
722
 
      for(QListViewItemIterator it(m_sourceListView); it.current(); ++it) {
723
 
        if(it.current()->text(0) == s) {
724
 
          m_sourceListView->setSelected(it.current(), true);
725
 
          m_sourceListView->ensureItemVisible(it.current());
726
 
          break;
 
741
    // reload fetcher items if OK was not clicked
 
742
    // meaning apply was clicked
 
743
    if(!m_okClicked) {
 
744
      readFetchConfig();
 
745
      if(!s.isEmpty()) {
 
746
        for(QListViewItemIterator it(m_sourceListView); it.current(); ++it) {
 
747
          if(it.current()->text(0) == s) {
 
748
            m_sourceListView->setSelected(it.current(), true);
 
749
            m_sourceListView->ensureItemVisible(it.current());
 
750
            break;
 
751
          }
727
752
        }
728
753
      }
729
754
    }