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(cancelChanges()));
00085
00086
00087 grp->actions()[0]->setChecked(true);
00088
00089 #if defined(Q_WS_MAC)
00090 helpAct->setShortcut(QString("Ctrl+?"));
00091 cancelAct->setShortcut(QString("Ctrl+W"));
00092 #else
00093 helpAct->setShortcut(QString("F1"));
00094 cancelAct->setShortcut(QString("Esc"));
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::show()
00121 {
00122
00123 loadSettings();
00124
00125 VidaliaWindow::show();
00126 }
00127
00128
00129 void
00130 ConfigDialog::show(Page page)
00131 {
00132
00133 show();
00134
00135
00136 ui.stackPages->setCurrentIndex((int)page);
00137 }
00138
00139
00140 void
00141 ConfigDialog::loadSettings()
00142 {
00143
00144 foreach (ConfigPage *page, ui.stackPages->pages()) {
00145 page->load();
00146 }
00147 }
00148
00149
00150 void
00151 ConfigDialog::cancelChanges()
00152 {
00153
00154 loadSettings();
00155 QMainWindow::close();
00156 }
00157
00158
00159 void
00160 ConfigDialog::saveChanges()
00161 {
00162 QString errmsg;
00163
00164
00165 foreach (ConfigPage *page, ui.stackPages->pages()) {
00166 if (!page->save(errmsg)) {
00167
00168 ui.stackPages->setCurrentPage(page);
00169
00170
00171 VMessageBox::warning(this,
00172 tr("Error Saving Configuration"), errmsg,
00173 VMessageBox::Ok);
00174
00175
00176 return;
00177 }
00178 }
00179 QMainWindow::close();
00180 }
00181
00182
00183 void
00184 ConfigDialog::help()
00185 {
00186 Vidalia::help("config");
00187 }
00188