/* Copyright 2003 Rikard Björklind, Mikael Gransell This file is part of dc-qt. dc-qt is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. dc-qt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dc-qt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "preferences_dlg.h" #include "dc_settings.h" #include "debugdlg.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pixmaps.h" using namespace std; Pixmap *pix=NULL; preferences_dlg::preferences_dlg(QWidget *p, const char *name, bool modal) : QDialog(p, name, modal) { pix = new Pixmap(); setCaption("dc-qt preferences"); bool ok; // used for conversion checking QGridLayout *grid = new QGridLayout(this,4,2); wstack = new QWidgetStack(this,"wstack"); QTabWidget *tabs = new QTabWidget(wstack,"preftabs"); QTabWidget *commontabs = new QTabWidget(wstack,"commontabs"); wstack->addWidget(commontabs,0); wstack->addWidget(tabs,1); QHBoxLayout *bottom = new QHBoxLayout; grid->addMultiCellLayout(bottom,3,3,0,1); QPushButton *okBtn = new QPushButton("&Close",this); //QPushButton *cancelBtn = new QPushButton("&Cancel",this); bottom->addWidget(okBtn); //bottom->addWidget(cancelBtn); connect(okBtn,SIGNAL(clicked()),this,SLOT(update_profile())); connect(okBtn,SIGNAL(clicked()),this,SLOT(update_settings())); connect(okBtn,SIGNAL(clicked()),this,SLOT(close())); // connect(cancelBtn,SIGNAL(clicked()),this,SLOT(close())); QFrame *userbox = new QFrame(this,"user box"); QGroupBox *connbox = new QGroupBox("Connection",this,"connection box"); QVGroupBox *dirbox = new QVGroupBox("Sharing",this,"dir box"); QVGroupBox *downloadbox = new QVGroupBox("Downloading",this,"downloadbox"); QVGroupBox *guibox = new QVGroupBox("User interface",this,"guibox"); QGroupBox *netbox = new QGroupBox(10,Qt::Vertical,"Network",this,"network box"); QVGroupBox *regbox = new QVGroupBox("Statistics Reporting",this,"registering box"); QVGroupBox *reglabelframe = new QVGroupBox(regbox, "textbox"); // registration checkboxes QLabel *reg_text = new QLabel(reglabelframe); reg_text->setText("If you allow it, dc-qt can report back very basic usage statistics (mostly for fun, really).\n\n" "There are two types of reports: new-installation registration and new-session registration.\n" "The first kind is sent once for every time a new version of dc-qt is installed. The second\n" "kind is sent once for every time you start a session of dc-qt.\n\n" "Reported data is completely anonymous. In fact, the only information that is recorded by us\n" "is that there has been a report, and - in case of new-install registration - which version\n" "of dc-qt was used to generate it.\n\n" "It is impossible to uniquely associate this data with your person, or with your computer,\n" "or even with your copy of dc-qt.\n\n" "The gathered statistics can be found at the following page: http://dc-qt.sf.net/cnt\n\n\n"); reg_text->setIndent(10); allowUserReg = new QCheckBox("Ask to register new installation", regbox); allowUserReg->setChecked((settings.get_setting("register_never")!="true")); allowSessionReg = new QCheckBox("Count sessions", regbox); allowSessionReg->setChecked((settings.get_setting("register_session")=="true")); // Name QGridLayout *userGrid = new QGridLayout(userbox,3,3,10); userGrid->setRowStretch(3,10); QLabel *editLbl = new QLabel("Nick:", userbox); nameEdit = new QLineEdit(settings.get_setting("nick"), userbox,"nameedit"); // Description QLabel *descLbl = new QLabel("Description:",userbox); descEdit = new QLineEdit(settings.get_setting("description"), userbox,"descedit"); // Email QLabel *emailLbl = new QLabel("Email:", userbox); emailEdit = new QLineEdit(settings.get_setting("email"),userbox,"emailedit"); userGrid->addWidget(editLbl,0,0); userGrid->addWidget(nameEdit,0,1); userGrid->addWidget(descLbl,1,0); userGrid->addWidget(descEdit,1,1); userGrid->addWidget(emailLbl,2,0); userGrid->addWidget(emailEdit,2,1); // -------------- Network section ------------------- // Slots QLabel *slotsLbl = new QLabel("Upload slots:",netbox); int slotnr = settings.get_setting("slots").toInt(&ok); slotsSpin = new QSpinBox(1,15,1,netbox); slotsSpin->setValue(slotnr); // Max upload speed QLabel *speedLbl = new QLabel("Max upload speed (kb/s):",netbox); int limit = settings.get_setting("ul_rate_limit").toInt(&ok); speedSpin = new QSpinBox(0,99999,1,netbox); speedSpin->setValue(limit); desctagButtons = new QVButtonGroup("Add description tag",netbox,"desctagbuttons"); new QRadioButton("None",desctagButtons); new QRadioButton("DCTC",desctagButtons); new QRadioButton("DCGUI",desctagButtons); new QRadioButton("dc++",desctagButtons); QString desctag = settings.get_setting("desc_tag"); if(desctag=="none") desctagButtons->setButton(0); else if(desctag=="dctc") desctagButtons->setButton(1); else if(desctag=="dcgui") desctagButtons->setButton(2); else if(desctag=="dc++") desctagButtons->setButton(3); // Grant filelist slot option QHBox *granthbox = new QHBox(netbox); bool allowflst = settings.get_setting("allow_file_list_ul")=="true"?true:false; fileListCheck = new QCheckBox("Always allow file list upload",granthbox); fileListCheck->setChecked(allowflst); // Abort download when user leaves hub checkbox QHBox *abortbox = new QHBox(netbox); bool abortleaved = settings.get_setting("same_hub_only")=="true"?true:false; abortleavedCheck = new QCheckBox("Abort upload if user leaves hub",abortbox); abortleavedCheck->setChecked(abortleaved); // ------------------- Connection section -------------------- QGridLayout *netGrid = new QGridLayout(connbox,12,4,14); // Port QLabel *portLbl = new QLabel("Port:",connbox); int portnr = settings.get_setting("port").toInt(&ok); portSpin = new QSpinBox(0,65535,1,connbox); portSpin->setValue(portnr); // Address QLabel *addrLbl = new QLabel("Forced local IP (leave blank for default):",connbox); addrEdit = new QLineEdit(settings.get_setting("local_ip"), connbox,"Address"); // Connection type, sorry for the ugly code. connectionCombo = new QComboBox(connbox,"connectiontype"); QStringList connTypes = settings.get_connection_types(); int connTypeIndex = connTypes.findIndex(settings.get_setting("connection")); connectionCombo->insertStringList( connTypes ); connectionCombo->setCurrentItem(connTypeIndex); // passive passive = new QCheckBox("Passive connection",connbox); if(settings.get_setting("passive_mode") == "true") passive->setChecked(true); // Proxy stuff proxyCheck = new QCheckBox("Use proxy",connbox); if(settings.get_setting("use_proxy")=="true") proxyCheck->setChecked(true); QLabel *proxyAddrLbl = new QLabel("Proxy address:",connbox); proxyAddr = new QLineEdit(settings.get_setting("proxya_ip"),connbox,"proxyaddress"); QLabel *proxyPortLbl = new QLabel("Port:",connbox); proxyPort = new QLineEdit(settings.get_setting("proxy_port"),connbox,"proxyport"); if(proxyPort->text().isEmpty()) proxyPort->setText("8080"); proxyUseSocks = new QCheckBox("Use SOCKS",connbox); if(settings.get_setting("use_socks")=="true") proxyUseSocks->setChecked(true); QLabel *proxyUserLbl = new QLabel("Username:",connbox); proxyUsername = new QLineEdit(settings.get_setting("proxy_username"),connbox,"proxyusername"); QLabel *proxyPwdLbl = new QLabel("Password:",connbox); proxyPassword = new QLineEdit(settings.get_setting("proxy_password"),connbox,"proxypassword"); if(!proxyCheck->isChecked()) disableProxyWidgets(!true); if(!proxyUseSocks->isChecked()) disableSocksWidgets(!true); connect(proxyCheck,SIGNAL(toggled(bool)),this,SLOT(disableProxyWidgets(bool))); connect(proxyUseSocks,SIGNAL(toggled(bool)),this,SLOT(disableSocksWidgets(bool))); netGrid->addWidget(portLbl,0,0); netGrid->addWidget(portSpin,0,1); netGrid->addWidget(addrLbl,3,0); netGrid->addWidget(addrEdit,3,1); netGrid->addWidget(connectionCombo,4,1); netGrid->addWidget(passive,5,1); netGrid->addWidget(proxyCheck,6,0); netGrid->addWidget(proxyAddrLbl,7,0); netGrid->addWidget(proxyAddr,7,1); netGrid->addWidget(proxyPortLbl,8,0); netGrid->addWidget(proxyPort,8,1); netGrid->addWidget(proxyUseSocks,9,0); netGrid->addWidget(proxyUserLbl,10,0); netGrid->addWidget(proxyUsername,10,1); netGrid->addWidget(proxyPwdLbl,11,0); netGrid->addWidget(proxyPassword,11,1); // shared shared = new QListView(dirbox,"sharedlist"); shared->addColumn("Directory"); QStringList shares = QStringList::split(";",settings.get_setting("shares")); for ( QStringList::Iterator it = shares.begin(); it != shares.end(); ++it ) { QListViewItem *directory = new QListViewItem(shared,*it); } QHBox *hbox1 = new QHBox(dirbox); QPushButton *add = new QPushButton("add",hbox1); QPushButton *remove = new QPushButton("remove",hbox1); connect(add,SIGNAL(clicked()),this,SLOT(addSharesDlg())); connect(remove,SIGNAL(clicked()),this,SLOT(removeSelectedShare())); // DL path QHBox *hbox2 = new QHBox(downloadbox); QLabel *dlLbl = new QLabel("Download path:",hbox2); dlEdit = new QLineEdit(settings.get_setting("dl_dir"),hbox2,"dlpath"); QPushButton *dlBrowseBtn = new QPushButton("...",hbox2); connect(dlBrowseBtn,SIGNAL(clicked()),this,SLOT(openDirSelDlg())); // Max download speed QLabel *dspeedLbl = new QLabel("Max download speed (kb/s):",downloadbox); int dlimit = settings.get_setting("dl_rate_limit").toInt(&ok); dspeedSpin = new QSpinBox(0,99999,1,downloadbox,"hooo"); dspeedSpin->setValue(dlimit); // GUI tab section QHGroupBox *transbox = new QHGroupBox("Text encoding",guibox); encodingBox = new QComboBox(transbox,"translationcodecscombo"); encodingBox->insertItem( "Latin1"); encodingBox->insertItem( "Big5 -- Chinese"); encodingBox->insertItem( "Big5-HKSCS -- Chinese"); encodingBox->insertItem( "eucJP -- Japanese"); encodingBox->insertItem( "eucKR -- Korean"); encodingBox->insertItem( "GB2312 -- Chinese"); encodingBox->insertItem( "GBK -- Chinese"); encodingBox->insertItem( "GB18030 -- Chinese"); encodingBox->insertItem( "JIS7 -- Japanese"); encodingBox->insertItem( "Shift-JIS -- Japanese"); encodingBox->insertItem( "TSCII -- Tamil"); encodingBox->insertItem( "utf8 -- Unicode, 8-bit"); encodingBox->insertItem( "utf16 -- Unicode"); encodingBox->insertItem( "KOI8-R -- Russian"); encodingBox->insertItem( "KOI8-U -- Ukrainian"); encodingBox->insertItem( "ISO8859-1 -- Western"); encodingBox->insertItem( "ISO8859-2 -- Central European"); encodingBox->insertItem( "ISO8859-3 -- Central European"); encodingBox->insertItem( "ISO8859-4 -- Baltic"); encodingBox->insertItem( "ISO8859-5 -- Cyrillic"); encodingBox->insertItem( "ISO8859-6 -- Arabic"); encodingBox->insertItem( "ISO8859-7 -- Greek"); encodingBox->insertItem( "ISO8859-8 -- Hebrew, visually ordered"); encodingBox->insertItem( "ISO8859-8-i -- Hebrew, logically ordered"); encodingBox->insertItem( "ISO8859-9 -- Turkish"); encodingBox->insertItem( "ISO8859-10"); encodingBox->insertItem( "ISO8859-13"); encodingBox->insertItem( "ISO8859-14"); encodingBox->insertItem( "ISO8859-15 -- Western"); encodingBox->insertItem( "IBM 850"); encodingBox->insertItem( "IBM 866"); encodingBox->insertItem( "CP874"); encodingBox->insertItem( "CP1250 -- Central European"); encodingBox->insertItem( "CP1251 -- Cyrillic"); encodingBox->insertItem( "CP1252 -- Western"); encodingBox->insertItem( "CP1253 -- Greek"); encodingBox->insertItem( "CP1254 -- Turkish"); encodingBox->insertItem( "CP1255 -- Hebrew"); encodingBox->insertItem( "CP1256 -- Arabic"); encodingBox->insertItem( "CP1257 -- Baltic"); encodingBox->insertItem( "CP1258"); // encodingBox->insertItem( "Apple Roman"); encodingBox->insertItem( "TIS-620 -- Thai"); // Find the item in the box that matches the loaded setting and select it QString enc = settings.get_setting("font_encoding"); for(int i=0;i < encodingBox->count();i++) if( encodingBox->text(i).section(" ",0,0) == enc ) { encodingBox->setCurrentItem(i); break; } QHGroupBox *fontbox = new QHGroupBox("Application font",guibox); fontEdit = new QLineEdit(settings.get_setting("font"),fontbox,"fontlineedit"); fontEdit->setReadOnly(true); QPushButton *fontBtn = new QPushButton("...",fontbox,"fontchoosebtn"); connect( fontBtn, SIGNAL(pressed()), this, SLOT(chooseFont())); QHGroupBox *iconprefbox = new QHGroupBox("Icon-set (loads at start-up)",guibox); iconsetBox = new QComboBox(iconprefbox,"iconsetcombo"); iconsetBox->insertItem( "Default"); iconsetBox->insertItem( "IHQ"); // should call this "ugly" instead =) // Find the item in the box that matches the loaded setting and select it QString iset = settings.get_setting("tool_iconset"); for(int i=0;i < iconsetBox->count();i++) if( iconsetBox->text(i).section(" ",0,0) == iset ) { iconsetBox->setCurrentItem(i); break; } QVGroupBox *viewbox = new QVGroupBox("Hub View",guibox); splitviewCheck = new QCheckBox("IRC-style user-list placement", viewbox); splitviewCheck->setChecked((settings.get_setting("use_split_view") == "true")); QVGroupBox *chatbox = new QVGroupBox("Chatting",viewbox); timestampCheck = new QCheckBox("Timestamp messages", chatbox); timestampCheck->setChecked((settings.get_setting("chat_timestamp") == "true")); highlightCheck = new QCheckBox("Highlight messages that contain your nickname", chatbox); highlightCheck->setChecked((settings.get_setting("nick_highlight") == "true")); tabs->addTab(connbox,"Co&nnection"); tabs->addTab(netbox,"N&etwork"); tabs->addTab(userbox,"&User"); tabs->addTab(dirbox,"&Directories"); commontabs->addTab(downloadbox,"Downloading"); commontabs->addTab(guibox,"&Interface"); commontabs->addTab(regbox,"Stats &Reporting"); // grid->addWidget(tabs,0,0); grid->addWidget(wstack,0,1); // Profile selection listview QVGroupBox *profileBox = new QVGroupBox("Profiles", this); profileBox->setInsideMargin(1); profileList = new QListBox(profileBox,"profilelist"); profileList->insertItem(pix->getCommonProf(), "common"); QStringList profiles = settings.get_profiles(); for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it ) { if (*it == "default") profileList->insertItem(pix->getDefaultProf(), "default"); else profileList->insertItem(pix->getUserProf(), *it); } profileList->setCurrentItem(0); connect(profileList,SIGNAL(highlighted(const QString& )),this,SLOT(profileSelected(const QString&))); connect(profileList,SIGNAL(rightButtonPressed(QListBoxItem*, const QPoint& )),this,SLOT(showProfilePopup(QListBoxItem*, const QPoint&))); wstack->raiseWidget(0); profilePop = new QPopupMenu(this,"profilepopup"); profilePop->insertItem("New",this,SLOT(performProfileListOp(int )),0,0); profilePop->insertItem("Remove",this,SLOT(performProfileListOp(int)),0,1); // connect(profilePop,SIGNAL(activated(int)),this,SLOT(performProfileListOp(int))); grid->addMultiCellWidget(profileBox,0,2,0,0); grid->setColStretch(0,1); lastProfile = 0; } void preferences_dlg::showProfilePopup(QListBoxItem* i, const QPoint &p) { if(!i || currentProfile=="common" || currentProfile=="default") profilePop->setItemEnabled(1,false); else profilePop->setItemEnabled(1,true); lastProfile = i; profilePop->popup(p); } void preferences_dlg::performProfileListOp(int i) { debugWin->print("item: " + QString::number(i)); if(i==1) // remove { if( QMessageBox::question(this,"dc-qt confirmation","Do you really want to remove the selected profile?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { // Remove the profile from settings settings.remove_profile(lastProfile->text()); delete lastProfile; profileList->clearSelection(); profileList->setSelected(profileList->count()-1,true); currentProfile = profileList->selectedItem()->text(); } } else // add { bool ok; QString newName = QInputDialog::getText("dc-qt: Enter new profile name","Enter a name for this profile",QLineEdit::Normal, QString::null, &ok, this ); if(ok && !newName.isEmpty()) { profileList->insertItem(pix->getUserProf(), newName); profileList->clearSelection(); profileList->setSelected(profileList->findItem(newName),true); currentProfile = newName; settings.set_profile(newName); recall_profile("default"); } } } void preferences_dlg::profileSelected(const QString& name) { if(name=="common") wstack->raiseWidget(0); else { wstack->raiseWidget(1); // Save current profile if in the listview if( profileList->findItem(currentProfile)) update_profile(); settings.set_profile(name); recall_profile(name); } currentProfile = name; debugWin->print("Profile selected: " + name); } void preferences_dlg::openDirSelDlg() { QString dir = QFileDialog::getExistingDirectory(settings.get_home_dir(), this, "dldir_dialog", "Select download directory"); dlEdit->setText(dir); } void preferences_dlg::removeSelectedShare() { shared->takeItem( shared->selectedItem() ); } void preferences_dlg::addSharesDlg() { QString dir = QFileDialog::getExistingDirectory(settings.get_home_dir(), this, "shdir_dialog", "Select a sharing directory"); if(dir != QString::null) QListViewItem *item = new QListViewItem(shared,dir); } void preferences_dlg::chooseFont() { bool ok; font = QFontDialog::getFont( &ok, QApplication::font(), this ); if ( ok ) { // Set tahe desired font QApplication::setFont(font,true); fontEdit->setText( font.toString() ); } else { // Font dialog was cancelled. } } void preferences_dlg::update_profile() { settings.set_setting( "nick", nameEdit->text() ); settings.set_setting( "description", descEdit->text() ); settings.set_setting( "email", emailEdit->text() ); settings.set_setting( "local_ip", addrEdit->text() ); settings.set_setting( "slots", slotsSpin->text() ); settings.set_setting( "port", portSpin->text() ); settings.set_setting( "connection", connectionCombo->currentText() ); settings.set_setting( "passive_mode", passive->isChecked() ? "true" : "false"); settings.set_setting( "allow_file_list_ul", fileListCheck->isChecked()?"true":"false"); settings.set_setting( "same_hub_only", abortleavedCheck->isChecked()?"true":"false"); settings.set_setting( "ul_rate_limit", speedSpin->text() ); settings.set_setting( "use_proxy", proxyCheck->isChecked() ? "true" : "false"); settings.set_setting( "use_socks", proxyUseSocks->isChecked() ? "true" : "false"); settings.set_setting( "proxy_ip", proxyAddr->text() ); settings.set_setting( "proxy_port", proxyPort->text() ); settings.set_setting( "proxy_username", proxyUsername->text() ); settings.set_setting( "proxy_password", proxyPassword->text() ); QString desctag; switch(desctagButtons->id(desctagButtons->selected())) { case 0: desctag = "none"; break; case 1: desctag = "dctc"; break; case 2: desctag = "dcgui"; break; case 3: desctag = "dc++"; break; default: ; } settings.set_setting( "desc_tag",desctag); settings.set_setting( "same_hub_only", abortleavedCheck->isChecked() ? "true":"false"); // Add shares QString sharesstr(""); QListViewItem *item = shared->firstChild(); while(item) { sharesstr += item->text(0) + ";"; item = item->nextSibling(); } settings.set_setting("shares", sharesstr); } void preferences_dlg::recall_profile(const QString& profile) { nameEdit->setText( settings.get_setting(profile,"nick")); descEdit->setText( settings.get_setting(profile,"description")); emailEdit->setText( settings.get_setting(profile,"email")); addrEdit->setText( settings.get_setting(profile,"local_ip")); slotsSpin->setValue( settings.get_setting(profile,"slots").toInt()); portSpin->setValue( settings.get_setting(profile,"port").toInt()); for(int i=0;i < connectionCombo->count();i++) if(connectionCombo->text(i)==settings.get_setting(profile,"connection")) connectionCombo->setCurrentItem(i); passive->setChecked( settings.get_setting(profile,"passive_mode")=="true"); fileListCheck->setChecked( settings.get_setting(profile,"allow_file_list_ul")=="true"); abortleavedCheck->setChecked( settings.get_setting(profile,"same_hub_only")=="true"); speedSpin->setValue( settings.get_setting(profile,"ul_rate_limit").toInt()); proxyCheck->setChecked( settings.get_setting(profile,"use_proxy")=="true"); proxyUseSocks->setChecked( settings.get_setting(profile,"use_socks")=="true"); proxyAddr->setText( settings.get_setting(profile,"proxy_ip")); proxyPort->setText( settings.get_setting(profile,"proxy_port")); proxyUsername->setText( settings.get_setting(profile,"proxy_username")); proxyPassword->setText( settings.get_setting(profile,"proxy_password")); QString desctag = settings.get_setting(profile,"desc_tag"); if(desctag=="none") desctagButtons->setButton(0); else if(desctag=="dctc") desctagButtons->setButton(1); else if(desctag=="dcgui") desctagButtons->setButton(2); else if(desctag=="dc++") desctagButtons->setButton(3); QStringList shares = QStringList::split(";",settings.get_setting(profile,"shares")); shared->clear(); for ( QStringList::Iterator it = shares.begin(); it != shares.end(); ++it ) { QListViewItem *directory = new QListViewItem(shared,*it); } } // Typically called when someone presses OK. void preferences_dlg::update_settings() { update_profile(); settings.set_setting("common", "dl_rate_limit", dspeedSpin->text()); settings.set_setting("common", "dl_dir", dlEdit->text() ); settings.set_setting("common","font", font.toString() ); settings.set_setting("common","font_encoding", encodingBox->currentText().section(" ",0,0) ); settings.set_setting("common","use_split_view", splitviewCheck->isChecked() ? "true":"false"); settings.set_setting("common","nick_highlight", highlightCheck->isChecked() ? "true":"false"); settings.set_setting("common","chat_timestamp", timestampCheck->isChecked() ? "true":"false"); settings.set_setting("common","tool_iconset", iconsetBox->currentText().section(" ",0,0) ); // stats reporting settings.set_setting("common", "register_never", allowUserReg->isChecked() ? "false" : "true"); settings.set_setting("common","register_session", allowSessionReg->isChecked() ? "true" : "false"); if(!settings.save_to_file()) QMessageBox::critical(this, "Error", "Error saving the preferences file.","Ok"); } void preferences_dlg::disableProxyWidgets(bool yes) { proxyAddr->setDisabled(!yes); proxyPort->setDisabled(!yes); proxyUseSocks->setDisabled(!yes); if(yes) disableSocksWidgets(proxyUseSocks->isChecked()); else disableSocksWidgets(false); } void preferences_dlg::disableSocksWidgets(bool yes) { proxyUsername->setDisabled(!yes); proxyPassword->setDisabled(!yes); }