0.7.1
[fapman] / settings.cpp
index c26a96c..7f343fd 100644 (file)
@@ -17,6 +17,7 @@
        (C) Heikki Holstila 2010
 */
 
+#include <QtNetwork>
 #include "settings.h"
 #include "ui_settings.h"
 #include "mainwindow.h"
@@ -38,8 +39,8 @@ Settings::Settings(QWidget *parent) :
 Settings::~Settings()
 {
        iQSettings->sync();
-       delete iQSettings;
-    delete ui;
+       delete iQSettings; iQSettings=0;
+       delete ui; ui=0;
 }
 
 void Settings::changeEvent(QEvent *e)
@@ -61,6 +62,8 @@ void Settings::openWin()
        ui->checkBox_autoremove->setChecked( iQSettings->value("enable_autoremove", true).toBool() );
        ui->checkBox_autoclean->setChecked( iQSettings->value("enable_autoclean", true).toBool() );
        ui->checkBox_remove_readfull->setChecked( iQSettings->value("remove_readfull", false).toBool() );
+       ui->checkBox_no_catalogs_autoupdate->setChecked( iQSettings->value("no_catalogs_autoupdate",false).toBool() );
+       ui->checkBox_always_fetch_changes->setChecked( iQSettings->value("always_fetch_changes",false).toBool() );
 
        ui->checkBox_proxies->setChecked( iQSettings->value("use_proxies", false).toBool() );
        ui->lineEdit_http_proxy->setText( iQSettings->value("http_proxy","").toString() );
@@ -88,10 +91,12 @@ void Settings::on_btn_OK_clicked()
        iQSettings->setValue("enable_autoremove", ui->checkBox_autoremove->isChecked() );
        iQSettings->setValue("enable_autoclean", ui->checkBox_autoclean->isChecked() );
        iQSettings->setValue("remove_readfull", ui->checkBox_remove_readfull->isChecked() );
+       iQSettings->setValue("no_catalogs_autoupdate", ui->checkBox_no_catalogs_autoupdate->isChecked() );
+       iQSettings->setValue("always_fetch_changes", ui->checkBox_always_fetch_changes->isChecked() );
 
        iQSettings->setValue("use_proxies", ui->checkBox_proxies->isChecked() );
-       iQSettings->setValue("http_proxy", ui->lineEdit_http_proxy->text() );
-       iQSettings->setValue("https_proxy", ui->lineEdit_https_proxy->text() );
+       iQSettings->setValue("http_proxy", ui->lineEdit_http_proxy->text().trimmed() );
+       iQSettings->setValue("https_proxy", ui->lineEdit_https_proxy->text().trimmed() );
 
        iQSettings->setValue("default_sort_order", ui->comboBox_sortorder->currentIndex() );
 
@@ -145,3 +150,54 @@ void Settings::on_pushButton_searchOptions_clicked()
                                                                           s.searchDescShort(), s.searchDescLong() );
        }
 }
+
+QNetworkProxy Settings::createProxyFromString(QString proxystr)
+{
+       proxystr = proxystr.trimmed();
+       QString hostname = "";
+       quint16 port = 8080;
+       QString user;
+       QString pass;
+
+       QString proto;
+       int pos_proto = proxystr.indexOf("://");
+       if( pos_proto != -1 )
+       {
+               proto = proxystr.left(pos_proto+3);
+               proxystr = proxystr.mid(pos_proto+3);
+       }
+
+       QString temp;
+       QString temp2;
+       int pos_half = proxystr.indexOf('@');
+       if( pos_half==-1 ) {
+               temp = proxystr;
+       } else {
+               temp = proxystr.mid(pos_half+1);
+               temp2 = proxystr.left(pos_half);
+       }
+
+       if( !temp2.isNull() ) {
+               int pos_pass = temp2.indexOf(':');
+               if( pos_pass==-1 ) {
+                       user = temp2;
+               } else {
+                       user = temp2.left(pos_pass);
+                       pass = temp2.mid(pos_pass+1);
+               }
+       }
+
+       int pos_port = temp.indexOf(':');
+       if( pos_port==-1 ) {
+               hostname = temp;
+       } else {
+               hostname = temp.left(pos_port);
+               port = temp.mid(pos_port+1).remove('/').toInt();
+       }
+
+       hostname = proto + hostname;
+       qDebug() << "creating proxy" << hostname << port << user << pass;
+
+       QNetworkProxy p(QNetworkProxy::HttpProxy, hostname, port, user, pass);
+       return p;
+}