settingsimpl.cpp

Go to the documentation of this file.
00001 /*
00002         Description: settings dialog
00003 
00004         Author: Marco Costalba (C) 2005-2006
00005 
00006         Copyright: See COPYING file that comes with this distribution
00007 
00008 */
00009 #include <qlineedit.h>
00010 #include <qcheckbox.h>
00011 #include <qtabwidget.h>
00012 #include <qcombobox.h>
00013 #include <qpushbutton.h>
00014 #include <qtextcodec.h>
00015 #include <qtextedit.h>
00016 #include <qfiledialog.h>
00017 #include <qsettings.h>
00018 #include <qfontdialog.h>
00019 #include "common.h"
00020 #include "git.h"
00021 #include "settingsimpl.h"
00022 
00023 /*
00024 By default, there are two entries in the search path:
00025 
00026    1. SYSCONF - where SYSCONF is a directory specified when configuring Qt;
00027                         by default it is INSTALL/etc/settings.
00028    2. $HOME/.qt/ - where $HOME is the user's home directory.
00029 */
00030 
00031 const char* SettingsImpl::en[] = {"Latin1", "Big5 -- Chinese", "EUC-JP -- Japanese",
00032         "EUC-KR -- Korean", "GB2312 -- Chinese", "GBK -- Chinese",
00033         "ISO-2022-JP -- Japanese", "Shift_JIS -- Japanese", "UTF-8 -- Unicode, 8-bit",
00034         "KOI8-R -- Russian", "KOI8-U -- Ukrainian", "ISO-8859-1 -- Western",
00035         "ISO-8859-2 -- Central European", "ISO-8859-3 -- Central European",
00036         "ISO-8859-4 -- Baltic", "ISO-8859-5 -- Cyrillic", "ISO-8859-6 -- Arabic",
00037         "ISO-8859-7 -- Greek", "ISO-8859-8 -- Hebrew, visually ordered",
00038         "ISO-8859-8-i -- Hebrew, logically ordered", "ISO-8859-9 -- Turkish",
00039         "ISO-8859-10", "ISO-8859-13", "ISO-8859-14", "ISO-8859-15 -- Western", "CP 850",
00040         "IBM 866", "CP 874", "windows-1250 -- Central European", "windows-1251 -- Cyrillic",
00041         "windows-1252 -- Western", "windows-1253 -- Greek", "windows-1254 -- Turkish",
00042         "windows-1255 -- Hebrew", "windows-1256 -- Arabic", "windows-1257 -- Baltic",
00043         "windows-1258", 0};
00044 
00045 using namespace QGit;
00046 
00047 SettingsImpl::SettingsImpl(QWidget* p, Git* g, int defTab) :
00048               settingsBase(p, "", true, Qt::WDestructiveClose), git(g) {
00049 
00050         int f = flags();
00051         checkBoxDiffCache->setChecked(f & DIFF_INDEX_F);
00052         checkBoxNumbers->setChecked(f & NUMBERS_F);
00053         checkBoxSign->setChecked(f & SIGN_PATCH_F);
00054         checkBoxCommitSign->setChecked(f & SIGN_CMT_F);
00055         checkBoxCommitVerify->setChecked(f & VERIFY_CMT_F);
00056         checkBoxRangeSelectDialog->setChecked(f & RANGE_SELECT_F);
00057         checkBoxRelativeDate->setChecked(f & REL_DATE_F);
00058 
00059         QSettings set;
00060         SCRef FPArgs(set.readEntry(APP_KEY + FPATCH_ARGS_KEY, ""));
00061         SCRef extDiff(set.readEntry(APP_KEY + EXT_DIFF_KEY, EXT_DIFF_DEF));
00062         SCRef exFile(set.readEntry(APP_KEY + EX_KEY, EX_DEF));
00063         SCRef exPDir(set.readEntry(APP_KEY + EX_PER_DIR_KEY, EX_PER_DIR_DEF));
00064         SCRef tmplt(set.readEntry(APP_KEY + CMT_TEMPL_KEY, CMT_TEMPL_DEF));
00065         SCRef CMArgs(set.readEntry(APP_KEY + CMT_ARGS_KEY, ""));
00066 
00067         lineEditExtraOptions->setText(FPArgs);
00068         lineEditExternalDiffViewer->setText(extDiff);
00069         lineEditExcludeFile->setText(exFile);
00070         lineEditExcludePerDir->setText(exPDir);
00071         lineEditTemplate->setText(tmplt);
00072         lineEditCommitExtraOptions->setText(CMArgs);
00073         lineEditTypeWriterFont->setText(TYPE_WRITER_FONT.toString());
00074 
00075         setupCodecsCombo();
00076         checkBoxDiffCache_toggled(checkBoxDiffCache->isChecked());
00077         tabDialog->setCurrentPage(defTab);
00078         userInfo();
00079 }
00080 
00081 void SettingsImpl::userInfo() {
00082 /*
00083         QGit::userInfo() returns a QStringList formed by
00084         triples (defined in, user, email)
00085 */
00086         git->userInfo(_uInfo);
00087         if (_uInfo.count() % 3 != 0) {
00088                 dbs("ASSERT in SettingsImpl::userInfo(), bad info returned");
00089                 return;
00090         }
00091         bool found = false;
00092         int idx = 0;
00093         FOREACH_SL(it, _uInfo) {
00094                 comboBoxUserSrc->insertItem(*it);
00095                 ++it;
00096                 if (!found && !(*it).isEmpty())
00097                         found = true;
00098                 if (!found)
00099                         idx++;
00100                 ++it;
00101         }
00102         if (!found)
00103                 idx = 0;
00104 
00105         comboBoxUserSrc->setCurrentItem(idx);
00106         comboBoxUserSrc_activated(idx);
00107 }
00108 
00109 void SettingsImpl::comboBoxUserSrc_activated(int i) {
00110 
00111         lineEditAuthor->setText(_uInfo[i * 3 + 1]);
00112         lineEditMail->setText(_uInfo[i * 3 + 2]);
00113 }
00114 
00115 void SettingsImpl::setupCodecList(QStringList& list) {
00116 
00117         int i = 0;
00118         while (en[i] != 0)
00119                 list.append(QString::fromLatin1(en[i++]));
00120 }
00121 
00122 void SettingsImpl::setupCodecsCombo() {
00123 
00124         const QString localCodec(QTextCodec::codecForLocale()->mimeName());
00125         QStringList codecs;
00126         codecs.append(QString("Local Codec (" + localCodec + ")"));
00127         setupCodecList(codecs);
00128         comboBoxCodecs->insertStringList(codecs);
00129 
00130         bool isGitArchive;
00131         QTextCodec* tc = git->getTextCodec(&isGitArchive);
00132         if (!isGitArchive) {
00133                 comboBoxCodecs->setEnabled(false);
00134                 return;
00135         }
00136         const QString curCodec((tc == 0) ? "Latin1" : tc->mimeName());
00137         if (curCodec == localCodec) {
00138                 comboBoxCodecs->setCurrentItem(0);
00139                 return;
00140         }
00141         int idx = codecs.findIndex(codecs.grep(curCodec, false).first());
00142         if (idx != -1) {
00143                 comboBoxCodecs->setCurrentItem(idx);
00144                 return;
00145         }
00146         dbp("ASSERT: codec <%1> not available, using local codec", curCodec);
00147         comboBoxCodecs->setCurrentItem(0);
00148         comboBoxCodecs_activated(0);
00149 }
00150 
00151 void SettingsImpl::comboBoxCodecs_activated(int idx) {
00152 
00153         QString codecName(QTextCodec::codecForLocale()->mimeName());
00154         if (idx != 0)
00155                 codecName = comboBoxCodecs->currentText().section(" --", 0, 0);
00156 
00157         git->setTextCodec(QTextCodec::codecForName(codecName));
00158 }
00159 
00160 void SettingsImpl::pushButtonExtDiff_clicked() {
00161 
00162         QString extDiffName(QFileDialog::getOpenFileName("", NULL, this, "",
00163                             "Choose the diff viewer - External diff viewer"));
00164         if (!extDiffName.isEmpty())
00165                 lineEditExternalDiffViewer->setText(extDiffName);
00166 }
00167 
00168 void SettingsImpl::pushButtonFont_clicked() {
00169 
00170         bool ok;
00171         QFont fnt = QFontDialog::getFont(&ok, TYPE_WRITER_FONT, this);
00172         if (ok) {
00173                 TYPE_WRITER_FONT = fnt;
00174                 lineEditTypeWriterFont->setText(fnt.toString());
00175                 writeSetting(FONT_KEY, fnt.toString());
00176         }
00177 }
00178 
00179 void SettingsImpl::checkBoxDiffCache_toggled(bool b) {
00180 
00181         lineEditExcludeFile->setEnabled(b);
00182         lineEditExcludePerDir->setEnabled(b);
00183         setFlag(DIFF_INDEX_F, b);
00184 }
00185 
00186 void SettingsImpl::checkBoxNumbers_toggled(bool b) {
00187 
00188         setFlag(NUMBERS_F, b);
00189 }
00190 
00191 void SettingsImpl::checkBoxSign_toggled(bool b) {
00192 
00193         setFlag(SIGN_PATCH_F, b);
00194 }
00195 
00196 void SettingsImpl::checkBoxRangeSelectDialog_toggled(bool b) {
00197 
00198         setFlag(RANGE_SELECT_F, b);
00199 }
00200 
00201 void SettingsImpl::checkBoxRelativeDate_toggled(bool b) {
00202 
00203         setFlag(REL_DATE_F, b);
00204 }
00205 
00206 void SettingsImpl::checkBoxCommitSign_toggled(bool b) {
00207 
00208         setFlag(SIGN_CMT_F, b);
00209 }
00210 
00211 void SettingsImpl::checkBoxCommitVerify_toggled(bool b) {
00212 
00213         setFlag(VERIFY_CMT_F, b);
00214 }
00215 
00216 void SettingsImpl::lineEditExternalDiffViewer_textChanged(const QString& s) {
00217 
00218         writeSetting(EXT_DIFF_KEY, s);
00219 }
00220 
00221 void SettingsImpl::lineEditExtraOptions_textChanged(const QString& s) {
00222 
00223         writeSetting(FPATCH_ARGS_KEY, s);
00224 }
00225 
00226 void SettingsImpl::lineEditExcludeFile_textChanged(const QString& s) {
00227 
00228         writeSetting(EX_KEY, s);
00229 }
00230 
00231 void SettingsImpl::lineEditExcludePerDir_textChanged(const QString& s) {
00232 
00233         writeSetting(EX_PER_DIR_KEY, s);
00234 }
00235 
00236 void SettingsImpl::lineEditTemplate_textChanged(const QString& s) {
00237 
00238         writeSetting(CMT_TEMPL_KEY, s);
00239 }
00240 
00241 void SettingsImpl::lineEditCommitExtraOptions_textChanged(const QString& s) {
00242 
00243         writeSetting(CMT_ARGS_KEY, s);
00244 }

Generated on Fri Dec 7 21:57:38 2007 for QGit by  doxygen 1.5.3