1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

PluginsList: Sorting plugins alphabetically

This commit is contained in:
nowrep 2012-07-06 14:37:49 +02:00
parent 0d4078f005
commit 189193a8b8
6 changed files with 82 additions and 36 deletions

View File

@ -66,7 +66,6 @@ SOURCES += \
app/commandlineoptions.cpp \ app/commandlineoptions.cpp \
other/aboutdialog.cpp \ other/aboutdialog.cpp \
plugins/plugins.cpp \ plugins/plugins.cpp \
preferences/pluginslist.cpp \
plugins/pluginproxy.cpp \ plugins/pluginproxy.cpp \
tools/clickablelabel.cpp \ tools/clickablelabel.cpp \
downloads/downloadoptionsdialog.cpp \ downloads/downloadoptionsdialog.cpp \
@ -180,7 +179,8 @@ SOURCES += \
adblock/adblockaddsubscriptiondialog.cpp \ adblock/adblockaddsubscriptiondialog.cpp \
adblock/adblockschemehandler.cpp \ adblock/adblockschemehandler.cpp \
tools/emptynetworkreply.cpp \ tools/emptynetworkreply.cpp \
3rdparty/processinfo.cpp 3rdparty/processinfo.cpp \
preferences/pluginsmanager.cpp
HEADERS += \ HEADERS += \
webview/tabpreview.h \ webview/tabpreview.h \
@ -215,7 +215,6 @@ HEADERS += \
other/aboutdialog.h \ other/aboutdialog.h \
plugins/plugininterface.h \ plugins/plugininterface.h \
plugins/plugins.h \ plugins/plugins.h \
preferences/pluginslist.h \
plugins/pluginproxy.h \ plugins/pluginproxy.h \
tools/clickablelabel.h \ tools/clickablelabel.h \
downloads/downloadoptionsdialog.h \ downloads/downloadoptionsdialog.h \
@ -333,7 +332,8 @@ HEADERS += \
adblock/adblockaddsubscriptiondialog.h \ adblock/adblockaddsubscriptiondialog.h \
adblock/adblockschemehandler.h \ adblock/adblockschemehandler.h \
tools/emptynetworkreply.h \ tools/emptynetworkreply.h \
3rdparty/processinfo.h 3rdparty/processinfo.h \
preferences/pluginsmanager.h
FORMS += \ FORMS += \
preferences/autofillmanager.ui \ preferences/autofillmanager.ui \

View File

