X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/edd98d7659d028f17185835fc14208d655273c82..1b2b63eb3a01025e03ff964f187adda52c62bcb3:/src/settings/services/servicessettingspage.cpp diff --git a/src/settings/services/servicessettingspage.cpp b/src/settings/services/servicessettingspage.cpp index d2ad90e38..fbddbbfa7 100644 --- a/src/settings/services/servicessettingspage.cpp +++ b/src/settings/services/servicessettingspage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009-2010 by Peter Penz * + * Copyright (C) 2009-2010 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -21,17 +21,20 @@ #include "dolphin_versioncontrolsettings.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 @@ -39,12 +42,13 @@ #include #include #include +#include #include ServicesSettingsPage::ServicesSettingsPage(QWidget* parent) : SettingsPageBase(parent), m_initialized(false), - m_servicesList(0), + m_listView(0), m_vcsGroupBox(0), m_vcsPluginsMap(), m_enabledVcsPlugins() @@ -53,14 +57,19 @@ ServicesSettingsPage::ServicesSettingsPage(QWidget* parent) : QLabel* label = new QLabel(i18nc("@label:textbox", "Select which services should " - "be shown in the context menu."), this); + "be shown in the context menu:"), this); label->setWordWrap(true); - m_servicesList = new QListWidget(this); - m_servicesList->setSortingEnabled(true); - m_servicesList->setSelectionMode(QAbstractItemView::NoSelection); - connect(m_servicesList, SIGNAL(itemClicked(QListWidgetItem*)), - this, SIGNAL(changed())); + m_listView = new QListView(this); + ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView); + ServiceModel* serviceModel = new ServiceModel(this); + QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this); + proxyModel->setSourceModel(serviceModel); + proxyModel->setSortRole(Qt::DisplayRole); + m_listView->setModel(proxyModel); + m_listView->setItemDelegate(delegate); + m_listView->setVerticalScrollMode(QListView::ScrollPerPixel); + connect(m_listView, SIGNAL(clicked(QModelIndex)), this, SIGNAL(changed())); KNS3::Button* downloadButton = new KNS3::Button(i18nc("@action:button", "Download New Services..."), "servicemenu.knsrc", @@ -73,7 +82,7 @@ ServicesSettingsPage::ServicesSettingsPage(QWidget* parent) : m_vcsGroupBox->hide(); topLayout->addWidget(label); - topLayout->addWidget(m_servicesList); + topLayout->addWidget(m_listView); topLayout->addWidget(downloadButton); topLayout->addWidget(m_vcsGroupBox); @@ -86,15 +95,19 @@ ServicesSettingsPage::~ServicesSettingsPage() void ServicesSettingsPage::applySettings() { + if (!m_initialized) { + return; + } + // Apply service menu settingsentries KConfig config("kservicemenurc", KConfig::NoGlobals); KConfigGroup showGroup = config.group("Show"); - const int count = m_servicesList->count(); - for (int i = 0; i < count; ++i) { - QListWidgetItem* item = m_servicesList->item(i); - const bool show = (item->checkState() == Qt::Checked); - const QString service = item->data(Qt::UserRole).toString(); + const QAbstractItemModel* model = m_listView->model(); + for (int i = 0; i < model->rowCount(); ++i) { + const QModelIndex index = model->index(i, 0); + const bool show = model->data(index, Qt::CheckStateRole).toBool(); + const QString service = model->data(index, ServiceModel::DesktopEntryNameRole).toString(); showGroup.writeEntry(service, show); } @@ -124,18 +137,18 @@ void ServicesSettingsPage::applySettings() void ServicesSettingsPage::restoreDefaults() { - const int count = m_servicesList->count(); - for (int i = 0; i < count; ++i) { - QListWidgetItem* item = m_servicesList->item(i); - item->setCheckState(Qt::Checked); + QAbstractItemModel* model = m_listView->model(); + for (int i = 0; i < model->rowCount(); ++i) { + const QModelIndex index = model->index(i, 0); + model->setData(index, true, Qt::CheckStateRole); } } void ServicesSettingsPage::showEvent(QShowEvent* event) { if (!event->spontaneous() && !m_initialized) { - QMetaObject::invokeMethod(this, "loadServices", Qt::QueuedConnection); - QMetaObject::invokeMethod(this, "loadVersionControlSystems", Qt::QueuedConnection); + loadServices(); + loadVersionControlSystems(); m_initialized = true; } SettingsPageBase::showEvent(event); @@ -143,6 +156,8 @@ void ServicesSettingsPage::showEvent(QShowEvent* event) void ServicesSettingsPage::loadServices() { + QAbstractItemModel* model = m_listView->model(); + const KConfig config("kservicemenurc", KConfig::NoGlobals); const KConfigGroup showGroup = config.group("Show"); @@ -166,12 +181,14 @@ void ServicesSettingsPage::loadServices() const QString itemName = subMenuName.isEmpty() ? action.text() : i18nc("@item:inmenu", "%1: %2", subMenuName, action.text()); - QListWidgetItem* item = new QListWidgetItem(KIcon(action.icon()), - itemName, - m_servicesList); - item->setData(Qt::UserRole, serviceName); const bool show = showGroup.readEntry(serviceName, true); - item->setCheckState(show ? Qt::Checked : Qt::Unchecked); + + model->insertRow(0); + const QModelIndex index = model->index(0, 0); + model->setData(index, action.icon(), Qt::DecorationRole); + model->setData(index, show, Qt::CheckStateRole); + model->setData(index, itemName, Qt::DisplayRole); + model->setData(index, serviceName, ServiceModel::DesktopEntryNameRole); } } } @@ -179,16 +196,20 @@ void ServicesSettingsPage::loadServices() // Load service plugins that implement the KFileItemActionPlugin interface const KService::List pluginServices = KServiceTypeTrader::self()->query("KFileItemAction/Plugin"); foreach (const KSharedPtr& service, pluginServices) { - const QString serviceName = service->desktopEntryName(); - if (!isInServicesList(serviceName)) { - QListWidgetItem* item = new QListWidgetItem(KIcon(service->icon()), - service->name(), - m_servicesList); - item->setData(Qt::UserRole, serviceName); - const bool show = showGroup.readEntry(serviceName, true); - item->setCheckState(show ? Qt::Checked : Qt::Unchecked); + const QString desktopEntryName = service->desktopEntryName(); + if (!isInServicesList(desktopEntryName)) { + const bool show = showGroup.readEntry(desktopEntryName, true); + + model->insertRow(0); + const QModelIndex index = model->index(0, 0); + model->setData(index, service->icon(), Qt::DecorationRole); + model->setData(index, show, Qt::CheckStateRole); + model->setData(index, service->name(), Qt::DisplayRole); + model->setData(index, desktopEntryName, ServiceModel::DesktopEntryNameRole); } } + + model->sort(Qt::DisplayRole); } void ServicesSettingsPage::loadVersionControlSystems() @@ -224,10 +245,10 @@ void ServicesSettingsPage::loadVersionControlSystems() bool ServicesSettingsPage::isInServicesList(const QString& service) const { - const int count = m_servicesList->count(); - for (int i = 0; i < count; ++i) { - QListWidgetItem* item = m_servicesList->item(i); - if (item->data(Qt::UserRole).toString() == service) { + QAbstractItemModel* model = m_listView->model(); + for (int i = 0; i < model->rowCount(); ++i) { + const QModelIndex index = model->index(i, 0); + if (model->data(index, ServiceModel::DesktopEntryNameRole).toString() == service) { return true; } }