Better cache handling. Added clear cache button to settings.
[jenirok] / src / gui / settingsdialog.cpp
index 757a0ff..f84f8c8 100644 (file)
@@ -21,6 +21,7 @@
 #include <QtGui/QVBoxLayout>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QIntValidator>
 #include <QtGui/QVBoxLayout>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QIntValidator>
+#include <QtGui/QDialogButtonBox>
 #include <QMaemo5ValueButton>
 #include <QMaemo5InformationBox>
 #include <QDebug>
 #include <QMaemo5ValueButton>
 #include <QMaemo5InformationBox>
 #include <QDebug>
@@ -28,6 +29,7 @@
 #include "settings.h"
 #include "db.h"
 #include "daemon.h"
 #include "settings.h"
 #include "db.h"
 #include "daemon.h"
+#include "cache.h"
 
 QMap <Eniro::Site, Eniro::SiteDetails> SettingsDialog::sites_ = Eniro::getSites();
 
 
 QMap <Eniro::Site, Eniro::SiteDetails> SettingsDialog::sites_ = Eniro::getSites();
 
@@ -54,6 +56,8 @@ autostartSelector_(0)
     QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
     cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
     cacheInput_->setValidator(new QIntValidator(0, 10000, this));
     QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
     cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
     cacheInput_->setValidator(new QIntValidator(0, 10000, this));
+    QPushButton* cacheResetButton = new QPushButton(tr("Clear"), this);
+    connect(cacheResetButton, SIGNAL(pressed()), this, SLOT(resetCache()));
 
     siteSelector_ = new ButtonSelector(tr("Eniro site"), this);
     QString site = Settings::instance()->get("eniro_site");
 
     siteSelector_ = new ButtonSelector(tr("Eniro site"), this);
     QString site = Settings::instance()->get("eniro_site");
@@ -95,7 +99,7 @@ autostartSelector_(0)
     autostartSelector_->addItem(tr("Disabled"), "0");
     autostartSelector_->setCurrentIndex(autostart == "1" ? 0 : 1);
 
     autostartSelector_->addItem(tr("Disabled"), "0");
     autostartSelector_->setCurrentIndex(autostart == "1" ? 0 : 1);
 
-    QPushButton* submitButton = new QPushButton(tr("Save"));
+    QPushButton* submitButton = new QPushButton(tr("Save"), this);
     connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));
 
     username->addWidget(usernameLabel);
     connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));
 
     username->addWidget(usernameLabel);
@@ -104,14 +108,19 @@ autostartSelector_(0)
     password->addWidget(passwordInput_);
     cache->addWidget(cacheLabel);
     cache->addWidget(cacheInput_);
     password->addWidget(passwordInput_);
     cache->addWidget(cacheLabel);
     cache->addWidget(cacheInput_);
+    cache->addWidget(cacheResetButton);
     left->addLayout(username);
     left->addLayout(password);
     left->addLayout(cache);
     left->addWidget(siteSelector_);
     left->addWidget(autostartSelector_);
 
     left->addLayout(username);
     left->addLayout(password);
     left->addLayout(cache);
     left->addWidget(siteSelector_);
     left->addWidget(autostartSelector_);
 
+    QDialogButtonBox* buttons = new QDialogButtonBox;
+    buttons->setCenterButtons(false);
+    buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
+
     mainLayout->addLayout(left);
     mainLayout->addLayout(left);
-    mainLayout->addWidget(submitButton);
+    mainLayout->addWidget(buttons);
 
     setLayout(mainLayout);
 
 
     setLayout(mainLayout);
 
@@ -166,3 +175,13 @@ void SettingsDialog::setVisible(bool visible)
     }
 
 }
     }
 
 }
+
+void SettingsDialog::resetCache()
+{
+    int ret = Cache::instance().clear();
+
+    if(ret >= 0)
+    {
+        QMaemo5InformationBox::information(this, tr("%n number(s) were deleted from cache", "", ret));
+    }
+}