From e7357ffa7d7cbde721e1befe0da8a9f3b8bf0b97 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 15 Oct 2008 01:56:00 +0000 Subject: [PATCH] move the applet browser stuff into the two shells that actually use it (desktop and overlay) so that we can unburden libplasma from it; makes me a lot more comfortable talking about BC with a straight face. a new browser may end up going back in post-4.2 however svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=871492 --- CMakeLists.txt | 14 - appletbrowser.cpp | 481 ------------------ appletbrowser.h | 120 ----- appletbrowser/TODO | 16 - appletbrowser/customdragtreeview.cpp | 86 ---- appletbrowser/customdragtreeview_p.h | 43 -- appletbrowser/kcategorizeditemsview.cpp | 217 -------- appletbrowser/kcategorizeditemsview_p.h | 104 ---- appletbrowser/kcategorizeditemsviewbase.ui | 156 ------ .../kcategorizeditemsviewdelegate.cpp | 369 -------------- .../kcategorizeditemsviewdelegate_p.h | 93 ---- appletbrowser/kcategorizeditemsviewmodels.cpp | 270 ---------- appletbrowser/kcategorizeditemsviewmodels_p.h | 186 ------- appletbrowser/openwidgetassistant.cpp | 198 ------- appletbrowser/openwidgetassistant_p.h | 61 --- appletbrowser/plasmaappletitemmodel.cpp | 238 --------- appletbrowser/plasmaappletitemmodel_p.h | 95 ---- includes/AppletBrowser | 1 - tests/CMakeLists.txt | 6 +- 19 files changed, 3 insertions(+), 2751 deletions(-) delete mode 100644 appletbrowser.cpp delete mode 100644 appletbrowser.h delete mode 100644 appletbrowser/TODO delete mode 100644 appletbrowser/customdragtreeview.cpp delete mode 100644 appletbrowser/customdragtreeview_p.h delete mode 100644 appletbrowser/kcategorizeditemsview.cpp delete mode 100644 appletbrowser/kcategorizeditemsview_p.h delete mode 100644 appletbrowser/kcategorizeditemsviewbase.ui delete mode 100644 appletbrowser/kcategorizeditemsviewdelegate.cpp delete mode 100644 appletbrowser/kcategorizeditemsviewdelegate_p.h delete mode 100644 appletbrowser/kcategorizeditemsviewmodels.cpp delete mode 100644 appletbrowser/kcategorizeditemsviewmodels_p.h delete mode 100644 appletbrowser/openwidgetassistant.cpp delete mode 100644 appletbrowser/openwidgetassistant_p.h delete mode 100644 appletbrowser/plasmaappletitemmodel.cpp delete mode 100644 appletbrowser/plasmaappletitemmodel_p.h delete mode 100644 includes/AppletBrowser diff --git a/CMakeLists.txt b/CMakeLists.txt index ab175f45a..1964f1672 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,13 +25,6 @@ set(plasma_LIB_SRCS animationdriver.cpp animator.cpp applet.cpp - appletbrowser.cpp - appletbrowser/customdragtreeview.cpp - appletbrowser/kcategorizeditemsview.cpp - appletbrowser/kcategorizeditemsviewdelegate.cpp - appletbrowser/kcategorizeditemsviewmodels.cpp - appletbrowser/openwidgetassistant.cpp - appletbrowser/plasmaappletitemmodel.cpp configxml.cpp containment.cpp context.cpp @@ -102,11 +95,6 @@ set(plasma_LIB_SRCS # TEST_INCLUDES #) -kde4_add_ui_files ( - plasma_LIB_SRCS - appletbrowser/kcategorizeditemsviewbase.ui -) - if(QT_QTOPENGL_FOUND AND OPENGL_FOUND) MESSAGE(STATUS "Adding support for OpenGL applets to libplasma") set(plasma_LIB_SRCS @@ -151,7 +139,6 @@ set(plasma_LIB_INCLUDES animationdriver.h animator.h applet.h - appletbrowser.h configxml.h containment.h context.h @@ -226,7 +213,6 @@ includes/AbstractRunner includes/AnimationDriver includes/Animator includes/Applet -includes/AppletBrowser includes/AppletScript includes/CheckBox includes/ComboBox diff --git a/appletbrowser.cpp b/appletbrowser.cpp deleted file mode 100644 index c9f640e42..000000000 --- a/appletbrowser.cpp +++ /dev/null @@ -1,481 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "plasma/appletbrowser.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "plasma/applet.h" -#include "plasma/corona.h" -#include "plasma/containment.h" -#include "plasma/appletbrowser/kcategorizeditemsview_p.h" -#include "plasma/appletbrowser/plasmaappletitemmodel_p.h" -#include "plasma/appletbrowser/openwidgetassistant_p.h" -#include "plasma/private/packages_p.h" - -namespace Plasma -{ - -class AppletBrowserWidgetPrivate -{ -public: - AppletBrowserWidgetPrivate(AppletBrowserWidget *w) - : q(w), - containment(0), - appletList(0), - config("plasmarc"), - configGroup(&config, "Applet Browser"), - itemModel(configGroup, w), - filterModel(w) - { - } - - void initFilters(); - void init(); - void initRunningApplets(); - void containmentDestroyed(); - - /** - * Tracks a new running applet - */ - void appletAdded(Plasma::Applet *applet); - - /** - * A running applet is no more - */ - void appletRemoved(Plasma::Applet *applet); - - AppletBrowserWidget *q; - QString application; - Plasma::Containment *containment; - KCategorizedItemsView *appletList; - QHash runningApplets; // applet name => count - //extra hash so we can look up the names of deleted applets - QHash appletNames; - - KConfig config; - KConfigGroup configGroup; - - PlasmaAppletItemModel itemModel; - KCategorizedItemsViewModels::DefaultFilterModel filterModel; -}; - -void AppletBrowserWidgetPrivate::initFilters() -{ - filterModel.clear(); - - filterModel.addFilter(i18n("All Widgets"), - KCategorizedItemsViewModels::Filter(), KIcon("plasma")); - - // Recommended emblems and filters - QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]caption"); - QMapIterator i(configGroup.entryMap()); - while (i.hasNext()) { - i.next(); - if (!rx.exactMatch(i.key())) { - continue; - } - //kDebug() << "These are the key/vals in rc file " << rx.cap(1) << "\n"; - - QString id = rx.cap(1); - QString caption = configGroup.readEntry("recommended." + id + ".caption"); - QString icon = configGroup.readEntry("recommended." + id + ".icon"); - QString plugins = configGroup.readEntry("recommended." + id + ".plugins"); - - appletList->addEmblem(i18n("Recommended by %1", caption), KIcon(icon), - KCategorizedItemsViewModels::Filter("recommended." + id, true)); - filterModel.addFilter(i18n("Recommended by %1", caption), - KCategorizedItemsViewModels::Filter("recommended." + id, true), - KIcon(icon)); - } - - // Filters: Special - filterModel.addFilter(i18n("My Favorite Widgets"), - KCategorizedItemsViewModels::Filter("favorite", true), - KIcon("bookmarks")); - filterModel.addFilter(i18n("Widgets I Have Used Before"), - KCategorizedItemsViewModels::Filter("used", true), - KIcon("view-history")); - filterModel.addFilter(i18n("Currently Running Widgets"), - KCategorizedItemsViewModels::Filter("running", true), - KIcon("view-history")); - - filterModel.addSeparator(i18n("Categories:")); - - foreach (const QString &category, Plasma::Applet::listCategories(application)) { - filterModel.addFilter(category, - KCategorizedItemsViewModels::Filter("category", category)); - } -} - -AppletBrowserWidget::AppletBrowserWidget(QWidget * parent, Qt::WindowFlags f) - : QWidget(parent, f), - d(new AppletBrowserWidgetPrivate(this)) -{ - d->init(); -} - -AppletBrowserWidget::~AppletBrowserWidget() -{ - delete d; -} - -void AppletBrowserWidgetPrivate::init() -{ - QVBoxLayout *layout = new QVBoxLayout(q); - - appletList = new KCategorizedItemsView(q); - QObject::connect(appletList, SIGNAL(doubleClicked(const QModelIndex &)), q, SLOT(addApplet())); - layout->addWidget(appletList); - - // Other Emblems - appletList->addEmblem(i18n("Widgets I Have Used Before"), KIcon("view-history"), - KCategorizedItemsViewModels::Filter("used", true)); - - initFilters(); - appletList->setFilterModel(&filterModel); - - // Other models - appletList->setItemModel(&itemModel); - initRunningApplets(); - - q->setLayout(layout); -} - -void AppletBrowserWidgetPrivate::initRunningApplets() -{ -//get applets from corona, count them, send results to model - if (!containment) { - return; - } - - //kDebug() << runningApplets.count(); - Plasma::Corona *c = containment->corona(); - - //we've tried our best to get a corona - //we don't want just one containment, we want them all - if (!c) { - kDebug() << "can't happen"; - return; - } - - appletNames.clear(); - runningApplets.clear(); - QList containments = c->containments(); - foreach (Containment *containment, containments) { - QObject::connect(containment, SIGNAL(appletAdded(Plasma::Applet*,QPointF)), q, SLOT(appletAdded(Plasma::Applet*))); - QObject::connect(containment, SIGNAL(appletRemoved(Plasma::Applet*)), q, SLOT(appletRemoved(Plasma::Applet*))); - - foreach (Applet *applet, containment->applets()) { - runningApplets[applet->name()]++; - } - } - - //kDebug() << runningApplets; - itemModel.setRunningApplets(runningApplets); -} - -void AppletBrowserWidget::setApplication(const QString &app) -{ - d->application = app; - d->initFilters(); - d->itemModel.setApplication(app); - - //FIXME: AFAIK this shouldn't be necessary ... but here it is. need to find out what in that - // maze of models and views is screwing up - d->appletList->setItemModel(&d->itemModel); - - //kDebug() << d->runningApplets; - d->itemModel.setRunningApplets(d->runningApplets); -} - -QString AppletBrowserWidget::application() -{ - return d->application; -} - -void AppletBrowserWidget::setContainment(Plasma::Containment *containment) -{ - if (d->containment != containment) { - if (d->containment) { - d->containment->disconnect(this); - } - - d->containment = containment; - - if (d->containment) { - connect(d->containment, SIGNAL(destroyed(QObject*)), this, SLOT(containmentDestroyed())); - } - - d->initRunningApplets(); - } -} - -Containment *AppletBrowserWidget::containment() const -{ - return d->containment; -} - -void AppletBrowserWidgetPrivate::containmentDestroyed() -{ - containment = 0; -} - -void AppletBrowserWidget::addApplet() -{ - if (!d->containment) { - return; - } - - foreach (AbstractItem *item, d->appletList->selectedItems()) { - PlasmaAppletItem *selectedItem = (PlasmaAppletItem *) item; - //kDebug() << "Adding applet " << selectedItem->name() << "to containment"; - d->containment->addApplet(selectedItem->pluginName(), selectedItem->arguments()); - } -} - -void AppletBrowserWidgetPrivate::appletAdded(Plasma::Applet *applet) -{ - QString name = applet->name(); - //kDebug() << name; - - runningApplets[name]++; - appletNames.insert(applet, name); - itemModel.setRunningApplets(name, runningApplets[name]); -} - -void AppletBrowserWidgetPrivate::appletRemoved(Plasma::Applet *applet) -{ - //kDebug() << (QObject*)applet; - Plasma::Applet *a = (Plasma::Applet *)applet; //don't care if it's valid, just need the address - - QString name = appletNames.take(a); - - int count = 0; - if (runningApplets.contains(name)) { - count = runningApplets[name] - 1; - - if (count < 1) { - runningApplets.remove(name); - } else { - runningApplets[name] = count; - } - } - - itemModel.setRunningApplets(name, count); -} - -void AppletBrowserWidget::destroyApplets(const QString &name) -{ - if (!d->containment) { - return; - } - - Plasma::Corona *c = d->containment->corona(); - - //we've tried our best to get a corona - //we don't want just one containment, we want them all - if (!c) { - kDebug() << "can't happen"; - return; - } - - foreach (Containment *containment, c->containments()) { - QList applets = containment->applets(); - foreach (Applet *applet, applets) { - if (applet->name() == name) { - d->appletNames.remove(applet); - applet->disconnect(this); - applet->destroy(); - } - } - } - - d->runningApplets.remove(name); - d->itemModel.setRunningApplets(name, 0); -} - -void AppletBrowserWidget::downloadWidgets(const QString &type) -{ - //kDebug() << type; - PackageStructure *installer = 0; - - if (!type.isEmpty()) { - QString constraint = QString("'%1' == [X-KDE-PluginInfo-Name]").arg(type); - KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure", - constraint); - - if (offers.isEmpty()) { - kDebug() << "could not find requested PackageStructure plugin" << type; - } else { - KService::Ptr service = offers.first(); - QString error; - installer = service->createInstance(topLevelWidget(), - QVariantList(), &error); - - if (installer) { - connect(installer, SIGNAL(newWidgetBrowserFinished()), - installer, SLOT(deleteLater())); - } else { - kDebug() << "found, but could not load requested PackageStructure plugin" << type - << "; reported error was" << error; - } - } - } - - if (!installer) { - // we don't need to delete the default Applet::packageStructure as that - // belongs to the applet - installer = new PlasmoidPackage(); - } - - installer->createNewWidgetBrowser(this); -} - -void AppletBrowserWidget::openWidgetFile() -{ - // TODO: if we already have one of these showing and the user clicks to - // add it again, show the same window? - OpenWidgetAssistant *assistant = new OpenWidgetAssistant(topLevelWidget()); - assistant->setAttribute(Qt::WA_DeleteOnClose, true); - assistant->show(); -} - -class AppletBrowserPrivate -{ -public: - void init(AppletBrowser *browser); - void populateWidgetsMenu(); - - AppletBrowser *q; - AppletBrowserWidget *widget; - QMenu *widgetsMenu; -}; - -void AppletBrowserPrivate::populateWidgetsMenu() -{ - if (!widgetsMenu->actions().isEmpty()) { - // already populated. - return; - } - - QSignalMapper *mapper = new QSignalMapper(q); - QObject::connect(mapper, SIGNAL(mapped(QString)), widget, SLOT(downloadWidgets(QString))); - - QAction *action = new QAction(KIcon("applications-internet"), - i18n("Download New Plasma Widgets"), q); - QObject::connect(action, SIGNAL(triggered(bool)), mapper, SLOT(map())); - mapper->setMapping(action, QString()); - widgetsMenu->addAction(action); - - KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure"); - foreach (const KService::Ptr service, offers) { - //kDebug() << service->property("X-Plasma-ProvidesWidgetBrowser"); - if (service->property("X-Plasma-ProvidesWidgetBrowser").toBool()) { - QAction *action = new QAction(KIcon("applications-internet"), - i18n("Download New %1", service->name()), q); - widgetsMenu->addAction(action); - mapper->setMapping(action, service->property("X-KDE-PluginInfo-Name").toString()); - } - } - - widgetsMenu->addSeparator(); - - action = new QAction(KIcon("package-x-generic"), - i18n("Install A Widget From A Local File..."), q); - QObject::connect(action, SIGNAL(triggered(bool)), widget, SLOT(openWidgetFile())); - widgetsMenu->addAction(action); -} - -void AppletBrowserPrivate::init(AppletBrowser *browser) -{ - q = browser; - widget = new AppletBrowserWidget(q); - - q->setMainWidget(widget); - q->setWindowTitle(i18n("Widgets")); - - q->setButtons(KDialog::Apply | KDialog::Close | KDialog::User1); - q->setButtonText(KDialog::Apply, i18n("Add Widget")); - q->setButtonText(KDialog::User1, i18n("Install New Widgets")); - - widgetsMenu = new KMenu(i18n("Get New Widgets"), q); - QObject::connect(widgetsMenu, SIGNAL(aboutToShow()), q, SLOT(populateWidgetsMenu())); - q->button(KDialog::User1)->setMenu(widgetsMenu); - - q->setButtonToolTip(KDialog::Close, i18n("Close the dialog")); - q->setButtonWhatsThis(KDialog::Close, i18n("When clicking Close, this dialog will be closed with no further action taken.")); - q->setButtonToolTip(KDialog::Apply, i18n("Add selected widgets")); - q->setButtonWhatsThis(KDialog::Apply, i18n("When clicking Add Widget, the selected widgets will be added to your desktop.")); - q->setButtonToolTip(KDialog::User1, i18n("Install new widgets")); - q->setButtonWhatsThis(KDialog::User1, i18n("Selecting Get New Widgets will show a window that allows you to download new widgets directly from the Internet, while Install From File allows you to add new widgets from files you have on disk.")); - - QObject::connect(q, SIGNAL(applyClicked()), widget, SLOT(addApplet())); - - q->setInitialSize(QSize(400, 600)); - KConfigGroup cg(KGlobal::config(), "PlasmaAppletBrowserDialog"); - q->restoreDialogSize(cg); -} - -AppletBrowser::AppletBrowser(QWidget * parent, Qt::WindowFlags f) - : KDialog(parent, f), - d(new AppletBrowserPrivate) -{ - d->init(this); -} - -AppletBrowser::~AppletBrowser() -{ - KConfigGroup cg(KGlobal::config(), "PlasmaAppletBrowserDialog"); - saveDialogSize(cg); -} - -void AppletBrowser::setApplication(const QString &app) -{ - d->widget->setApplication(app); -} - -QString AppletBrowser::application() -{ - return d->widget->application(); -} - -void AppletBrowser::setContainment(Plasma::Containment *containment) -{ - d->widget->setContainment(containment); -} - -Containment *AppletBrowser::containment() const -{ - return d->widget->containment(); -} - -} // namespace Plasma - -#include "appletbrowser.moc" diff --git a/appletbrowser.h b/appletbrowser.h deleted file mode 100644 index d4c892e6d..000000000 --- a/appletbrowser.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef PLASMA_APPLETBROWSER_H -#define PLASMA_APPLETBROWSER_H - -#include - -#include - -namespace Plasma -{ - -class Corona; -class Containment; -class Applet; -class AppletBrowserPrivate; -class AppletBrowserWidgetPrivate; - -class PLASMA_EXPORT AppletBrowserWidget : public QWidget -{ - Q_OBJECT -public: - explicit AppletBrowserWidget(QWidget *parent = 0, Qt::WindowFlags f = 0); - virtual ~AppletBrowserWidget(); - - void setApplication(const QString &application = QString()); - QString application(); - - /** - * Changes the current default containment to add applets to - * - * @arg containment the new default - */ - void setContainment(Plasma::Containment *containment); - - /** - * @return the current default containment to add applets to - */ - Containment *containment() const; - -public Q_SLOTS: - /** - * Adds currently selected applets - */ - void addApplet(); - - /** - * Destroy all applets with this name - */ - void destroyApplets(const QString &name); - - /** - * Launches a download dialog to retrieve new applets from the Internet - * - * @arg type the type of widget to download; an empty string means the default - * Plasma widgets will be accessed, any other value should map to a - * PackageStructure PluginInfo-Name entry that provides a widget browser. - */ - void downloadWidgets(const QString &type = QString()); - - /** - * Opens a file dialog to open a widget from a local file - */ - void openWidgetFile(); - -private: - Q_PRIVATE_SLOT(d, void appletAdded(Plasma::Applet*)) - Q_PRIVATE_SLOT(d, void appletRemoved(Plasma::Applet*)) - Q_PRIVATE_SLOT(d, void containmentDestroyed()) - - AppletBrowserWidgetPrivate * const d; -}; - -class PLASMA_EXPORT AppletBrowser: public KDialog -{ - Q_OBJECT -public: - explicit AppletBrowser(QWidget *parent = 0, Qt::WindowFlags f = 0); - virtual ~AppletBrowser(); - - void setApplication(const QString &application = QString()); - QString application(); - - /** - * Changes the current default containment to add applets to - * - * @arg containment the new default - */ - void setContainment(Plasma::Containment *containment); - - /** - * @return the current default containment to add applets to - */ - Containment *containment() const; - -private: - Q_PRIVATE_SLOT(d, void populateWidgetsMenu()) - AppletBrowserPrivate * const d; -}; - -} // namespace Plasma - -#endif /*APPLETBROWSERWINDOW_H_*/ diff --git a/appletbrowser/TODO b/appletbrowser/TODO deleted file mode 100644 index 22d5319b8..000000000 --- a/appletbrowser/TODO +++ /dev/null @@ -1,16 +0,0 @@ -* Bug [LOW]: items deselect if a user changes one - of the stars of selected items - -Not before it goes into plasma: -* Adding multiple items -* Dragging the schreenshots of plasmoids -* Customized recommended by -* GHNS - -Done: -* Bug [MEDIUM]: items select when the star is clicked -* Feedback on hovering the star -* The rest of the dialog - buttons, etc. -* Separate (visually) special and normal categories -* Applets without an icon - default icon, category icon - diff --git a/appletbrowser/customdragtreeview.cpp b/appletbrowser/customdragtreeview.cpp deleted file mode 100644 index 0c4a7f3aa..000000000 --- a/appletbrowser/customdragtreeview.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "kcategorizeditemsview_p.h" - -#define PIX_SIZE 64 -#define MAX_OFFSET 16 -#define MAX_COUNT 5 - -CustomDragTreeView::CustomDragTreeView(QWidget * parent) - : QTreeView(parent) {} - -void CustomDragTreeView::startDrag(Qt::DropActions supportedActions) -{ - Q_UNUSED(supportedActions); - - // TODO: calculate real size for pixmap - using the icon sizes, not fixed - // like now - - if (!m_view) { - return; - } - - QModelIndexList indexes = selectedIndexes(); - if (indexes.count() > 0) { - QMimeData *data = model()->mimeData(indexes); - if (!data) { - return; - } - - int size = PIX_SIZE + (qMin(MAX_COUNT, indexes.count()) * MAX_OFFSET); - int off = MAX_OFFSET; - if (indexes.count() > MAX_COUNT) { - off = (MAX_OFFSET * MAX_COUNT) / indexes.count(); - } - - //kDebug() << "Size: " << size << " Off: " << off << "\n"; - - QPixmap pixmap(size, size); - pixmap.fill(QColor(255, 255, 255, 0)); // TODO: Transparent. Now it flickers when it's transparent - QPainter painter(&pixmap); - QRect rect(0, 0, PIX_SIZE, PIX_SIZE); - - foreach (const QModelIndex &index, indexes) { - if (index.column() != 0) { - continue; - } - - KCategorizedItemsViewModels::AbstractItem * item = - m_view->getItemByProxyIndex(index); - - if (item) { - rect.setSize(item->icon().actualSize(QSize(PIX_SIZE, PIX_SIZE))); - //painter.fillRect(rect, QBrush(QColor(255, 255, 255))); // TODO: Use global palettes - item->icon().paint(&painter, rect); - rect.moveTopLeft(rect.topLeft() + QPoint(off, off)); - } - } - painter.end(); - - QDrag *drag = new QDrag(this); - drag->setPixmap(pixmap); - drag->setMimeData(data); - drag->start(supportedActions); - //drag->setHotSpot(d->pressedPosition - rect.topLeft()); - //if (drag->start(supportedActions) == Qt::MoveAction) - // d->clearOrRemove(); - } -} - diff --git a/appletbrowser/customdragtreeview_p.h b/appletbrowser/customdragtreeview_p.h deleted file mode 100644 index dccde9bcf..000000000 --- a/appletbrowser/customdragtreeview_p.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef PLASMA_CUSTOMDRAGTREEVIEW_P_H -#define PLASMA_CUSTOMDRAGTREEVIEW_P_H - -#include -#include "kcategorizeditemsviewmodels_p.h" - -class KCategorizedItemsView; - -class CustomDragTreeView: public QTreeView -{ -public: - CustomDragTreeView(QWidget *parent = 0); - -protected: - void startDrag(Qt::DropActions supportedActions); - -private: - KCategorizedItemsView *m_view; - - friend class KCategorizedItemsView; -}; - -#endif - diff --git a/appletbrowser/kcategorizeditemsview.cpp b/appletbrowser/kcategorizeditemsview.cpp deleted file mode 100644 index e4ac18b19..000000000 --- a/appletbrowser/kcategorizeditemsview.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "kcategorizeditemsview_p.h" -#include "kcategorizeditemsviewdelegate_p.h" - -#include -#include -#include -#include - -#define UNIVERSAL_PADDING 6 - -KCategorizedItemsView::KCategorizedItemsView(QWidget * parent, Qt::WindowFlags f) - : QWidget(parent, f), m_modelCategories(NULL), m_modelFilters(NULL), - m_modelItems(NULL), m_modelFilterItems(NULL), m_delegate(NULL), - m_viewWidth(0) -{ - setupUi(this); - itemsView->m_view = this; - - textSearch->setClickMessage(i18n("Enter search phrase here")); - - textSearch->setFocus(); - - connect(textSearch, SIGNAL(textChanged(QString)), - this, SLOT(searchTermChanged(QString))); - connect(comboFilters, SIGNAL(currentIndexChanged(int)), - this, SLOT(filterChanged(int))); - - // we filter "activated" signals to re-emit them only when wanted - connect(itemsView, SIGNAL(activated(const QModelIndex &)), - this, SLOT(itemActivated(const QModelIndex &))); - connect(itemsView, SIGNAL(doubleClicked(const QModelIndex &)), - this, SLOT(itemDoubleClicked(const QModelIndex &))); - - connect (itemsView, SIGNAL(clicked(const QModelIndex &)), - this, SIGNAL(clicked(const QModelIndex &))); - connect (itemsView, SIGNAL(entered(const QModelIndex &)), - this, SIGNAL(entered(const QModelIndex &))); - connect (itemsView, SIGNAL(pressed(const QModelIndex &)), - this, SIGNAL(pressed(const QModelIndex &))); - - itemsView->header()->setVisible(false); - - itemsView->setItemDelegate(m_delegate = new KCategorizedItemsViewDelegate(this)); - //itemsView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); - - connect (m_delegate, SIGNAL(destroyApplets(const QString)), - parent, SLOT(destroyApplets(const QString))); - - comboFilters->setItemDelegate(new KCategorizedItemsViewFilterDelegate(this)); - - itemsView->viewport()->setAttribute(Qt::WA_Hover); - itemsView->setAlternatingRowColors(true); - - QAction * find = KStandardAction::find(textSearch, SLOT(setFocus()), this); - addAction(find); -} - -KCategorizedItemsView::~KCategorizedItemsView() -{ - delete m_modelFilterItems; - delete m_delegate; -} - -void KCategorizedItemsView::resizeEvent (QResizeEvent *event) -{ - updateColumnsWidth(); - - QWidget::resizeEvent(event); -} - -bool KCategorizedItemsView::event (QEvent *event) -{ - switch (event->type()) { - case QEvent::PolishRequest: - case QEvent::Polish: - updateColumnsWidth(true); - break; - default: - break; - } - - return QWidget::event(event); -} - -void KCategorizedItemsView::setFilterModel(QStandardItemModel *model) -{ - comboFilters->setModel(model); - m_modelFilters = model; -} - -void KCategorizedItemsView::setItemModel(QStandardItemModel *model) -{ - if (!m_modelFilterItems) { - m_modelFilterItems = new DefaultItemFilterProxyModel(this); - connect(m_modelFilterItems, SIGNAL(searchTermChanged(QString)), - this, SLOT(slotSearchTermChanged(QString))); - } - - m_modelItems = model; - m_modelFilterItems->setSortCaseSensitivity(Qt::CaseInsensitive); - m_modelFilterItems->setDynamicSortFilter(true); - m_modelFilterItems->setSourceModel(m_modelItems); - m_modelFilterItems->sort(0); - - itemsView->setModel(m_modelFilterItems); - - if (m_modelFilterItems->rowCount()) { - itemsView->verticalScrollBar()->setSingleStep(itemsView->sizeHintForRow(0)); - } -} - -void KCategorizedItemsView::searchTermChanged(const QString &text) -{ - kDebug() << "EVENT\n" << text; - if (m_modelFilterItems) { - m_modelFilterItems->setSearch(text); - } -} - -void KCategorizedItemsView::filterChanged(int index) -{ - if (m_modelFilterItems) { - QVariant data = m_modelFilters->item(index)->data(); - m_modelFilterItems->setFilter(qVariantValue(data)); - } -} - -void KCategorizedItemsView::itemActivated(const QModelIndex &index) -{ - // don't emit activated signal for "favicon" and "remove applet" - // columns so double clicking on these columns won't unexpectedly - // add an applet to the containment - if (index.column() == 1 || index.column() == 2) { - return; - } - - emit activated(index); -} - -void KCategorizedItemsView::itemDoubleClicked(const QModelIndex &index) -{ - // don't emit activated signal for "favicon" and "remove applet" - // columns so double clicking on these columns won't unexpectedly - // add an applet to the containment - if (index.column() == 1 || index.column() == 2) { - return; - } - - emit doubleClicked(index); -} - -void KCategorizedItemsView::slotSearchTermChanged(const QString &term) -{ - updateColumnsWidth(); -} - -void KCategorizedItemsView::updateColumnsWidth(bool force) -{ - m_viewWidth = itemsView->viewport()->width(); - - if (force) { - m_viewWidth -= style()->pixelMetric(QStyle::PM_ScrollBarExtent) + UNIVERSAL_PADDING; - } - - itemsView->setColumnWidth(0, m_delegate->columnWidth(0, m_viewWidth)); - itemsView->setColumnWidth(1, m_delegate->columnWidth(1, m_viewWidth)); - itemsView->setColumnWidth(2, m_delegate->columnWidth(2, m_viewWidth)); -} - -void KCategorizedItemsView::addEmblem(const QString &title, const QIcon &icon, - const Filter &filter) -{ - m_emblems[title] = QPair(filter, icon); -} - -void KCategorizedItemsView::clearEmblems() -{ - m_emblems.clear(); -} - -AbstractItem *KCategorizedItemsView::getItemByProxyIndex(const QModelIndex &index) const -{ - return (AbstractItem *)m_modelItems->itemFromIndex(m_modelFilterItems->mapToSource(index)); -} - -QList KCategorizedItemsView::selectedItems() const -{ - QList items; - foreach (const QModelIndex &index, itemsView->selectionModel()->selectedIndexes()) { - if (index.column() == 0) { - items << getItemByProxyIndex(index); - } - } - return items; -} - -#include "kcategorizeditemsview_p.moc" - diff --git a/appletbrowser/kcategorizeditemsview_p.h b/appletbrowser/kcategorizeditemsview_p.h deleted file mode 100644 index 30b4704f2..000000000 --- a/appletbrowser/kcategorizeditemsview_p.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef PLASMA_KCATEGORIZEDITEMSVIEW_P_H -#define PLASMA_KCATEGORIZEDITEMSVIEW_P_H - -#include -#include - -#include "kcategorizeditemsviewmodels_p.h" - -#include "ui_kcategorizeditemsviewbase.h" - -using namespace KCategorizedItemsViewModels; -class KCategorizedItemsViewDelegate; - -/** - * QT4 View Widget for displaying a list of categorized items with special - * filtering capabilities. - * - * To use it, you need to implement KCategorizedItemsView::AbstractItem - * - * For convenience, there are default implementations of category model - * (DefaultCategoryModel), filters model (DefaultFilterModel) and the - * default item mode (DefaultItemModel), but you do not need to use them. - * - * One constraint is that DefaultItemModel *must* hold the items that - * are subclassed from KCategorizedItemsView::AbstractItem - * - */ -class KCategorizedItemsView: public QWidget, public Ui::KCategorizedItemsViewBase -{ - Q_OBJECT -public: - - explicit KCategorizedItemsView(QWidget *parent = 0, Qt::WindowFlags f = 0); - virtual ~KCategorizedItemsView(); - - void setFilterModel(QStandardItemModel *model); ///< Sets the filters model - void setItemModel(QStandardItemModel *model); ///< Sets the item model, as mentioned items must implement AbstractItem class - - void addEmblem(const QString &title, const QIcon &icon, const Filter &filter); - void clearEmblems(); - - QList < AbstractItem * > selectedItems() const; - -protected: - virtual void resizeEvent (QResizeEvent *event) ; - virtual bool event (QEvent *event); - -protected slots: - void searchTermChanged(const QString &text); - void filterChanged(int index); - -private slots: - void itemActivated(const QModelIndex &index); - void itemDoubleClicked(const QModelIndex &index); - void slotSearchTermChanged(const QString &term); - -Q_SIGNALS: - void activated(const QModelIndex &index); - void clicked(const QModelIndex &index); - void doubleClicked(const QModelIndex &index); - void entered(const QModelIndex &index); - void pressed(const QModelIndex &index); - -private: - void updateColumnsWidth(bool force = false); - - QStandardItemModel *m_modelCategories; - QStandardItemModel *m_modelFilters; - QStandardItemModel *m_modelItems; - - DefaultItemFilterProxyModel *m_modelFilterItems; - KCategorizedItemsViewDelegate *m_delegate; - - int m_viewWidth; - - QMap < QString, QPair < Filter, QIcon > > m_emblems; - AbstractItem *getItemByProxyIndex(const QModelIndex &index) const; - - friend class KCategorizedItemsViewDelegate; - friend class CustomDragTreeView; -}; - -//Q_DECLARE_METATYPE(KCategorizedItemsView::Filter) - -#endif diff --git a/appletbrowser/kcategorizeditemsviewbase.ui b/appletbrowser/kcategorizeditemsviewbase.ui deleted file mode 100644 index 86920f977..000000000 --- a/appletbrowser/kcategorizeditemsviewbase.ui +++ /dev/null @@ -1,156 +0,0 @@ - - KCategorizedItemsViewBase - - - - 0 - 0 - 487 - 528 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 3 - 0 - - - - - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 2 - 0 - - - - false - - - true - - - - - - - QFrame::Plain - - - Qt::Horizontal - - - - - - - QFrame::NoFrame - - - QAbstractItemView::NoEditTriggers - - - true - - - QAbstractItemView::DragOnly - - - QAbstractItemView::ExtendedSelection - - - - 64 - 64 - - - - 0 - - - false - - - - - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
- - CustomDragTreeView - QTreeView -
appletbrowser/customdragtreeview_p.h
-
-
- - comboFilters - - - - - comboFilters - currentIndexChanged(int) - textSearch - clear() - - - 438 - 14 - - - 438 - 38 - - - - -
diff --git a/appletbrowser/kcategorizeditemsviewdelegate.cpp b/appletbrowser/kcategorizeditemsviewdelegate.cpp deleted file mode 100644 index a1a5b0efc..000000000 --- a/appletbrowser/kcategorizeditemsviewdelegate.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "kcategorizeditemsviewdelegate_p.h" - -#include - -#include - -#include - -#include "kcategorizeditemsview_p.h" - -#define FAV_ICON_SIZE 24 -#define EMBLEM_ICON_SIZE 16 -#define UNIVERSAL_PADDING 6 -#define FADE_LENGTH 32 -#define MAIN_ICON_SIZE 48 -#define DROPDOWN_PADDING 2 -#define DROPDOWN_SEPARATOR_HEIGHT 32 - -KCategorizedItemsViewDelegate::KCategorizedItemsViewDelegate(QObject * parent) - : QItemDelegate(parent), m_favoriteIcon("bookmarks"), - m_favoriteAddIcon("list-add"), m_removeIcon("list-remove"), - m_onFavoriteIconItem(NULL) -{ - m_parent = (KCategorizedItemsView *) parent; -} - -void KCategorizedItemsViewDelegate::paint(QPainter *painter, - const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - KCategorizedItemsViewModels::AbstractItem * item = getItemByProxyIndex(index); - if (!item) { - return; - } - - QStyleOptionViewItemV4 opt(option); - QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); - style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget); - - switch (index.column()) { - case 0: - paintColMain(painter, option, item); - break; - case 1: - paintColFav(painter, option, item); - break; - case 2: - paintColRemove(painter, option, item); - break; - default: - kDebug() << "unexpected column"; - } -} - -int KCategorizedItemsViewDelegate::calcItemHeight(const QStyleOptionViewItem &option) const -{ - // Painting main column - QFont titleFont = option.font; - titleFont.setBold(true); - titleFont.setPointSize(titleFont.pointSize() + 2); - - int textHeight = QFontInfo(titleFont).pixelSize() + QFontInfo(option.font).pixelSize(); - //kDebug() << textHeight << qMax(textHeight, MAIN_ICON_SIZE) + 2 * UNIVERSAL_PADDING; - return qMax(textHeight, MAIN_ICON_SIZE) + 2 * UNIVERSAL_PADDING; -} - -void KCategorizedItemsViewDelegate::paintColMain( - QPainter *painter, const QStyleOptionViewItem &option, - const KCategorizedItemsViewModels::AbstractItem *item) const -{ - const int left = option.rect.left(); - const int top = option.rect.top(); - const int width = option.rect.width(); - const int height = calcItemHeight(option); - - bool leftToRight = (painter->layoutDirection() == Qt::LeftToRight); - QIcon::Mode iconMode = QIcon::Normal; - - QColor foregroundColor = (option.state.testFlag(QStyle::State_Selected))? - option.palette.color(QPalette::HighlightedText):option.palette.color(QPalette::Text); - - // Painting main column - QFont titleFont = option.font; - titleFont.setBold(true); - titleFont.setPointSize(titleFont.pointSize() + 2); - - QPixmap pixmap(width, height); - pixmap.fill(Qt::transparent); - QPainter p(&pixmap); - p.translate(-option.rect.topLeft()); - - QLinearGradient gradient; - - QString title = item->name(); - QString description = item->description(); - - // Painting - - // Text - int textInner = 2 * UNIVERSAL_PADDING + MAIN_ICON_SIZE; - - p.setPen(foregroundColor); - p.setFont(titleFont); - p.drawText(left + (leftToRight ? textInner : 0), - top, width - textInner, height / 2, - Qt::AlignBottom | Qt::AlignLeft, title); - p.setFont(option.font); - p.drawText(left + (leftToRight ? textInner : 0), - top + height / 2, - width - textInner, height / 2, - Qt::AlignTop | Qt::AlignLeft, description); - - // Main icon - item->icon().paint( - &p, - leftToRight ? left + UNIVERSAL_PADDING : left + width - UNIVERSAL_PADDING - MAIN_ICON_SIZE, - top + UNIVERSAL_PADDING, - MAIN_ICON_SIZE, - MAIN_ICON_SIZE, - Qt::AlignCenter, iconMode); - - // Counting the number of emblems for this item - int emblemCount = 0; - QPair < Filter, QIcon > emblem; - foreach (emblem, m_parent->m_emblems) { - if (item->passesFiltering(emblem.first)) { - ++emblemCount; - } - } - - // Gradient part of the background - fading of the text at the end - if (leftToRight) { - gradient = QLinearGradient(left + width - UNIVERSAL_PADDING - FADE_LENGTH, 0, - left + width - UNIVERSAL_PADDING, 0); - gradient.setColorAt(0, Qt::white); - gradient.setColorAt(1, Qt::transparent); - } else { - gradient = QLinearGradient(left + UNIVERSAL_PADDING, 0, - left + UNIVERSAL_PADDING + FADE_LENGTH, 0); - gradient.setColorAt(0, Qt::transparent); - gradient.setColorAt(1, Qt::white); - } - - QRect paintRect = option.rect; - p.setCompositionMode(QPainter::CompositionMode_DestinationIn); - p.fillRect(paintRect, gradient); - - if (leftToRight) { - gradient.setStart( - left + width - emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) - FADE_LENGTH, 0); - gradient.setFinalStop( - left + width - emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0); - } else { - gradient.setStart( - left + UNIVERSAL_PADDING + emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE), 0); - gradient.setFinalStop( - left + UNIVERSAL_PADDING + emblemCount * (UNIVERSAL_PADDING + EMBLEM_ICON_SIZE) + FADE_LENGTH, 0); - } - paintRect.setHeight(UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2); - p.fillRect(paintRect, gradient); - - // Emblems icons - p.setCompositionMode(QPainter::CompositionMode_SourceOver); - int emblemLeft = leftToRight ? (left + width - EMBLEM_ICON_SIZE) : left; // - FAV_ICON_SIZE - 2 * UNIVERSAL_PADDING - foreach (emblem, m_parent->m_emblems) { - if (item->passesFiltering(emblem.first)) { - emblem.second.paint(&p, - emblemLeft, top + UNIVERSAL_PADDING, - EMBLEM_ICON_SIZE, EMBLEM_ICON_SIZE, Qt::AlignCenter, iconMode); - if (leftToRight) { - emblemLeft -= UNIVERSAL_PADDING + EMBLEM_ICON_SIZE; - } else { - emblemLeft += UNIVERSAL_PADDING + EMBLEM_ICON_SIZE; - } - } - } - p.end(); - - painter->drawPixmap(option.rect.topLeft(), pixmap); -} - -void KCategorizedItemsViewDelegate::paintColFav( - QPainter *painter, const QStyleOptionViewItem &option, - const KCategorizedItemsViewModels::AbstractItem *item) const -{ - int left = option.rect.left(); - int top = option.rect.top(); - int width = option.rect.width(); - - // Painting favorite icon column - - if (! (option.state & QStyle::State_MouseOver) && m_onFavoriteIconItem == item) { - m_onFavoriteIconItem = NULL; - } - - QIcon::Mode iconMode = QIcon::Normal; - if (!item->isFavorite()) { - iconMode = QIcon::Disabled; - } else if (option.state & QStyle::State_MouseOver) { - iconMode = QIcon::Active; - } - - m_favoriteIcon.paint( - painter, - left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING, - top + UNIVERSAL_PADDING, - FAV_ICON_SIZE, - FAV_ICON_SIZE, - Qt::AlignCenter, - iconMode); - - const KIcon &icon = (item->isFavorite())? m_removeIcon : m_favoriteAddIcon; - - if ((option.state & QStyle::State_MouseOver) && (m_onFavoriteIconItem != item)) { - icon.paint( - painter, - left + width - EMBLEM_ICON_SIZE - UNIVERSAL_PADDING, - top + UNIVERSAL_PADDING, - EMBLEM_ICON_SIZE, - EMBLEM_ICON_SIZE, - Qt::AlignCenter, - iconMode); - } -} - -void KCategorizedItemsViewDelegate::paintColRemove( - QPainter *painter, const QStyleOptionViewItem &option, - const KCategorizedItemsViewModels::AbstractItem *item) const -{ - // Painting remove icon column - int running = item->running(); - if (!running) { - return; - } - - int left = option.rect.left(); - int top = option.rect.top(); - int width = option.rect.width(); - - QIcon::Mode iconMode = QIcon::Normal; - if (option.state & QStyle::State_MouseOver) { - iconMode = QIcon::Active; - } - - m_removeIcon.paint(painter, - left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING, - FAV_ICON_SIZE, FAV_ICON_SIZE, Qt::AlignCenter, iconMode); - - if (running == 1) { - return; - } - //paint number - QColor foregroundColor = (option.state.testFlag(QStyle::State_Selected))? - option.palette.color(QPalette::HighlightedText):option.palette.color(QPalette::Text); - painter->setPen(foregroundColor); - painter->setFont(option.font); - painter->drawText( - left + UNIVERSAL_PADDING, //FIXME might be wrong - top + UNIVERSAL_PADDING + MAIN_ICON_SIZE / 2, - width - 2 * UNIVERSAL_PADDING, MAIN_ICON_SIZE / 2, - Qt::AlignCenter, QString::number(running)); -} - -bool KCategorizedItemsViewDelegate::editorEvent( - QEvent *event, QAbstractItemModel *model, - const QStyleOptionViewItem &option, const QModelIndex &index) -{ - if (event->type() == QEvent::MouseButtonPress) { - KCategorizedItemsViewModels::AbstractItem *item = getItemByProxyIndex(index); - if (index.column() == 1) { - m_onFavoriteIconItem = item; - item->setFavorite(!item->isFavorite()); - return true; - } else if (index.column() == 2 && item->running()) { - item->setRunning(0); - emit destroyApplets(item->name()); - return true; - } - } - - return QItemDelegate::editorEvent(event, model, option, index); -} - -QSize KCategorizedItemsViewDelegate::sizeHint(const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - int width = (index.column() == 0) ? 0 : FAV_ICON_SIZE; - return QSize(width, calcItemHeight(option)); -} - -int KCategorizedItemsViewDelegate::columnWidth (int column, int viewWidth) const { - if (column != 0) { - return FAV_ICON_SIZE + 2 * UNIVERSAL_PADDING; - } else { - return viewWidth - 2 * columnWidth(1, viewWidth); - } -} - -KCategorizedItemsViewModels::AbstractItem *KCategorizedItemsViewDelegate::getItemByProxyIndex( - const QModelIndex &index) const -{ - return (AbstractItem *)m_parent->m_modelItems->itemFromIndex(m_parent->m_modelFilterItems->mapToSource(index)); -} - -// KCategorizedItemsViewFilterDelegate - -KCategorizedItemsViewFilterDelegate::KCategorizedItemsViewFilterDelegate(QObject *parent) - : QItemDelegate(parent) -{ - kDebug() << "KCategorizedItemsViewFilterDelegate(QObject *parent)\n"; - -} - -void KCategorizedItemsViewFilterDelegate::paint(QPainter *painter, - const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - if (index.flags() & Qt::ItemIsEnabled) { - QItemDelegate::paint(painter, option, index); - } else { - QStyleOptionViewItem separatorOption(option); - int height = QItemDelegate::sizeHint(option, index).height() + 2 * DROPDOWN_PADDING; - - separatorOption.state &= ~(QStyle::State_Selected | - QStyle::State_MouseOver | - QStyle::State_HasFocus); - separatorOption.rect.setTop( - separatorOption.rect.top() + separatorOption.rect.height() - height); - separatorOption.rect.setHeight(height); - QItemDelegate::paint(painter, separatorOption, index); - /*painter->drawLine( - option.rect.left(), - option.rect.top() + 1, - option.rect.left() + option.rect.width(), - option.rect.top() + 1);*/ - } -} - -QSize KCategorizedItemsViewFilterDelegate::sizeHint(const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - QSize size = QItemDelegate::sizeHint(option, index); - if (index.flags() & Qt::ItemIsEnabled) { - size.setHeight(size.height() + 2 * DROPDOWN_PADDING); - } else { - size.setHeight(DROPDOWN_SEPARATOR_HEIGHT); - } - return size; -} - -#include "kcategorizeditemsviewdelegate_p.moc" - diff --git a/appletbrowser/kcategorizeditemsviewdelegate_p.h b/appletbrowser/kcategorizeditemsviewdelegate_p.h deleted file mode 100644 index c345cfb4b..000000000 --- a/appletbrowser/kcategorizeditemsviewdelegate_p.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef PLASMA_KCATEGORIZEDITEMSVIEWDELEGATE_P_H -#define PLASMA_KCATEGORIZEDITEMSVIEWDELEGATE_P_H - -#include -#include - -#include - -#include "kcategorizeditemsviewmodels_p.h" - -class KCategorizedItemsView; - -namespace KCategorizedItemsViewModels { - class AbstractItem; -} - -/** - * Delegate for displaying the items - */ -class KCategorizedItemsViewDelegate: public QItemDelegate -{ - Q_OBJECT - -public: - KCategorizedItemsViewDelegate(QObject *parent = 0); - - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; - int columnWidth (int column, int viewWidth) const; - - bool editorEvent(QEvent *event, - QAbstractItemModel *model, - const QStyleOptionViewItem &option, - const QModelIndex &index); - -Q_SIGNALS: - void destroyApplets(const QString name); -private: - - KCategorizedItemsView *m_parent; - KIcon m_favoriteIcon; - KIcon m_favoriteAddIcon; - KIcon m_removeIcon; - - mutable KCategorizedItemsViewModels::AbstractItem *m_onFavoriteIconItem; - - KCategorizedItemsViewModels::AbstractItem *getItemByProxyIndex(const QModelIndex & index) const; - void paintColMain(QPainter *painter, const QStyleOptionViewItem &option, - const KCategorizedItemsViewModels::AbstractItem * item) const; - void paintColFav(QPainter *painter, const QStyleOptionViewItem &option, - const KCategorizedItemsViewModels::AbstractItem * item) const; - void paintColRemove(QPainter *painter, const QStyleOptionViewItem &option, - const KCategorizedItemsViewModels::AbstractItem * item) const; - - int calcItemHeight(const QStyleOptionViewItem &option) const; -}; - -/** - * Delegate for displaying the filters/categories - */ -class KCategorizedItemsViewFilterDelegate: public QItemDelegate -{ - Q_OBJECT - -public: - KCategorizedItemsViewFilterDelegate(QObject *parent = 0); - - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; -}; - -#endif /*KCATEGORIZEDITEMSVIEWDELEGATE_H_*/ diff --git a/appletbrowser/kcategorizeditemsviewmodels.cpp b/appletbrowser/kcategorizeditemsviewmodels.cpp deleted file mode 100644 index 7a24272c8..000000000 --- a/appletbrowser/kcategorizeditemsviewmodels.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "kcategorizeditemsviewmodels_p.h" -#include - -namespace KCategorizedItemsViewModels { - -// AbstractItem - -QString AbstractItem::name() const -{ - return text(); -} - -QString AbstractItem::description() const -{ - return ""; -} - -bool AbstractItem::isFavorite() const -{ - return passesFiltering(Filter("favorite", true)); -} - -int AbstractItem::running() const -{ - return 0; -} - -bool AbstractItem::matches(const QString &pattern) const -{ - return - name().contains(pattern, Qt::CaseInsensitive) || - description().contains(pattern, Qt::CaseInsensitive); -} - -// DefaultFilterModel - -DefaultFilterModel::DefaultFilterModel(QObject *parent) : - QStandardItemModel(0, 1, parent) -{ - setHeaderData(1, Qt::Horizontal, i18n("Filters")); -} - -void DefaultFilterModel::addFilter(const QString &caption, const Filter &filter, const KIcon &icon) -{ - QList newRow; - QStandardItem *item = new QStandardItem(caption); - item->setData(qVariantFromValue(filter)); - if (!icon.isNull()) { - item->setIcon(icon); - } - - newRow << item; - appendRow(newRow); -} - -void DefaultFilterModel::addSeparator(const QString &caption) -{ - QList newRow; - QStandardItem *item = new QStandardItem(caption); - item->setEnabled(false); - - newRow << item; - appendRow(newRow); -} - -// DefaultItemFilterProxyModel - -DefaultItemFilterProxyModel::DefaultItemFilterProxyModel(QObject *parent) : - QSortFilterProxyModel(parent), m_innerModel(parent) -{ -} - -void DefaultItemFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel) -{ - QStandardItemModel *model = qobject_cast(sourceModel); - - if (!model) { - kWarning() << "Expecting a QStandardItemModel!"; - return; - } - - m_innerModel.setSourceModel(model); - QSortFilterProxyModel::setSourceModel(&m_innerModel); -} - -QStandardItemModel *DefaultItemFilterProxyModel::sourceModel() const -{ - return m_innerModel.sourceModel(); -} - -int DefaultItemFilterProxyModel::columnCount(const QModelIndex &index) const -{ - Q_UNUSED(index); - return 3; -} - -QVariant DefaultItemFilterProxyModel::data(const QModelIndex &index, int role) const -{ - return m_innerModel.data(index, (index.column() == 1), role); -} - -bool DefaultItemFilterProxyModel::filterAcceptsRow(int sourceRow, - const QModelIndex &sourceParent) const -{ - QStandardItemModel *model = (QStandardItemModel *) sourceModel(); - - QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); - - AbstractItem *item = (AbstractItem *) model->itemFromIndex(index); - //kDebug() << "ITEM " << (item ? "IS NOT " : "IS") << " NULL\n"; - - return - (m_filter.first.isEmpty() || item->passesFiltering(m_filter)) && - (m_searchPattern.isEmpty() || item->matches(m_searchPattern)); -} - -bool DefaultItemFilterProxyModel::lessThan(const QModelIndex &left, - const QModelIndex &right) const -{ - return - sourceModel()->data(left).toString().localeAwareCompare( - sourceModel()->data(right).toString()) < 0; -} - -void DefaultItemFilterProxyModel::setSearch(const QString &pattern) -{ - m_searchPattern = pattern; - invalidateFilter(); - emit searchTermChanged(pattern); -} - -void DefaultItemFilterProxyModel::setFilter(const Filter &filter) -{ - m_filter = filter; - invalidateFilter(); -} - -// DefaultItemFilterProxyModel::InnerProxyModel - -DefaultItemFilterProxyModel::InnerProxyModel::InnerProxyModel(QObject *parent) : - QAbstractItemModel(parent), m_sourceModel(NULL) -{ -} - -Qt::ItemFlags DefaultItemFilterProxyModel::InnerProxyModel::flags(const QModelIndex &index) const -{ - if (!m_sourceModel) { - return 0; - } - return m_sourceModel->flags(index); -} - -QVariant DefaultItemFilterProxyModel::InnerProxyModel::data( - const QModelIndex &index, bool favoriteColumn, int role) const -{ - Q_UNUSED(favoriteColumn); - return data(index, role); -} - -QVariant DefaultItemFilterProxyModel::InnerProxyModel::data( - const QModelIndex &index, int role) const -{ - if (!m_sourceModel) { - return QVariant(); - } - return m_sourceModel->data(index, role); -} - -QVariant DefaultItemFilterProxyModel::InnerProxyModel::headerData( - int section, Qt::Orientation orientation, int role) const -{ - Q_UNUSED(orientation); - Q_UNUSED(role); - return QVariant(section); -} - -int DefaultItemFilterProxyModel::InnerProxyModel::rowCount(const QModelIndex &parent) const -{ - if (!m_sourceModel) { - return 0; - } - return m_sourceModel->rowCount(parent); -} - -bool DefaultItemFilterProxyModel::InnerProxyModel::setData( - const QModelIndex &index, const QVariant &value, int role) -{ - if (!m_sourceModel) { - return false; - } - return m_sourceModel->setData(index, value, role); -} - -bool DefaultItemFilterProxyModel::InnerProxyModel::setHeaderData( - int section, Qt::Orientation orientation, const QVariant &value, int role) -{ - Q_UNUSED(section); - Q_UNUSED(value); - Q_UNUSED(orientation); - Q_UNUSED(role); - return false; -} - -QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::index( - int row, int column, const QModelIndex &parent) const -{ - Q_UNUSED(column); - if (!m_sourceModel) { - return QModelIndex(); - } - return m_sourceModel->index(row, 0, parent); -} - -QModelIndex DefaultItemFilterProxyModel::InnerProxyModel::parent(const QModelIndex &index) const -{ - if (!m_sourceModel) { - return QModelIndex(); - } - return m_sourceModel->parent(index); -} - -QMimeData *DefaultItemFilterProxyModel::InnerProxyModel::mimeData( - const QModelIndexList &indexes) const -{ - if (!m_sourceModel) { - return NULL; - } - return m_sourceModel->mimeData(indexes); -} - -int DefaultItemFilterProxyModel::InnerProxyModel::columnCount(const QModelIndex &index) const -{ - Q_UNUSED(index); - return 3; //FIXME: a hardcoded magic number that appears in two places CANNOT be good -} - -void DefaultItemFilterProxyModel::InnerProxyModel::setSourceModel(QStandardItemModel *sourceModel) -{ - m_sourceModel = sourceModel; -} - -QStandardItemModel *DefaultItemFilterProxyModel::InnerProxyModel::sourceModel() const -{ - return m_sourceModel; -} - -// DefaultItemModel - -DefaultItemModel::DefaultItemModel(QObject *parent) : - QStandardItemModel(parent) {} -} diff --git a/appletbrowser/kcategorizeditemsviewmodels_p.h b/appletbrowser/kcategorizeditemsviewmodels_p.h deleted file mode 100644 index da3ac653d..000000000 --- a/appletbrowser/kcategorizeditemsviewmodels_p.h +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef PLASMA_KCATEGORIZEDITEMSVIEWMODELS_P_H -#define PLASMA_KCATEGORIZEDITEMSVIEWMODELS_P_H - -#include -#include -#include -#include -namespace KCategorizedItemsViewModels { - -typedef QPair Filter; - -/** - * Abstract class that needs to be implemented and used with the ItemModel - */ -class AbstractItem : public QStandardItem -{ -public: - /** - * Returns a localized string - name of the item - */ - virtual QString name() const; - - /** - * Returns a localized string - description of the item - */ - virtual QString description() const; - - /** - * Returns if the item is flagged as favorite - * Default implementation checks if the item passes the Filter("favorite", "1") filter - */ - virtual bool isFavorite() const; - - /** - * Returns the item's number of running applets - * Default implementation just returns 0 - */ - virtual int running() const; - - /** - * Returns if the item contains string specified by pattern. - * Default implementation checks whether name or description contain the - * string (not needed to be exactly that string) - */ - virtual bool matches(const QString &pattern) const; - - /** - * sets the favorite flag for the item - */ - virtual void setFavorite(bool favorite) = 0; - /** - * sets the number of running applets for the item - */ - virtual void setRunning(int count) = 0; - - /** - * Returns if the item passes the filter specified - */ - virtual bool passesFiltering(const Filter &filter) const = 0; -private: -}; - -/** - * The default implementation of the model containing filters - */ -class DefaultFilterModel : public QStandardItemModel -{ -public: - DefaultFilterModel(QObject *parent = 0); - - /** - * Adds a filter to the model - * @param caption The localized string to be displayed as a name of the filter - * @param filter The filter structure - */ - void addFilter(const QString &caption, const Filter &filter, const KIcon &icon = KIcon()); - - /** - * Adds a separator to the model - * @param caption The localized string to be displayed as a name of the separator - */ - void addSeparator(const QString &caption); -}; - -/** - * Default filter proxy model. - */ -class DefaultItemFilterProxyModel : public QSortFilterProxyModel -{ -Q_OBJECT - -public: - DefaultItemFilterProxyModel(QObject *parent = 0); - - bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; - bool lessThan(const QModelIndex &left, const QModelIndex &right) const; - - void setSearch(const QString &pattern); - void setFilter(const Filter &filter); - - void setSourceModel(QAbstractItemModel *sourceModel); - - QStandardItemModel *sourceModel() const; - - int columnCount(const QModelIndex &index) const; - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - -Q_SIGNALS: - void searchTermChanged(const QString &term); - -private: - - class InnerProxyModel : public QAbstractItemModel - { - public: - InnerProxyModel(QObject *parent = 0); - - Qt::ItemFlags flags(const QModelIndex &index) const; - - QVariant data(const QModelIndex &index, bool favoriteColumn, - int role = Qt::DisplayRole) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - bool setData(const QModelIndex &index, const QVariant &value, - int role = Qt::EditRole); - - QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - bool setHeaderData(int section, Qt::Orientation orientation, - const QVariant &value, int role = Qt::EditRole); - - int rowCount(const QModelIndex &parent = QModelIndex()) const; - int columnCount(const QModelIndex &index) const; - - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &index) const; - - QMimeData *mimeData(const QModelIndexList &indexes) const; - - void setSourceModel(QStandardItemModel *sourceModel); - QStandardItemModel *sourceModel() const; - - private: - QStandardItemModel *m_sourceModel; - }; - - Filter m_filter; - QString m_searchPattern; - InnerProxyModel m_innerModel; - -}; - -/** - * The default implementation of the model containing items. It /is/ QStandardItemModel - */ -class DefaultItemModel : public QStandardItemModel -{ -public: - DefaultItemModel(QObject *parent = 0); -}; - -} - -Q_DECLARE_METATYPE(KCategorizedItemsViewModels::Filter) - -#endif /*KCATEGORIZEDITEMSVIEWMODELS_H_*/ diff --git a/appletbrowser/openwidgetassistant.cpp b/appletbrowser/openwidgetassistant.cpp deleted file mode 100644 index 96c790c03..000000000 --- a/appletbrowser/openwidgetassistant.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (C) 2008 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "plasma/appletbrowser/openwidgetassistant_p.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "plasma/packagestructure.h" - -namespace Plasma -{ - -OpenWidgetAssistant::OpenWidgetAssistant(QWidget *parent) - : KAssistantDialog(parent), - m_fileDialog(0), - m_filePageWidget(0) -{ - QWidget *selectWidget = new QWidget(this); - QVBoxLayout *selectLayout = new QVBoxLayout(selectWidget); - QLabel *selectLabel = new QLabel(selectWidget); - selectLabel->setText(i18n("Select the type of widget to install from the list below.")); - m_widgetTypeList = new KListWidget(selectWidget); - m_widgetTypeList->setSelectionMode(QAbstractItemView::SingleSelection); - //m_widgetTypeList->setSelectionBehavior(QAbstractItemView::SelectItems); - connect(m_widgetTypeList, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(next())); - connect(m_widgetTypeList, SIGNAL(itemSelectionChanged ()), this, SLOT(slotItemChanged())); - - QString constraint("'Applet' in [X-Plasma-ComponentTypes] and exist [X-Plasma-PackageFormat]"); - KService::List offers = KServiceTypeTrader::self()->query("Plasma/ScriptEngine", constraint); - - QListWidgetItem * item = new QListWidgetItem(KIcon("plasma"), i18n("Plasmoid: Native plasma widget"), m_widgetTypeList); - item->setSelected(true); - m_widgetTypeList->setCurrentItem(item); - - foreach (const KService::Ptr &offer, offers) { - QString text(offer->name()); - if (!offer->comment().isEmpty()) { - text.append(": ").append(offer->comment()); - } - - item = new QListWidgetItem(text, m_widgetTypeList); - item->setData(PackageStructureRole, offer->property("X-KDE-PluginInfo-Name")); - - if (!offer->icon().isEmpty()) { - item->setIcon(KIcon(offer->icon())); - } - } - - selectLayout->addWidget(selectLabel); - selectLayout->addWidget(m_widgetTypeList); - - m_typePage = new KPageWidgetItem(selectWidget, i18n("Install New Widget From File")); - m_typePage->setIcon(KIcon("plasma")); - addPage(m_typePage); - - m_filePageWidget = new QWidget(this); - m_filePage = new KPageWidgetItem(m_filePageWidget, i18n("Select File")); - addPage(m_filePage); - - connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(prepPage(KPageWidgetItem*,KPageWidgetItem*))); - enableButton(KDialog::Help, false); - //connect( this, SIGNAL( helpClicked() ), this, SLOT( slotHelpClicked() ) ); - m_widgetTypeList->setFocus(); - resize(QSize(560, 400).expandedTo(minimumSizeHint())); -} - -void OpenWidgetAssistant::slotItemChanged() -{ - enableButton(KDialog::User2, !m_widgetTypeList->selectedItems().isEmpty()); -} - -void OpenWidgetAssistant::prepPage(KPageWidgetItem *current, KPageWidgetItem *before) -{ - Q_UNUSED(before); - if (m_widgetTypeList->selectedItems().isEmpty()) { - return; - } - - if (current != m_filePage) { - return; - } - - if (!m_fileDialog) { - QVBoxLayout *layout = new QVBoxLayout(m_filePageWidget); - m_fileDialog = new KFileWidget(KUrl(), m_filePageWidget); - m_fileDialog->setOperationMode(KFileWidget::Opening); - m_fileDialog->setMode(KFile::File | KFile::ExistingOnly); - connect(this, SIGNAL(user1Clicked()), m_fileDialog, SLOT(slotOk())); - connect(m_fileDialog, SIGNAL(accepted()), this, SLOT(finished())); - //m_fileDialog->setWindowFlags(Qt::Widget); - layout->addWidget(m_fileDialog); - } - - QListWidgetItem *item = m_widgetTypeList->selectedItems().first(); - Q_ASSERT(item); - - QString type = item->data(PackageStructureRole).toString(); - - m_fileDialog->setFilter(QString()); - if (!type.isEmpty()) { - QString constraint = QString("'%1' == [X-KDE-PluginInfo-Name]").arg(type); - KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure", constraint); - - kDebug() << "looking for a Plasma/PackageStructure with" << constraint << type; - Q_ASSERT(offers.count() > 0); - - m_packageStructureService = offers.first(); - QStringList mimes = m_packageStructureService->property("X-Plasma-PackageFileMimetypes").toStringList(); - - if (mimes.count() > 0) { - m_fileDialog->setMimeFilter(mimes); - } else { - QString filter = m_packageStructureService->property("X-Plasma-PackageFileFilter").toString(); - if (!filter.isEmpty()) { - m_fileDialog->setFilter(+ '|' + m_packageStructureService->name()); - } - } - } else { - QStringList mimes; - mimes << "application/x-plasma"; - m_fileDialog->setMimeFilter(mimes); - } -} - -void OpenWidgetAssistant::slotHelpClicked() -{ - //enable it when doc will created -} - -void OpenWidgetAssistant::finished() -{ - m_fileDialog->accept(); // how interesting .. accept() must be called before the state is set - QString packageFilePath = m_fileDialog->selectedFile(); - if (packageFilePath.isEmpty()) { - //TODO: user visible error handling - kDebug() << "hm. no file path?"; - return; - } - - kDebug() << "selected uri is" << packageFilePath << "of type" << m_fileDialog->currentFilter(); - PackageStructure *installer = 0; - if (m_packageStructureService) { - QString error; - installer = m_packageStructureService->createInstance(0, QVariantList(), &error); - if (!installer) { - kDebug() << "Could not load requested PackageStructure installer " - << m_packageStructureService << ". Error given: " << error; - KMessageBox::error( - this, - i18n("Could not load the required installer %1. " - "The error given was: %2", - m_packageStructureService, error), - i18n("Installation Failure")); - return; - } - } else { - installer = new PackageStructure; - } - - QString root = KStandardDirs::locateLocal("data", "plasma/plasmoids/"); - kDebug() << "installing" << packageFilePath << "to root dir of" << root; - - if (!installer->installPackage(packageFilePath, root)) { - KMessageBox::error(this, i18n("Installing the package %1 failed.", packageFilePath), - i18n("Installation Failure")); - } - - delete installer; -} - -} // Plasma namespace - -#include "openwidgetassistant_p.moc" diff --git a/appletbrowser/openwidgetassistant_p.h b/appletbrowser/openwidgetassistant_p.h deleted file mode 100644 index 2cc39d7ea..000000000 --- a/appletbrowser/openwidgetassistant_p.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2008 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef PLASMA_OPENWIDGETASSISTANT_P_H -#define PLASMA_OPENWIDGETASSISTANT_P_H - -#include -#include - -class KFileWidget; -class KListWidget; -class QListWidgetItem; - -namespace Plasma -{ - -class OpenWidgetAssistant : public KAssistantDialog -{ - Q_OBJECT - -public: - enum { - PackageStructureRole = Qt::UserRole + 1 - }; - - OpenWidgetAssistant(QWidget *parent); - -protected Q_SLOTS: - void prepPage(KPageWidgetItem *current, KPageWidgetItem *before); - void finished(); - void slotHelpClicked(); - void slotItemChanged(); - -private: - KPageWidgetItem *m_typePage; - KPageWidgetItem *m_filePage; - KFileWidget *m_fileDialog; - QWidget *m_filePageWidget; - KListWidget *m_widgetTypeList; - KService::Ptr m_packageStructureService; -}; - -} // Plasma namespace - -#endif diff --git a/appletbrowser/plasmaappletitemmodel.cpp b/appletbrowser/plasmaappletitemmodel.cpp deleted file mode 100644 index d34d24e94..000000000 --- a/appletbrowser/plasmaappletitemmodel.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "plasmaappletitemmodel_p.h" - -#include - -PlasmaAppletItem::PlasmaAppletItem(PlasmaAppletItemModel *model, - const QMap& info, - FilterFlags flags, - QMap *extraAttrs) - : QObject(model), m_model(model) -{ - QMap attrs(info); - - attrs.insert("favorite", flags & Favorite ? true : false); - attrs.insert("used", flags & Used ? true : false); - //attrs.insert("recommended", flags & Recommended ? true : false); - if (extraAttrs) { - attrs.unite(* extraAttrs); - } - setText(info["name"].toString() + " - "+ info["category"].toString()); - setData(attrs); - setIcon(qvariant_cast(info["icon"])); -} - -QString PlasmaAppletItem::name() const -{ - return data().toMap()["name"].toString(); -} - -QString PlasmaAppletItem::pluginName() const -{ - return data().toMap()["pluginName"].toString(); -} - -QString PlasmaAppletItem::description() const -{ - return data().toMap()["description"].toString(); -} - -int PlasmaAppletItem::running() const -{ - return data().toMap()["runningCount"].toInt(); -} - -void PlasmaAppletItem::setFavorite(bool favorite) -{ - QMap attrs = data().toMap(); - attrs.insert("favorite", favorite ? true : false); - setData(QVariant(attrs)); - - QString pluginName = attrs["pluginName"].toString(); - m_model->setFavorite(pluginName, favorite); -} - -void PlasmaAppletItem::setRunning(int count) -{ - QMap attrs = data().toMap(); - attrs.insert("running", count > 0); //bool for the filter - attrs.insert("runningCount", count); - setData(QVariant(attrs)); -} - -bool PlasmaAppletItem::passesFiltering( - const KCategorizedItemsViewModels::Filter & filter) const -{ - return data().toMap()[filter.first] == filter.second; -} - -QVariantList PlasmaAppletItem::arguments() const -{ - return qvariant_cast(data().toMap()["arguments"]); -} - -PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent) : - KCategorizedItemsViewModels::DefaultItemModel(parent), - m_configGroup(configGroup) -{ - m_used = m_configGroup.readEntry("used").split(','); - m_favorites = m_configGroup.readEntry("favorites").split(','); - connect(KSycoca::self(), SIGNAL(databaseChanged()), this, SLOT(populateModel())); -} - -void PlasmaAppletItemModel::populateModel() -{ - clear(); - //kDebug() << "populating model, our application is" << m_application; - - // Recommended emblems and filters - QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]plugins"); - QMapIterator i(m_configGroup.entryMap()); - QMap < QString, QMap < QString, QVariant > > extraPluginAttrs; - while (i.hasNext()) { - i.next(); - if (!rx.exactMatch(i.key())) { - continue; - } - QString id = rx.cap(1); - - foreach (const QString &plugin, i.value().split(',')) { - extraPluginAttrs[plugin]["recommended." + id] = true; - } - } - - //TODO: get recommended, favorite, used, etc out of listAppletInfo() - //kDebug() << "number of applets is" - // << Plasma::Applet::listAppletInfo(QString(), m_application).count(); - foreach (const KPluginInfo &info, Plasma::Applet::listAppletInfo(QString(), m_application)) { - //kDebug() << info.pluginName() << "NoDisplay" << info.property("NoDisplay").toBool(); - if (info.property("NoDisplay").toBool()) { - // we don't want to show the hidden category - continue; - } - //kDebug() << info.pluginName() << " is the name of the plugin\n"; - - QMap attrs; - attrs.insert("name", info.name()); - attrs.insert("pluginName", info.pluginName()); - attrs.insert("description", info.comment()); - attrs.insert("category", info.category()); - attrs.insert("icon", - static_cast(KIcon(info.icon().isEmpty() ? - "application-x-plasma" : info.icon()))); - - appendRow(new PlasmaAppletItem(this, attrs,((m_favorites.contains(info.pluginName())) ? PlasmaAppletItem::Favorite : PlasmaAppletItem::NoFilter) | ((m_used.contains(info.pluginName())) ? PlasmaAppletItem::Used : PlasmaAppletItem::NoFilter), &(extraPluginAttrs[info.pluginName()]))); - } -} - -void PlasmaAppletItemModel::setRunningApplets(const QHash &apps) -{ - //foreach item, find that string and set the count - for (int r=0; r(i); - if (p) { - p->setRunning(apps.value(p->name())); - } - } -} - -void PlasmaAppletItemModel::setRunningApplets(const QString &name, int count) -{ - for (int r=0; r(i); - if (p && p->name() == name) { - p->setRunning(count); - } - } -} - -QStringList PlasmaAppletItemModel::mimeTypes() const -{ - QStringList types; - types << QLatin1String("text/x-plasmoidservicename"); - return types; -} - -QMimeData *PlasmaAppletItemModel::mimeData(const QModelIndexList &indexes) const -{ - kDebug() << "GETTING MIME DATA\n"; - if (indexes.count() <= 0) { - return 0; - } - - QStringList types = mimeTypes(); - - if (types.isEmpty()) { - return 0; - } - - QMimeData *data = new QMimeData(); - - QString format = types.at(0); - - QByteArray appletNames; - int lastRow = -1; - foreach (const QModelIndex &index, indexes) { - if (index.row() == lastRow) { - continue; - } - - lastRow = index.row(); - PlasmaAppletItem *selectedItem = (PlasmaAppletItem *) itemFromIndex(index); - appletNames += '\n' + selectedItem->pluginName().toUtf8(); - //kDebug() << selectedItem->pluginName() << index.column() << index.row(); - } - - data->setData(format, appletNames); - return data; -} - -void PlasmaAppletItemModel::setFavorite(const QString &plugin, bool favorite) -{ - if (favorite) { - if (!m_favorites.contains(plugin)) { - m_favorites.append(plugin); - } - } else { - if (m_favorites.contains(plugin)) { - m_favorites.removeAll(plugin); - } - } - m_configGroup.writeEntry("favorites", m_favorites.join(",")); - m_configGroup.sync(); - -} - -void PlasmaAppletItemModel::setApplication(const QString &app) -{ - m_application = app; - populateModel(); -} - -QString &PlasmaAppletItemModel::Application() -{ - return m_application; -} - -#include - diff --git a/appletbrowser/plasmaappletitemmodel_p.h b/appletbrowser/plasmaappletitemmodel_p.h deleted file mode 100644 index 6564356dc..000000000 --- a/appletbrowser/plasmaappletitemmodel_p.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2007 Ivan Cukic - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library/Lesser General Public License - * version 2, or (at your option) any later version, as published by the - * Free Software Foundation - * - * This program 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 Library/Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef PLASMA_PLASMAAPPLETITEMMODEL_P_H -#define PLASMA_PLASMAAPPLETITEMMODEL_P_H - -#include - -#include - -#include "kcategorizeditemsview_p.h" - -class PlasmaAppletItemModel; - -/** - * Implementation of the KCategorizedItemsViewModels::AbstractItem - */ -class PlasmaAppletItem : public QObject, public KCategorizedItemsViewModels::AbstractItem -{ - Q_OBJECT - -public: - enum FilterFlag { - NoFilter = 0, - Favorite = 1, - Used = 2 - }; - - Q_DECLARE_FLAGS(FilterFlags, FilterFlag) - - PlasmaAppletItem(PlasmaAppletItemModel *model, const QMap& info, FilterFlags flags = NoFilter, QMap *extraAttrs = NULL); - - virtual QString name() const; - QString pluginName() const; - virtual QString description() const; - virtual int running() const; - virtual void setFavorite(bool favorite); - //set how many instances of this applet are running - virtual void setRunning(int count); - virtual bool passesFiltering( - const KCategorizedItemsViewModels::Filter & filter) const; - virtual QVariantList arguments() const; - -private: - PlasmaAppletItemModel * m_model; -}; - -class PlasmaAppletItemModel : - public KCategorizedItemsViewModels::DefaultItemModel -{ - Q_OBJECT - -public: - explicit PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent = 0); - - QStringList mimeTypes() const; - - QMimeData *mimeData(const QModelIndexList &indexes) const; - - void setFavorite(const QString &plugin, bool favorite); - void setApplication(const QString &app); - void setRunningApplets(const QHash &apps); - void setRunningApplets(const QString &name, int count); - - QString &Application(); - -private: - QString m_application; - QStringList m_favorites; - QStringList m_used; - KConfigGroup m_configGroup; - -private slots: - void populateModel(); -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(PlasmaAppletItem::FilterFlags) - -#endif /*PLASMAAPPLETSMODEL_H_*/ diff --git a/includes/AppletBrowser b/includes/AppletBrowser deleted file mode 100644 index 3b95a41dd..000000000 --- a/includes/AppletBrowser +++ /dev/null @@ -1 +0,0 @@ -#include "../../plasma/appletbrowser.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index be9d05be3..2f126c13f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,7 +14,7 @@ PLASMA_UNIT_TESTS( plasmoidpackagetest ) -set(appletbrowser_SRCS appletbrowser.cpp) -kde4_add_executable(plasmaappletbrowser ${appletbrowser_SRCS}) -target_link_libraries(plasmaappletbrowser plasma ${KDE4_KDEUI_LIBS}) +#set(appletbrowser_SRCS appletbrowser.cpp) +#kde4_add_executable(plasmaappletbrowser ${appletbrowser_SRCS}) +#target_link_libraries(plasmaappletbrowser plasma ${KDE4_KDEUI_LIBS})