@ -45,6 +45,9 @@
<property name="alternatingRowColors"> <property name="alternatingRowColors">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="uniformItemSizes"> <property name="uniformItemSizes">
<bool>true</bool> <bool>true</bool>
</property> </property>

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */ * ============================================================ */
#include "pluginslist.h" #include "pluginsmanager.h"
#include "ui_pluginslist.h" #include "ui_pluginslist.h"
#include "pluginproxy.h" #include "pluginproxy.h"
#include "mainapplication.h" #include "mainapplication.h"
@ -28,9 +28,10 @@
#include <QMessageBox> #include <QMessageBox>
#include <QTimer> #include <QTimer>
PluginsList::PluginsList(QWidget* parent) PluginsManager::PluginsManager(QWidget* parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::PluginsList) , ui(new Ui::PluginsList)
, m_loaded(false)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -65,13 +66,17 @@ PluginsList::PluginsList(QWidget* parent)
} }
allowC2FChanged(ui->allowClick2Flash->isChecked()); allowC2FChanged(ui->allowClick2Flash->isChecked());
}
if (appPluginsEnabled) { void PluginsManager::load()
QTimer::singleShot(0, this, SLOT(refresh())); {
if (!m_loaded) {
refresh();
m_loaded = true;
} }
} }
void PluginsList::addWhitelist() void PluginsManager::addWhitelist()
{ {
QString site = QInputDialog::getText(this, tr("Add site to whitelist"), tr("Server without http:// (ex. youtube.com)")); QString site = QInputDialog::getText(this, tr("Add site to whitelist"), tr("Server without http:// (ex. youtube.com)"));
if (site.isEmpty()) { if (site.isEmpty()) {
@ -82,7 +87,7 @@ void PluginsList::addWhitelist()
ui->whitelist->insertTopLevelItem(0, new QTreeWidgetItem(QStringList(site))); ui->whitelist->insertTopLevelItem(0, new QTreeWidgetItem(QStringList(site)));
} }
void PluginsList::removeWhitelist() void PluginsManager::removeWhitelist()
{ {
QTreeWidgetItem* item = ui->whitelist->currentItem(); QTreeWidgetItem* item = ui->whitelist->currentItem();
if (!item) { if (!item) {
@ -93,7 +98,7 @@ void PluginsList::removeWhitelist()
delete item; delete item;
} }
void PluginsList::save() void PluginsManager::save()
{ {
QStringList allowedPlugins; QStringList allowedPlugins;
for (int i = 0; i < ui->list->count(); i++) { for (int i = 0; i < ui->list->count(); i++) {
@ -113,14 +118,11 @@ void PluginsList::save()
settings.endGroup(); settings.endGroup();
} }
void PluginsList::allowAppPluginsChanged(bool state) void PluginsManager::allowAppPluginsChanged(bool state)
{ {
ui->list->setEnabled(state); ui->list->setEnabled(state);
if (state) { if (!state) {
refresh();
}
else {
for (int i = 0; i < ui->list->count(); i++) { for (int i = 0; i < ui->list->count(); i++) {
QListWidgetItem* item = ui->list->item(i); QListWidgetItem* item = ui->list->item(i);
@ -129,9 +131,11 @@ void PluginsList::allowAppPluginsChanged(bool state)
} }
} }
} }
refresh();
} }
void PluginsList::allowC2FChanged(bool state) void PluginsManager::allowC2FChanged(bool state)
{ {
Settings settings; Settings settings;
settings.beginGroup("ClickToFlash"); settings.beginGroup("ClickToFlash");
@ -145,8 +149,12 @@ void PluginsList::allowC2FChanged(bool state)
mApp->plugins()->c2f_setEnabled(state); mApp->plugins()->c2f_setEnabled(state);
} }
void PluginsList::refresh() void PluginsManager::refresh()
{ {
if (!ui->allowAppPlugins->isChecked()) {
return;
}
ui->list->clear(); ui->list->clear();
ui->butSettings->setEnabled(false); ui->butSettings->setEnabled(false);
disconnect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*))); disconnect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
@ -178,10 +186,36 @@ void PluginsList::refresh()
ui->list->addItem(item); ui->list->addItem(item);
} }
sortItems();
connect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*))); connect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
} }
void PluginsList::currentChanged(QListWidgetItem* item) void PluginsManager::sortItems()
{
ui->list->sortItems();
bool itemMoved;
do {
itemMoved = false;
for (int i = 0; i < ui->list->count(); ++i) {
QListWidgetItem* topItem = ui->list->item(i);
QListWidgetItem* bottomItem = ui->list->item(i + 1);
if (!topItem || !bottomItem) {
continue;
}
if (topItem->checkState() == Qt::Unchecked && bottomItem->checkState() == Qt::Checked) {
QListWidgetItem* item = ui->list->takeItem(i + 1);
ui->list->insertItem(i, item);
itemMoved = true;
}
}
}
while (itemMoved);
}
void PluginsManager::currentChanged(QListWidgetItem* item)
{ {
if (!item) { if (!item) {
return; return;
@ -197,7 +231,7 @@ void PluginsList::currentChanged(QListWidgetItem* item)
ui->butSettings->setEnabled(showSettings); ui->butSettings->setEnabled(showSettings);
} }
void PluginsList::itemChanged(QListWidgetItem* item) void PluginsManager::itemChanged(QListWidgetItem* item)
{ {
if (!item) { if (!item) {
return; return;
@ -227,7 +261,7 @@ void PluginsList::itemChanged(QListWidgetItem* item)
currentChanged(ui->list->currentItem()); currentChanged(ui->list->currentItem());
} }
void PluginsList::settingsClicked() void PluginsManager::settingsClicked()
{ {
QListWidgetItem* item = ui->list->currentItem(); QListWidgetItem* item = ui->list->currentItem();
if (!item) { if (!item) {
@ -247,7 +281,7 @@ void PluginsList::settingsClicked()
} }
} }
PluginsList::~PluginsList() PluginsManager::~PluginsManager()
{ {
delete ui; delete ui;
} }

View File

@ -15,8 +15,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */ * ============================================================ */
#ifndef PLUGINSLIST_H #ifndef PLUGINSMANAGER_H
#define PLUGINSLIST_H #define PLUGINSMANAGER_H
#include <QWidget> #include <QWidget>
@ -29,13 +29,15 @@ class PluginsList;
class QListWidgetItem; class QListWidgetItem;
class QT_QUPZILLA_EXPORT PluginsList : public QWidget class QT_QUPZILLA_EXPORT PluginsManager : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PluginsList(QWidget* parent = 0); explicit PluginsManager(QWidget* parent = 0);
~PluginsList(); ~PluginsManager();
void load();
void save(); void save();
private slots: private slots:
@ -52,9 +54,11 @@ private slots:
void removeWhitelist(); void removeWhitelist();
void allowC2FChanged(bool state); void allowC2FChanged(bool state);
private:; private:
void sortItems();
Ui::PluginsList* ui; Ui::PluginsList* ui;
bool m_loaded;
}; };
#endif // PLUGINSLIST_H #endif // PLUGINSMANAGER_H

View File

@ -27,7 +27,7 @@
#include "mainapplication.h" #include "mainapplication.h"
#include "cookiemanager.h" #include "cookiemanager.h"
#include "pluginproxy.h" #include "pluginproxy.h"
#include "pluginslist.h" #include "pluginsmanager.h"
#include "qtwin.h" #include "qtwin.h"
#include "sslmanager.h" #include "sslmanager.h"
#include "networkproxyfactory.h" #include "networkproxyfactory.h"
@ -316,7 +316,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
settings.endGroup(); settings.endGroup();
//PLUGINS //PLUGINS
m_pluginsList = new PluginsList(this); m_pluginsList = new PluginsManager(this);
ui->pluginsFrame->addWidget(m_pluginsList); ui->pluginsFrame->addWidget(m_pluginsList);
//NOTIFICATIONS //NOTIFICATIONS
@ -427,10 +427,15 @@ void Preferences::showStackedPage(QListWidgetItem* item)
return; return;
} }
ui->caption->setText("<b>" + item->text() + "</b>"); int index = ui->listWidget->currentRow();
ui->stackedWidget->setCurrentIndex(ui->listWidget->currentRow());
setNotificationPreviewVisible(ui->stackedWidget->currentIndex() == 8); ui->caption->setText("<b>" + item->text() + "</b>");
ui->stackedWidget->setCurrentIndex(index);
setNotificationPreviewVisible(index == 8);
if (index == 9) {
m_pluginsList->load();
}
} }
void Preferences::setNotificationPreviewVisible(bool state) void Preferences::setNotificationPreviewVisible(bool state)

View File

@ -33,7 +33,7 @@ class QListWidgetItem;
class AutoFillManager; class AutoFillManager;
class QupZilla; class QupZilla;
class PluginsList; class PluginsManager;
class DesktopNotification; class DesktopNotification;
class ThemeManager; class ThemeManager;
@ -89,7 +89,7 @@ private:
Ui::Preferences* ui; Ui::Preferences* ui;
QupZilla* p_QupZilla; QupZilla* p_QupZilla;
AutoFillManager* m_autoFillManager; AutoFillManager* m_autoFillManager;
PluginsList* m_pluginsList; PluginsManager* m_pluginsList;
ThemeManager* m_themesManager; ThemeManager* m_themesManager;
QWeakPointer<DesktopNotification> m_notification; QWeakPointer<DesktopNotification> m_notification;