00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <gui/common/vmessagebox.h>
00029 #include <vidalia.h>
00030
00031 #include "configdialog.h"
00032
00033 #define FONT QFont(tr("Arial"), 10)
00034
00035
00036 #define IMAGE_GENERAL ":/images/22x22/preferences-system.png"
00037 #define IMAGE_SERVER ":/images/22x22/network-server.png"
00038 #define IMAGE_APPEARANCE ":/images/22x22/preferences-desktop-locale.png"
00039 #define IMAGE_ADVANCED ":/images/22x22/emblem-system.png"
00040 #define IMAGE_SAVE ":/images/22x22/media-floppy.png"
00041 #define IMAGE_CANCEL ":/images/22x22/emblem-unreadable.png"
00042 #define IMAGE_HELP ":/images/22x22/help-browser.png"
00043
00044
00045 ConfigDialog::ConfigDialog(QWidget* parent)
00046 : VidaliaWindow("ConfigDialog", parent)
00047 {
00048 QAction *helpAct, *saveAct, *cancelAct;
00049
00050
00051 ui.setupUi(this);
00052
00053
00054 QActionGroup *grp = new QActionGroup(this);
00055 ui.stackPages->add(new GeneralPage(ui.stackPages),
00056 createPageAction(QIcon(IMAGE_GENERAL), tr("General"), grp));
00057
00058 ui.stackPages->add(new ServerPage(ui.stackPages),
00059 createPageAction(QIcon(IMAGE_SERVER), tr("Server"), grp));
00060
00061 ui.stackPages->add(new AppearancePage(ui.stackPages),
00062 createPageAction(QIcon(IMAGE_APPEARANCE), tr("Appearance"), grp));
00063
00064 ui.stackPages->add(new AdvancedPage(ui.stackPages),
00065 createPageAction(QIcon(IMAGE_ADVANCED), tr("Advanced"), grp));
00066
00067
00068 ui.toolBar->addActions(grp->actions());
00069 ui.toolBar->addSeparator();
00070 connect(grp, SIGNAL(triggered(QAction *)), ui.stackPages, SLOT(showPage(QAction *)));
00071
00072
00073
00074 helpAct = new QAction(QIcon(IMAGE_HELP), tr("Help"), ui.toolBar);
00075 addAction(helpAct, SLOT(help()));
00076
00077
00078 saveAct = new QAction(QIcon(IMAGE_SAVE), tr("Save"), ui.toolBar);
00079 saveAct->setShortcut(QString("Ctrl+S"));
00080 addAction(saveAct, SLOT(saveChanges()));
00081
00082
00083 cancelAct = new QAction(QIcon(IMAGE_CANCEL), tr("Cancel"), ui.toolBar);
00084 addAction(cancelAct, SLOT(close()));
00085
00086
00087 grp->actions()[0]->setChecked(true);
00088
00089 #if defined(Q_WS_WIN)
00090 helpAct->setShortcut(QString("F1"));
00091 cancelAct->setShortcut(QString("Esc"));
00092 #else
00093 helpAct->setShortcut(QString("Ctrl+?"));
00094 cancelAct->setShortcut(QString("Ctrl+W"));
00095 #endif
00096 }
00097
00098
00099 QAction*
00100 ConfigDialog::createPageAction(QIcon img, QString text, QActionGroup *group)
00101 {
00102 QAction *action = new QAction(img, text, group);
00103 action->setCheckable(true);
00104 action->setFont(FONT);
00105 return action;
00106 }
00107
00108
00109
00110 void
00111 ConfigDialog::addAction(QAction *action, const char *slot)
00112 {
00113 action->setFont(FONT);
00114 ui.toolBar->addAction(action);
00115 connect(action, SIGNAL(triggered()), this, slot);
00116 }
00117
00118
00119 void
00120 ConfigDialog::showWindow(Page page)
00121 {
00122
00123 loadSettings();
00124
00125 VidaliaWindow::showWindow();
00126
00127 ui.stackPages->setCurrentIndex((int)page);
00128 }
00129
00130
00131 void
00132 ConfigDialog::loadSettings()
00133 {
00134
00135 foreach (ConfigPage *page, ui.stackPages->pages()) {
00136 page->load();
00137 }
00138 }
00139
00140
00141 void
00142 ConfigDialog::saveChanges()
00143 {
00144 QString errmsg;
00145
00146
00147 foreach (ConfigPage *page, ui.stackPages->pages()) {
00148 if (!page->save(errmsg)) {
00149
00150 ui.stackPages->setCurrentPage(page);
00151
00152
00153 VMessageBox::warning(this,
00154 tr("Error Saving Configuration"), errmsg,
00155 VMessageBox::Ok);
00156
00157
00158 return;
00159 }
00160 }
00161 QMainWindow::close();
00162 }
00163
00164
00165 void
00166 ConfigDialog::help()
00167 {
00168 Vidalia::help("config");
00169 }
00170