Merge lp:~smartboyhw/ubuntu/raring/homerun/0.2.1-0ubuntu1-version-1 into lp:ubuntu/raring/homerun

Proposed by Howard Chan
Status: Merged
Merge reported by: Philip Muškovac
Merged at revision: not available
Proposed branch: lp:~smartboyhw/ubuntu/raring/homerun/0.2.1-0ubuntu1-version-1
Merge into: lp:ubuntu/raring/homerun
Diff against target: 12832 lines (+6090/-4867)
128 files modified
CMakeLists.txt (+2/-14)
ExtraDesktop.sh (+0/-6)
NEWS (+24/-0)
README.md (+22/-4)
applet/plasma-applet-homerunlauncher.desktop.cmake (+13/-0)
components/CMakeLists.txt (+28/-15)
components/componentsplugin.cpp (+4/-0)
components/dirconfigurationwidget.cpp (+0/-67)
components/dirconfigurationwidget.h (+0/-48)
components/dirconfigurationwidget.ui (+0/-83)
components/dirmodel.cpp (+0/-240)
components/dirmodel.h (+0/-111)
components/favoriteappsmodel.cpp (+0/-215)
components/favoriteappsmodel.h (+0/-81)
components/favoriteplacesmodel.cpp (+0/-138)
components/favoriteplacesmodel.h (+0/-75)
components/groupedinstalledappsmodel.cpp (+0/-134)
components/groupedinstalledappsmodel.h (+0/-75)
components/installedappsconfigurationwidget.cpp (+0/-145)
components/installedappsconfigurationwidget.h (+0/-63)
components/installedappsconfigurationwidget.ui (+0/-50)
components/installedappsmodel.cpp (+0/-319)
components/installedappsmodel.h (+0/-159)
components/messagebox.cpp (+45/-0)
components/messagebox.h (+60/-0)
components/powermodel.cpp (+0/-143)
components/powermodel.h (+0/-75)
components/qml/Label.qml (+68/-0)
components/qml/TabButton.qml (+28/-2)
components/qml/qmldir (+1/-0)
components/runnerconfigurationwidget.cpp (+0/-105)
components/runnerconfigurationwidget.h (+0/-48)
components/runnerconfigurationwidget.ui (+0/-48)
components/runnermodel.cpp (+0/-408)
components/runnermodel.h (+0/-150)
components/sessionmodel.cpp (+0/-137)
components/sessionmodel.h (+0/-72)
components/shadoweffect.cpp (+222/-0)
components/shadoweffect.h (+87/-0)
components/sourceid.cpp (+0/-163)
components/sourceid.h (+0/-66)
components/sourceregistry.cpp (+32/-9)
components/sources/dir/dirconfigurationwidget.cpp (+67/-0)
components/sources/dir/dirconfigurationwidget.h (+48/-0)
components/sources/dir/dirconfigurationwidget.ui (+83/-0)
components/sources/dir/dirmodel.cpp (+259/-0)
components/sources/dir/dirmodel.h (+113/-0)
components/sources/favorites/favoriteappsmodel.cpp (+215/-0)
components/sources/favorites/favoriteappsmodel.h (+81/-0)
components/sources/favorites/favoriteplacesmodel.cpp (+162/-0)
components/sources/favorites/favoriteplacesmodel.h (+77/-0)
components/sources/installedapps/groupedinstalledappsmodel.cpp (+134/-0)
components/sources/installedapps/groupedinstalledappsmodel.h (+75/-0)
components/sources/installedapps/installedappsconfigurationwidget.cpp (+145/-0)
components/sources/installedapps/installedappsconfigurationwidget.h (+63/-0)
components/sources/installedapps/installedappsconfigurationwidget.ui (+50/-0)
components/sources/installedapps/installedappsmodel.cpp (+319/-0)
components/sources/installedapps/installedappsmodel.h (+159/-0)
components/sources/power/powermodel.cpp (+108/-0)
components/sources/power/powermodel.h (+40/-0)
components/sources/runners/querymatchmodel.cpp (+194/-0)
components/sources/runners/querymatchmodel.h (+84/-0)
components/sources/runners/runnerconfigurationwidget.cpp (+105/-0)
components/sources/runners/runnerconfigurationwidget.h (+48/-0)
components/sources/runners/runnerconfigurationwidget.ui (+48/-0)
components/sources/runners/runnermodel.cpp (+295/-0)
components/sources/runners/runnermodel.h (+134/-0)
components/sources/runners/singlerunnermodel.cpp (+131/-0)
components/sources/runners/singlerunnermodel.h (+87/-0)
components/sources/session/openedsessionsmodel.cpp (+92/-0)
components/sources/session/openedsessionsmodel.h (+53/-0)
components/sources/session/sessionmodel.cpp (+118/-0)
components/sources/session/sessionmodel.h (+45/-0)
components/sources/session/sessionswatcher.cpp (+92/-0)
components/sources/session/sessionswatcher.h (+53/-0)
components/standarditemmodel.cpp (+90/-0)
components/standarditemmodel.h (+79/-0)
components/tabmodel.cpp (+64/-111)
components/tabmodel.h (+5/-0)
config/homerunrc (+4/-1)
debian/changelog (+10/-0)
debian/control (+1/-1)
debian/libhomerun-dev.install (+1/-0)
debian/libhomerun0.symbols (+7/-0)
debian/plasma-widget-homerun.install (+4/-5)
devdoc/helloworld/homerun-source-helloworld.desktop (+18/-0)
devdoc/release_howto.md (+6/-5)
fixes/CMakeLists.txt (+0/-1)
fixes/README.md (+2/-29)
fixes/datamodel.cpp (+0/-171)
fixes/datamodel.h (+0/-119)
fixes/fixesplugin.cpp (+4/-5)
fixes/qml/Label.qml (+0/-69)
fixes/qml/ScrollArea.qml (+0/-248)
fixes/qml/TextField.qml (+196/-149)
fixes/qml/private/IconLoader.qml (+0/-140)
fixes/qml/qmldir (+0/-2)
homerun_config.h.in (+0/-3)
internal/i18nconfig.cpp (+34/-0)
lib/CMakeLists.txt (+3/-0)
lib/actionlist.cpp (+116/-0)
lib/actionlist.h (+63/-0)
lib/homerun-source.desktop (+9/-0)
lib/homerunmodel.dox (+38/-3)
package/contents/config/main.xml (+22/-10)
package/contents/ui/ActionMenu.qml (+102/-0)
package/contents/ui/FavoriteFeedback.qml (+0/-55)
package/contents/ui/Page.qml (+12/-12)
package/contents/ui/Result.qml (+90/-55)
package/contents/ui/ResultsView.qml (+69/-46)
package/contents/ui/SourceItem.qml (+10/-1)
package/contents/ui/TabContent.qml (+24/-19)
package/contents/ui/config.ui (+108/-0)
package/contents/ui/main.qml (+37/-29)
package/metadata.desktop.cmake (+15/-0)
plugins/recentdocuments/homerun-source-recentdocuments.desktop (+19/-0)
plugins/recentdocuments/recentdocuments.cpp (+64/-6)
plugins/recentdocuments/recentdocuments.h (+13/-1)
shell/fullview.cpp (+23/-11)
shell/fullview.h (+2/-0)
shell/homerunviewer.desktop (+13/-0)
shell/main.cpp (+30/-2)
tests/auto/CMakeLists.txt (+19/-10)
tests/auto/i18nconfigtest.cpp (+52/-0)
tests/auto/i18nconfigtest.h (+37/-0)
tests/auto/tabmodeltest.cpp (+151/-79)
tests/auto/tabmodeltest.h (+1/-1)
tests/manual/keyboard-navigation.md (+10/-0)
To merge this branch: bzr merge lp:~smartboyhw/ubuntu/raring/homerun/0.2.1-0ubuntu1-version-1
Reviewer Review Type Date Requested Status
Philip Muškovac (community) Approve
Review via email: mp+151266@code.launchpad.net

Description of the change

New upstream version 0.2.1.

To post a comment you must log in.
6. By Howard Chan

Added watch file

Revision history for this message
Philip Muškovac (yofel) wrote :

Great, thanks!
I fixed one additional thing:
W: libhomerun-dev: wrong-section-according-to-package-name libhomerun-dev => libdevel

review: Approve
Revision history for this message
Philip Muškovac (yofel) wrote :

Meh, noticed one thing too late: the watch file is missing.
Can you please file a new request for ubuntu2 that actually adds it? I'll upload it asap then.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2012-12-18 19:55:12 +0000
+++ CMakeLists.txt 2013-03-01 15:15:27 +0000
@@ -3,7 +3,7 @@
3SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})3SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})
44
5# Packaging5# Packaging
6set(HOMERUN_VERSION "0.1.1")6set(HOMERUN_VERSION "0.2.1")
77
8set(HOMERUN_SOURCE_VERSION "")8set(HOMERUN_SOURCE_VERSION "")
9set(HOMERUN_SOURCE_DATE "")9set(HOMERUN_SOURCE_DATE "")
@@ -23,23 +23,11 @@
23message(STATUS "Source date: ${HOMERUN_SOURCE_DATE}")23message(STATUS "Source date: ${HOMERUN_SOURCE_DATE}")
2424
25# Dependencies25# Dependencies
26find_package(KDE4 ${KDE_MIN_VERSION} REQUIRED)26find_package(KDE4 4.9.97 REQUIRED)
27include(KDE4Defaults)27include(KDE4Defaults)
28find_package(KDE4Workspace REQUIRED)28find_package(KDE4Workspace REQUIRED)
29find_package(KDeclarative REQUIRED)29find_package(KDeclarative REQUIRED)
3030
31# Check whether KDeclarative::setupQmlJsDebugger() exists
32set(CMAKE_REQUIRED_INCLUDES "${KDE4_INCLUDES}")
33set(CMAKE_REQUIRED_LIBRARIES "${KDECLARATIVE_LIBRARIES}")
34check_cxx_source_compiles("
35#include <kdeclarative.h>
36int main()
37{
38 KDeclarative::setupQmlJsDebugger();
39 return 0;
40}
41" HAVE_KDECLARATIVE_SETUPQMLJSDEBUGGER)
42
43# Compile options31# Compile options
44add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})32add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
45add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)33add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
4634
=== removed file 'ExtraDesktop.sh'
--- ExtraDesktop.sh 2012-11-14 21:30:06 +0000
+++ ExtraDesktop.sh 1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
1#! /bin/sh
2#This file outputs in a separate line each file with a .desktop syntax
3#that needs to be translated but has a non .desktop extension
4
5#We output homerunrc because we want the title of Homerun tabs to be translated
6echo ./config/homerunrc
70
=== modified file 'NEWS'
--- NEWS 2012-12-18 19:55:12 +0000
+++ NEWS 2013-03-01 15:15:27 +0000
@@ -1,3 +1,27 @@
1# 2013.02.27 - 0.2.1
2
3- Fix shutdown and halt items in the Power source
4- Improve appearance of header titles
5
6# 2013.02.26 - 0.2.0
7
8- Support for single runners
9- Items can now have more than one action. The other actions are accessible
10 through a context menu, which can be triggered by:
11 - Left-clicking the arrow in the top-right corner of the item
12 - Long-clicking the item
13 - Right-clicking the item
14 - Pressing M or the "Menu" key
15- Some sources expose more actions:
16 - Recent documents can now forget items
17 - Items from the Dir and FavoritePlaces sources show the relevant "Open with" actions
18- Add a "Reset tabs to default" action to the configuration menu
19- Fix window not showing on correct desktop at startup
20- Improved session handling: opened sessions are now listed in the "Power" tab
21- Hide unavailable sleep modes in Power source
22- No more border around full view
23- Show a shadow behind text in containment mode
24
1# 2012.12.18 - 0.1.125# 2012.12.18 - 0.1.1
226
3- Add support for selecting the launcher icon27- Add support for selecting the launcher icon
428
=== modified file 'README.md'
--- README.md 2012-11-14 21:30:06 +0000
+++ README.md 2013-03-01 15:15:27 +0000
@@ -21,16 +21,34 @@
2121
22## Dependencies22## Dependencies
2323
24kdelibs 4.824kdelibs 4.10
2525
26## Package Manager integration26## Build instructions
27
28Homerun currently requires kdelibs and kde-runtime 4.10.
29
30To build it, do the following:
31
32 mkdir build
33 cd build
34 cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` ..
35
36Assuming cmake did not complain about missing dependencies, run:
37
38 make
39
40Then to install it, run as root:
41
42 make install
43
44## For packagers: Package manager integration
2745
28You can integrate your package manager with Homerun.46You can integrate your package manager with Homerun.
2947
30When browsing installed applications by category, Homerun can provide an item to48When browsing installed applications by category, Homerun can provide an item to
31install more applications from this category. To do so you need to:49install more applications from this category. To do so you need to:
3250
33First, Create a .desktop file whose Exec= line contains a "@category" placeholder.51First, create a .desktop file whose Exec= line contains a "@category" placeholder.
34This placeholder will be replaced by the category Homerun is browsing.52This placeholder will be replaced by the category Homerun is browsing.
3553
36For example, here is muon-discover-category.desktop:54For example, here is muon-discover-category.desktop:
3755
=== modified file 'applet/plasma-applet-homerunlauncher.desktop.cmake'
--- applet/plasma-applet-homerunlauncher.desktop.cmake 2012-12-18 19:55:12 +0000
+++ applet/plasma-applet-homerunlauncher.desktop.cmake 2013-03-01 15:15:27 +0000
@@ -4,32 +4,45 @@
4Name=KDE Homerun Launcher4Name=KDE Homerun Launcher
5Name[da]=KDE Homerun-startmenu5Name[da]=KDE Homerun-startmenu
6Name[el]=Εκτελεστής KDE Homerun6Name[el]=Εκτελεστής KDE Homerun
7Name[es]=Lanzador Homerun de KDE
7Name[et]=KDE Homeruni käivitaja8Name[et]=KDE Homeruni käivitaja
9Name[fi]=KDE Homerun -käynnistin
8Name[fr]=Lanceur Homerun pour KDE10Name[fr]=Lanceur Homerun pour KDE
11Name[gl]=Lanzador de KDE Homerun
9Name[hu]=KDE Homerun indító12Name[hu]=KDE Homerun indító
13Name[lt]=KDE Homerun leidiklis
10Name[nl]=Programmastarter van KDE Homerun14Name[nl]=Programmastarter van KDE Homerun
11Name[pa]=ਕੇਡੀਈ ਹੋਮਰਨ ਲਾਂਚਰ15Name[pa]=ਕੇਡੀਈ ਹੋਮਰਨ ਲਾਂਚਰ
12Name[pt]=Lançador Homerun do KDE16Name[pt]=Lançador Homerun do KDE
13Name[pt_BR]=Lançador Homerun do KDE17Name[pt_BR]=Lançador Homerun do KDE
18Name[ro]=Lansator KDE Homerun
14Name[sk]=Spúšťač KDE Homerun19Name[sk]=Spúšťač KDE Homerun
15Name[sv]=KDE Homerun startprogram20Name[sv]=KDE Homerun startprogram
16Name[uk]=Засіб запуску KDE Homerun21Name[uk]=Засіб запуску KDE Homerun
17Name[x-test]=xxKDE Homerun Launcherxx22Name[x-test]=xxKDE Homerun Launcherxx
23Name[zh_CN]=KDE Homerun 启动器
1824
19Comment=An application launcher25Comment=An application launcher
20Comment[da]=Programstarter26Comment[da]=Programstarter
27Comment[de]=Ein Anwendungsstarter
21Comment[el]=Ένας εκτελεστής εφαρμογών28Comment[el]=Ένας εκτελεστής εφαρμογών
29Comment[es]=Un lanzador de aplicaciones
22Comment[et]=Rakenduste käivitaja30Comment[et]=Rakenduste käivitaja
31Comment[fi]=Sovelluskäynnistin
23Comment[fr]=Un lanceur d'applications32Comment[fr]=Un lanceur d'applications
33Comment[gl]=Un lanzador de aplicativos
24Comment[hu]=Egy alkalmazásindító34Comment[hu]=Egy alkalmazásindító
35Comment[lt]=Programų leidiklis
25Comment[nl]=Een programmastarter36Comment[nl]=Een programmastarter
26Comment[pa]=ਐਪਲੀਕੇਸ਼ਨ ਲਾਂਚਰ37Comment[pa]=ਐਪਲੀਕੇਸ਼ਨ ਲਾਂਚਰ
27Comment[pt]=Um lançador de aplicações38Comment[pt]=Um lançador de aplicações
28Comment[pt_BR]=Um lançador de aplicativos39Comment[pt_BR]=Um lançador de aplicativos
40Comment[ro]=Lansator de aplicații
29Comment[sk]=Spúšťač aplikácií41Comment[sk]=Spúšťač aplikácií
30Comment[sv]=Ett startprogram42Comment[sv]=Ett startprogram
31Comment[uk]=Засіб для запуску програм43Comment[uk]=Засіб для запуску програм
32Comment[x-test]=xxAn application launcherxx44Comment[x-test]=xxAn application launcherxx
45Comment[zh_CN]=一个应用程序启动器
3346
34Type=Service47Type=Service
35ServiceTypes=Plasma/Applet48ServiceTypes=Plasma/Applet
3649
=== modified file 'components/CMakeLists.txt'
--- components/CMakeLists.txt 2012-11-14 21:30:06 +0000
+++ components/CMakeLists.txt 2013-03-01 15:15:27 +0000
@@ -4,30 +4,36 @@
4 ${CMAKE_SOURCE_DIR}/internal/aboutdata.cpp4 ${CMAKE_SOURCE_DIR}/internal/aboutdata.cpp
5 abstractsourceregistry.cpp5 abstractsourceregistry.cpp
6 componentsplugin.cpp6 componentsplugin.cpp
7 dirconfigurationwidget.cpp
8 dirmodel.cpp
9 favoriteappsmodel.cpp
10 favoriteplacesmodel.cpp
11 groupedinstalledappsmodel.cpp
12 helpmenuactions.cpp7 helpmenuactions.cpp
13 icondialog.cpp8 icondialog.cpp
14 installedappsconfigurationwidget.cpp9 messagebox.cpp
15 installedappsmodel.cpp10 shadoweffect.cpp
16 powermodel.cpp
17 runnerconfigurationwidget.cpp
18 runnermodel.cpp
19 sessionmodel.cpp
20 sourceconfigurationdialog.cpp11 sourceconfigurationdialog.cpp
21 sourceid.cpp
22 sourcemodel.cpp12 sourcemodel.cpp
23 sourceregistry.cpp13 sourceregistry.cpp
14 sources/dir/dirconfigurationwidget.cpp
15 sources/dir/dirmodel.cpp
16 sources/favorites/favoriteappsmodel.cpp
17 sources/favorites/favoriteplacesmodel.cpp
18 sources/installedapps/groupedinstalledappsmodel.cpp
19 sources/installedapps/installedappsconfigurationwidget.cpp
20 sources/installedapps/installedappsmodel.cpp
21 sources/power/powermodel.cpp
22 sources/runners/querymatchmodel.cpp
23 sources/runners/singlerunnermodel.cpp
24 sources/runners/runnerconfigurationwidget.cpp
25 sources/runners/runnermodel.cpp
26 sources/session/openedsessionsmodel.cpp
27 sources/session/sessionmodel.cpp
28 sources/session/sessionswatcher.cpp
29 standarditemmodel.cpp
24 tabmodel.cpp30 tabmodel.cpp
25 )31 )
2632
27kde4_add_ui_files(components_SRCS33kde4_add_ui_files(components_SRCS
28 dirconfigurationwidget.ui34 sources/dir/dirconfigurationwidget.ui
29 installedappsconfigurationwidget.ui35 sources/installedapps/installedappsconfigurationwidget.ui
30 runnerconfigurationwidget.ui36 sources/runners/runnerconfigurationwidget.ui
31 )37 )
3238
33qt4_automoc(${components_SRCS})39qt4_automoc(${components_SRCS})
@@ -36,6 +42,12 @@
36 ${lib_BINARY_DIR}42 ${lib_BINARY_DIR}
37 ${lib_SOURCE_DIR}43 ${lib_SOURCE_DIR}
38 ${CMAKE_SOURCE_DIR}/internal44 ${CMAKE_SOURCE_DIR}/internal
45 ${CMAKE_CURRENT_SOURCE_DIR}/sources/dir
46 ${CMAKE_CURRENT_SOURCE_DIR}/sources/favorites
47 ${CMAKE_CURRENT_SOURCE_DIR}/sources/installedapps
48 ${CMAKE_CURRENT_SOURCE_DIR}/sources/power
49 ${CMAKE_CURRENT_SOURCE_DIR}/sources/runners
50 ${CMAKE_CURRENT_SOURCE_DIR}/sources/session
39 )51 )
4052
41kde4_add_library(componentsplugin SHARED ${components_SRCS})53kde4_add_library(componentsplugin SHARED ${components_SRCS})
@@ -46,6 +58,7 @@
46 ${KDE4_PLASMA_LIBS}58 ${KDE4_PLASMA_LIBS}
47 ${KDE4_KIO_LIBS}59 ${KDE4_KIO_LIBS}
48 ${KDE4_KFILE_LIBS}60 ${KDE4_KFILE_LIBS}
61 ${KDE4_SOLID_LIBS}
49 ${KDE4WORKSPACE_KWORKSPACE_LIBS}62 ${KDE4WORKSPACE_KWORKSPACE_LIBS}
50 homerun63 homerun
51 )64 )
5265
=== modified file 'components/componentsplugin.cpp'
--- components/componentsplugin.cpp 2012-11-14 21:30:06 +0000
+++ components/componentsplugin.cpp 2013-03-01 15:15:27 +0000
@@ -24,14 +24,18 @@
2424
25#include <helpmenuactions.h>25#include <helpmenuactions.h>
26#include <icondialog.h>26#include <icondialog.h>
27#include <messagebox.h>
28#include <shadoweffect.h>
27#include <sourceregistry.h>29#include <sourceregistry.h>
28#include <tabmodel.h>30#include <tabmodel.h>
2931
30void ComponentsPlugin::registerTypes(const char *uri)32void ComponentsPlugin::registerTypes(const char *uri)
31{33{
32 Q_ASSERT(uri == QLatin1String("org.kde.homerun.components"));34 Q_ASSERT(uri == QLatin1String("org.kde.homerun.components"));
35 qmlRegisterType<ShadowEffect>(uri, 0, 1, "ShadowEffect");
33 qmlRegisterType<HelpMenuActions>(uri, 0, 1, "HelpMenuActions");36 qmlRegisterType<HelpMenuActions>(uri, 0, 1, "HelpMenuActions");
34 qmlRegisterType<IconDialog>(uri, 0, 1, "IconDialog");37 qmlRegisterType<IconDialog>(uri, 0, 1, "IconDialog");
38 qmlRegisterType<MessageBox>(uri, 0, 1, "MessageBox");
35 qmlRegisterType<Homerun::AbstractSourceRegistry>(uri, 0, 1, "AbstractSourceRegistry");39 qmlRegisterType<Homerun::AbstractSourceRegistry>(uri, 0, 1, "AbstractSourceRegistry");
36 qmlRegisterType<Homerun::SourceRegistry>(uri, 0, 1, "SourceRegistry");40 qmlRegisterType<Homerun::SourceRegistry>(uri, 0, 1, "SourceRegistry");
37 qmlRegisterType<TabModel>(uri, 0, 1, "TabModel");41 qmlRegisterType<TabModel>(uri, 0, 1, "TabModel");
3842
=== removed file 'components/dirconfigurationwidget.cpp'
--- components/dirconfigurationwidget.cpp 2012-11-14 21:30:06 +0000
+++ components/dirconfigurationwidget.cpp 1970-01-01 00:00:00 +0000
@@ -1,67 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Self
21#include <dirconfigurationwidget.h>
22
23// Local
24#include <ui_dirconfigurationwidget.h>
25
26// KDE
27#include <KGlobalSettings>
28#include <KUrlRequester>
29
30// Qt
31#include <QDir>
32#include <QVBoxLayout>
33
34using namespace Homerun;
35
36DirConfigurationWidget::DirConfigurationWidget(const KConfigGroup &group)
37: SourceConfigurationWidget(group)
38, m_ui(new Ui_DirConfigurationWidget)
39{
40 m_ui->setupUi(this);
41
42 QFont helpFont = KGlobalSettings::smallestReadableFont();
43 m_ui->titleHelpLabel->setFont(helpFont);
44
45 KUrl url = group.readPathEntry("rootUrl", QDir::homePath());
46 if (url.isValid()) {
47 m_ui->urlRequester->setUrl(url);
48 }
49
50 m_ui->titleLineEdit->setText(group.readEntry("rootName", QString()));
51}
52
53DirConfigurationWidget::~DirConfigurationWidget()
54{
55 delete m_ui;
56}
57
58void DirConfigurationWidget::save()
59{
60 KUrl url = m_ui->urlRequester->url().url();
61 QString title = m_ui->titleLineEdit->text();
62
63 configGroup().writePathEntry("rootUrl", url.url());
64 configGroup().writeEntry("rootName", title);
65}
66
67#include <dirconfigurationwidget.moc>
680
=== removed file 'components/dirconfigurationwidget.h'
--- components/dirconfigurationwidget.h 2012-11-14 21:30:06 +0000
+++ components/dirconfigurationwidget.h 1970-01-01 00:00:00 +0000
@@ -1,48 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef DIRCONFIGURATIONWIDGET_H
21#define DIRCONFIGURATIONWIDGET_H
22
23// Local
24#include <sourceconfigurationwidget.h>
25
26// Qt
27
28// KDE
29
30class Ui_DirConfigurationWidget;
31
32/**
33 * Configuration widget for the Dir source
34 */
35class DirConfigurationWidget : public Homerun::SourceConfigurationWidget
36{
37 Q_OBJECT
38public:
39 DirConfigurationWidget(const KConfigGroup &group);
40 ~DirConfigurationWidget();
41
42 void save(); // reimp
43
44private:
45 Ui_DirConfigurationWidget *m_ui;
46};
47
48#endif /* DIRCONFIGURATIONWIDGET_H */
490
=== removed file 'components/dirconfigurationwidget.ui'
--- components/dirconfigurationwidget.ui 2012-11-14 21:30:06 +0000
+++ components/dirconfigurationwidget.ui 1970-01-01 00:00:00 +0000
@@ -1,83 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>DirConfigurationWidget</class>
4 <widget class="QWidget" name="DirConfigurationWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>400</width>
10 <height>85</height>
11 </rect>
12 </property>
13 <property name="sizePolicy">
14 <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
15 <horstretch>0</horstretch>
16 <verstretch>0</verstretch>
17 </sizepolicy>
18 </property>
19 <property name="minimumSize">
20 <size>
21 <width>400</width>
22 <height>0</height>
23 </size>
24 </property>
25 <property name="windowTitle">
26 <string/>
27 </property>
28 <layout class="QFormLayout" name="formLayout">
29 <item row="1" column="0">
30 <widget class="QLabel" name="label_2">
31 <property name="text">
32 <string>Folder to show:</string>
33 </property>
34 <property name="buddy">
35 <cstring>urlRequester</cstring>
36 </property>
37 </widget>
38 </item>
39 <item row="1" column="1">
40 <widget class="KUrlRequester" name="urlRequester">
41 <property name="mode">
42 <set>KFile::Directory|KFile::ExistingOnly</set>
43 </property>
44 </widget>
45 </item>
46 <item row="2" column="1">
47 <widget class="QLineEdit" name="titleLineEdit"/>
48 </item>
49 <item row="2" column="0">
50 <widget class="QLabel" name="label">
51 <property name="text">
52 <string>Title:</string>
53 </property>
54 <property name="buddy">
55 <cstring>titleLineEdit</cstring>
56 </property>
57 </widget>
58 </item>
59 <item row="3" column="1">
60 <widget class="QLabel" name="titleHelpLabel">
61 <property name="sizePolicy">
62 <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
63 <horstretch>0</horstretch>
64 <verstretch>0</verstretch>
65 </sizepolicy>
66 </property>
67 <property name="text">
68 <string>If title is left empty, the folder name will be used</string>
69 </property>
70 </widget>
71 </item>
72 </layout>
73 </widget>
74 <customwidgets>
75 <customwidget>
76 <class>KUrlRequester</class>
77 <extends>QFrame</extends>
78 <header>kurlrequester.h</header>
79 </customwidget>
80 </customwidgets>
81 <resources/>
82 <connections/>
83</ui>
840
=== removed file 'components/dirmodel.cpp'
--- components/dirmodel.cpp 2012-12-18 19:55:12 +0000
+++ components/dirmodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,240 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Self
21#include <dirmodel.h>
22
23// Local
24#include <dirconfigurationwidget.h>
25#include <pathmodel.h>
26#include <favoriteplacesmodel.h>
27
28// KDE
29#include <KConfigGroup>
30#include <KDebug>
31#include <KDirModel>
32#include <KDirLister>
33
34// Qt
35#include <QDir>
36
37namespace Homerun
38{
39
40static const char *SOURCE_ID = "Dir";
41
42static inline KFileItem itemForIndex(const QModelIndex &index)
43{
44 return index.data(KDirModel::FileItemRole).value<KFileItem>();
45}
46
47//- DirModel ------------------------------------------------------
48QVariantMap DirModel::sourceArguments(const KUrl &rootUrl, const QString &rootName, const KUrl &url)
49{
50 QVariantMap args;
51 args.insert("rootUrl", rootUrl.url());
52 args.insert("rootName", rootName);
53 args.insert("url", url.url());
54 return args;
55}
56
57
58DirModel::DirModel(QObject *parent)
59: KDirSortFilterProxyModel(parent)
60, m_pathModel(new PathModel(this))
61{
62 setSourceModel(new KDirModel(this));
63 setSortFoldersFirst(true);
64
65 QHash<int, QByteArray> roles;
66 roles.insert(Qt::DisplayRole, "display");
67 roles.insert(Qt::DecorationRole, "decoration");
68 roles.insert(DirModel::FavoriteIdRole, "favoriteId");
69 setRoleNames(roles);
70
71 dirLister()->setDelayedMimeTypes(true);
72 connect(dirLister(), SIGNAL(started(KUrl)), SLOT(emitRunningChanged()));
73 connect(dirLister(), SIGNAL(completed()), SLOT(emitRunningChanged()));
74}
75
76void DirModel::init(const KUrl &rootUrl, const QString &rootName, const KUrl &url)
77{
78 m_rootUrl = rootUrl;
79 m_rootName = rootName;
80 initPathModel(url);
81 dirLister()->openUrl(url);
82}
83
84void DirModel::initPathModel(const KUrl &openedUrl)
85{
86 QVariantMap args = sourceArguments(m_rootUrl, m_rootName, m_rootUrl);
87 m_pathModel->addPath(m_rootName, SOURCE_ID, args);
88
89 KUrl rootUrl = m_rootUrl;
90 // Needed for KUrl::relativeUrl
91 rootUrl.adjustPath(KUrl::AddTrailingSlash);
92 QString relativePath = KUrl::relativeUrl(rootUrl, openedUrl);
93 if (relativePath == "./") {
94 return;
95 }
96 KUrl url = m_rootUrl;
97 Q_FOREACH(const QString &token, relativePath.split('/')) {
98 if (token.isEmpty()) {
99 // Just in case relativePath ends with '/'
100 continue;
101 }
102 url.addPath(token);
103 args["url"] = url.url();
104 m_pathModel->addPath(token, SOURCE_ID, args);
105 }
106}
107
108KDirLister *DirModel::dirLister() const
109{
110 return static_cast<KDirModel *>(sourceModel())->dirLister();
111}
112
113QVariant DirModel::data(const QModelIndex &index, int role) const
114{
115 if (role != FavoriteIdRole) {
116 return QSortFilterProxyModel::data(index, role);
117 }
118 if (index.row() < 0 || index.row() >= rowCount()) {
119 return QVariant();
120 }
121
122 KFileItem item = itemForIndex(index);
123 if (item.isDir()) {
124 return FavoritePlacesModel::favoriteIdFromUrl(item.url());
125 } else {
126 return QString();
127 }
128}
129
130int DirModel::count() const
131{
132 return rowCount(QModelIndex());
133}
134
135QString DirModel::name() const
136{
137 return m_rootName;
138}
139
140bool DirModel::running() const
141{
142 return !dirLister()->isFinished();
143}
144
145PathModel *DirModel::pathModel() const
146{
147 return m_pathModel;
148}
149
150QString DirModel::query() const
151{
152 return filterRegExp().pattern();
153}
154
155void DirModel::setQuery(const QString &value)
156{
157 if (value == query()) {
158 return;
159 }
160 setFilterRegExp(QRegExp(value, Qt::CaseInsensitive));
161 queryChanged(value);
162}
163
164void DirModel::emitRunningChanged()
165{
166 runningChanged(running());
167}
168
169bool DirModel::trigger(int row)
170{
171 bool closed = false;
172 QModelIndex idx = index(row, 0);
173
174 KFileItem item = itemForIndex(idx);
175 if (item.isDir()) {
176 openSourceRequested(SOURCE_ID, sourceArguments(m_rootUrl, m_rootName, item.url()));
177 } else {
178 item.run();
179 closed = true;
180 }
181 return closed;
182}
183
184//- DirSource -------------------------------------------------------
185DirSource::DirSource(QObject *parent)
186: AbstractSource(parent)
187{}
188
189QAbstractItemModel *DirSource::createModelFromArguments(const QVariantMap &args)
190{
191 KUrl rootUrl = args.value("rootUrl").toString();
192 QString rootName = args.value("rootName").toString();
193 KUrl url = args.value("url").toString();
194 return createModel(rootUrl, rootName, url);
195}
196
197QAbstractItemModel *DirSource::createModelFromConfigGroup(const KConfigGroup &group)
198{
199 KUrl rootUrl = group.readPathEntry("rootUrl", QDir::homePath());
200 QString rootName = group.readEntry("rootName", QString());
201 return createModel(rootUrl, rootName, KUrl());
202}
203
204QAbstractItemModel *DirSource::createModel(const KUrl &rootUrl_, const QString &rootName_, const KUrl &url_)
205{
206 KUrl rootUrl = rootUrl_;
207 QString rootName = rootName_;
208 KUrl url = url_;
209 if (!rootUrl.isValid()) {
210 rootUrl = KUrl::fromPath(QDir::homePath());
211 }
212
213 if (rootName.isEmpty()) {
214 rootName = rootUrl.fileName();
215 if (rootName.isEmpty()) {
216 rootName = rootUrl.prettyUrl();
217 }
218 }
219 if (!url.isValid()) {
220 url = rootUrl;
221 }
222
223 DirModel *model = new DirModel;
224 model->init(rootUrl, rootName, url);
225 return model;
226}
227
228bool DirSource::isConfigurable() const
229{
230 return true;
231}
232
233SourceConfigurationWidget *DirSource::createConfigurationWidget(const KConfigGroup &group)
234{
235 return new DirConfigurationWidget(group);
236}
237
238} // namespace Homerun
239
240#include <dirmodel.moc>
2410
=== removed file 'components/dirmodel.h'
--- components/dirmodel.h 2012-11-14 21:30:06 +0000
+++ components/dirmodel.h 1970-01-01 00:00:00 +0000
@@ -1,111 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef DIRMODEL_H
21#define DIRMODEL_H
22
23// Local
24#include <abstractsource.h>
25
26// Qt
27
28// KDE
29#include <KDirSortFilterProxyModel>
30#include <KUrl>
31
32class KDirLister;
33
34namespace Homerun {
35
36class PathModel;
37
38/**
39 * Internal
40 */
41class DirModel : public KDirSortFilterProxyModel
42{
43 Q_OBJECT
44 Q_PROPERTY(int count READ count NOTIFY countChanged)
45 Q_PROPERTY(QString name READ name CONSTANT)
46
47 Q_PROPERTY(bool running READ running NOTIFY runningChanged)
48 Q_PROPERTY(QObject *pathModel READ pathModel CONSTANT)
49 Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged)
50public:
51 explicit DirModel(QObject *parent = 0);
52
53 void init(const KUrl &rootUrl, const QString &rootName, const KUrl &url);
54
55 enum {
56 FavoriteIdRole = Qt::UserRole + 1,
57 };
58
59 Q_INVOKABLE bool trigger(int row);
60
61 KDirLister *dirLister() const;
62
63 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; // reimp
64
65 PathModel *pathModel() const;
66
67 int count() const;
68
69 QString name() const;
70
71 bool running() const;
72
73 QString query() const;
74
75 void setQuery(const QString &query);
76
77 static QVariantMap sourceArguments(const KUrl &rootUrl, const QString &rootName, const KUrl &url);
78
79Q_SIGNALS:
80 void countChanged();
81 void runningChanged(bool);
82 void openSourceRequested(const QString &sourceId, const QVariantMap &sourceArguments);
83 void queryChanged(const QString &);
84
85private Q_SLOTS:
86 void emitRunningChanged();
87
88private:
89 PathModel *m_pathModel;
90 KUrl m_rootUrl;
91 QString m_rootName;
92
93 void initPathModel(const KUrl &url);
94};
95
96class DirSource : public AbstractSource
97{
98public:
99 DirSource(QObject *parent);
100 QAbstractItemModel *createModelFromConfigGroup(const KConfigGroup &group);
101 QAbstractItemModel *createModelFromArguments(const QVariantMap &args);
102 bool isConfigurable() const;
103 SourceConfigurationWidget *createConfigurationWidget(const KConfigGroup &group);
104
105private:
106 QAbstractItemModel *createModel(const KUrl &rootUrl, const QString &rootName, const KUrl &url);
107};
108
109} // namespace Homerun
110
111#endif /* DIRMODEL_H */
1120
=== removed file 'components/favoriteappsmodel.cpp'
--- components/favoriteappsmodel.cpp 2012-11-14 21:30:06 +0000
+++ components/favoriteappsmodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,215 +0,0 @@
1/*
2 Copyright 2009 Ivan Cukic <ivan.cukic+kde@gmail.com>
3 Copyright 2010 Marco Martin <notmart@gmail.com>
4 Copyright 2012 Aurélien Gâteau <agateau@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22// Own
23#include "favoriteappsmodel.h"
24
25// Qt
26
27// KDE
28#include <KDebug>
29#include <KIcon>
30#include <KConfigGroup>
31#include <KLocale>
32#include <KRun>
33#include <KService>
34
35namespace Homerun {
36
37static QString serviceIdFromFavoriteId(const QString &favoriteId)
38{
39 if (!favoriteId.startsWith("app:")) {
40 kWarning() << "Wrong favoriteId" << favoriteId;
41 return QString();
42 }
43 return favoriteId.mid(4);
44}
45
46FavoriteAppsModel::FavoriteAppsModel(QObject *parent)
47: QAbstractListModel(parent)
48{
49 QHash<int, QByteArray> roles;
50 roles.insert(Qt::DisplayRole, "display");
51 roles.insert(Qt::DecorationRole, "decoration");
52 roles.insert(FavoriteIdRole, "favoriteId");
53 setRoleNames(roles);
54 setConfig(KSharedConfig::openConfig("homerunrc"));
55}
56
57FavoriteAppsModel::~FavoriteAppsModel()
58{
59}
60
61void FavoriteAppsModel::setConfig(const KSharedConfig::Ptr &ptr)
62{
63 m_config = ptr;
64
65 KConfigGroup baseGroup(m_config, "favorites");
66
67 // get all the favorites
68 QMap<int, KService::Ptr> favoriteMap;
69 foreach (const QString &favoriteGroup, baseGroup.groupList()) {
70 if (favoriteGroup.startsWith("favorite-")) {
71 KConfigGroup favoriteConfig(&baseGroup, favoriteGroup);
72 int rank = favoriteGroup.split("-").last().toInt();
73 QString id = favoriteConfig.readEntry("serviceId");
74 KService::Ptr service = KService::serviceByStorageId(id);
75 if (!service.isNull()) {
76 favoriteMap.insert(rank, service);
77 }
78 }
79 }
80
81 beginResetModel();
82 m_favoriteList.clear();
83 auto it = favoriteMap.constBegin(), end = favoriteMap.constEnd();
84 for (; it != end; ++it) {
85 FavoriteInfo info = { it.key(), it.value() };
86 m_favoriteList << info;
87 }
88 endResetModel();
89 countChanged();
90}
91
92void FavoriteAppsModel::addFavorite(const QString &favoriteId)
93{
94 QString serviceId = serviceIdFromFavoriteId(favoriteId);
95 if (serviceId.isEmpty()) {
96 return;
97 }
98 KService::Ptr service = KService::serviceByStorageId(serviceId);
99 if (service.isNull()) {
100 kWarning() << "Could not find a service for" << serviceId;
101 return;
102 }
103 int rank;
104 if (!m_favoriteList.isEmpty()) {
105 rank = m_favoriteList.last().rank + 1;
106 } else {
107 rank = 0;
108 }
109 FavoriteInfo info = { rank, service };
110
111 int row = m_favoriteList.count();
112 beginInsertRows(QModelIndex(), row, row);
113 m_favoriteList << info;
114 endInsertRows();
115 countChanged();
116
117 KConfigGroup baseGroup(m_config, "favorites");
118 KConfigGroup group(&baseGroup, QString("favorite-%1").arg(rank));
119 group.writeEntry("serviceId", serviceId);
120 baseGroup.sync();
121}
122
123void FavoriteAppsModel::removeFavorite(const QString &favoriteId)
124{
125 int row = rowForFavoriteId(favoriteId);
126 if (row == -1) {
127 kWarning() << "Could not find favorite" << favoriteId;
128 return;
129 }
130 beginRemoveRows(QModelIndex(), row, row);
131 FavoriteInfo info = m_favoriteList.takeAt(row);
132 endRemoveRows();
133 countChanged();
134
135 KConfigGroup baseGroup(m_config, "favorites");
136 KConfigGroup group(&baseGroup, QString("favorite-%1").arg(info.rank));
137 group.deleteGroup();
138 baseGroup.sync();
139}
140
141bool FavoriteAppsModel::isFavorite(const QString &favoriteId) const
142{
143 return rowForFavoriteId(favoriteId) != -1;
144}
145
146int FavoriteAppsModel::rowForFavoriteId(const QString& favoriteId) const
147{
148 QString serviceId = serviceIdFromFavoriteId(favoriteId);
149 if (serviceId.isEmpty()) {
150 return -1;
151 }
152
153 for (int row = m_favoriteList.count() - 1; row >= 0; --row) {
154 const FavoriteInfo& info = m_favoriteList.at(row);
155 if (info.service->storageId() == serviceId) {
156 return row;
157 }
158 }
159 return -1;
160}
161
162int FavoriteAppsModel::count() const
163{
164 return m_favoriteList.count();
165}
166
167QString FavoriteAppsModel::name() const
168{
169 return i18n("Favorite Applications");
170}
171
172QString FavoriteAppsModel::favoritePrefix() const
173{
174 return "app";
175}
176
177int FavoriteAppsModel::rowCount(const QModelIndex &index) const
178{
179 if (index.isValid()) {
180 return 0;
181 }
182 return m_favoriteList.count();
183}
184
185QVariant FavoriteAppsModel::data(const QModelIndex &index, int role) const
186{
187 KService::Ptr service = m_favoriteList.value(index.row()).service;
188 if (service.isNull()) {
189 return QVariant();
190 }
191 if (role == Qt::DisplayRole) {
192 return service->name();
193 } else if (role == Qt::DecorationRole) {
194 return KIcon(service->icon());
195 } else if (role == FavoriteIdRole) {
196 return QVariant("app:" + service->storageId());
197 } else {
198 kWarning() << "Unhandled role" << role;
199 return QVariant();
200 }
201}
202
203bool FavoriteAppsModel::trigger(int row)
204{
205 KService::Ptr service = m_favoriteList.value(row).service;
206 if (service.isNull()) {
207 kWarning() << "Invalid row";
208 return false;
209 }
210 return KRun::run(*service, KUrl::List(), 0);
211}
212
213} // namespace Homerun
214
215#include "favoriteappsmodel.moc"
2160
=== removed file 'components/favoriteappsmodel.h'
--- components/favoriteappsmodel.h 2012-11-14 21:30:06 +0000
+++ components/favoriteappsmodel.h 1970-01-01 00:00:00 +0000
@@ -1,81 +0,0 @@
1/*
2 Copyright 2009 Ivan Cukic <ivan.cukic+kde@gmail.com>
3 Copyright 2010 Marco Martin <notmart@gmail.com>
4 Copyright 2012 Aurélien Gâteau <agateau@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef FAVORITEAPPSMODEL_H
23#define FAVORITEAPPSMODEL_H
24
25#include <QAbstractListModel>
26
27#include <KService>
28#include <KSharedConfig>
29
30namespace Homerun {
31
32struct FavoriteInfo
33{
34 int rank;
35 KService::Ptr service;
36};
37
38class FavoriteAppsModel : public QAbstractListModel
39{
40 Q_OBJECT
41 Q_PROPERTY(QString name READ name CONSTANT)
42 Q_PROPERTY(int count READ count NOTIFY countChanged)
43
44 Q_PROPERTY(QString favoritePrefix READ favoritePrefix CONSTANT)
45
46public:
47 FavoriteAppsModel(QObject *parent = 0);
48 ~FavoriteAppsModel();
49
50 enum {
51 FavoriteIdRole = Qt::UserRole + 1
52 };
53
54 int count() const;
55 QString name() const;
56 QString favoritePrefix() const;
57
58 void setConfig(const KSharedConfig::Ptr &);
59
60 int rowCount(const QModelIndex & = QModelIndex()) const;
61 QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const;
62
63 Q_INVOKABLE bool isFavorite(const QString &favoriteId) const;
64 Q_INVOKABLE void addFavorite(const QString &favoriteId);
65 Q_INVOKABLE void removeFavorite(const QString &favoriteId);
66
67 Q_INVOKABLE bool trigger(int row);
68
69Q_SIGNALS:
70 void countChanged();
71
72private:
73 KSharedConfig::Ptr m_config;
74 QList<FavoriteInfo> m_favoriteList;
75
76 int rowForFavoriteId(const QString &favoriteId) const;
77};
78
79} // namespace Homerun
80
81#endif // FAVORITEAPPSMODEL_H
820
=== removed file 'components/favoriteplacesmodel.cpp'
--- components/favoriteplacesmodel.cpp 2012-11-14 21:30:06 +0000
+++ components/favoriteplacesmodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,138 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#include "favoriteplacesmodel.h"
21
22// Local
23#include <dirmodel.h>
24
25// KDE
26#include <KDebug>
27#include <KLocale>
28
29// Qt
30
31namespace Homerun {
32
33KUrl FavoritePlacesModel::urlFromFavoriteId(const QString &favoriteId)
34{
35 if (!favoriteId.startsWith("place:")) {
36 kWarning() << "Wrong favoriteId" << favoriteId;
37 return QString();
38 }
39 return KUrl(favoriteId.mid(6));
40}
41
42QString FavoritePlacesModel::favoriteIdFromUrl(const KUrl &url)
43{
44 return "place:" + url.url();
45}
46
47//- FavoritePlacesModel ------------------------------------------------
48FavoritePlacesModel::FavoritePlacesModel(QObject *parent)
49: KFilePlacesModel(parent)
50{
51 QHash<int, QByteArray> roles;
52 roles.insert(Qt::DisplayRole, "display");
53 roles.insert(Qt::DecorationRole, "decoration");
54 roles.insert(FavoritePlacesModel::FavoriteIdRole, "favoriteId");
55 setRoleNames(roles);
56}
57
58QString FavoritePlacesModel::favoritePrefix() const
59{
60 return "place";
61}
62
63bool FavoritePlacesModel::isFavorite(const QString &favoriteId) const
64{
65 return indexForFavoriteId(favoriteId).isValid();
66}
67
68void FavoritePlacesModel::addFavorite(const QString &favoriteId)
69{
70 KUrl favoriteUrl = urlFromFavoriteId(favoriteId);
71 if (favoriteUrl.isEmpty()) {
72 return;
73 }
74 addPlace(favoriteUrl.fileName(), favoriteUrl);
75}
76
77void FavoritePlacesModel::removeFavorite(const QString &favoriteId)
78{
79 QModelIndex index = indexForFavoriteId(favoriteId);
80 if (!index.isValid()) {
81 kWarning() << "No favorite place for" << favoriteId;
82 return;
83 }
84 removePlace(index);
85}
86
87QModelIndex FavoritePlacesModel::indexForFavoriteId(const QString &favoriteId) const
88{
89 KUrl favoriteUrl = urlFromFavoriteId(favoriteId);
90 if (favoriteUrl.isEmpty()) {
91 return QModelIndex();
92 }
93 for (int row = rowCount() - 1; row >= 0; --row) {
94 QModelIndex idx = index(row, 0);
95 if (url(idx).equals(favoriteUrl, KUrl::CompareWithoutTrailingSlash)) {
96 return idx;
97 }
98 }
99 return QModelIndex();
100}
101
102QVariant FavoritePlacesModel::data(const QModelIndex &index, int role) const
103{
104 if (role != FavoriteIdRole) {
105 return KFilePlacesModel::data(index, role);
106 }
107
108 if (index.row() < 0 || index.row() >= rowCount()) {
109 return QVariant();
110 }
111 return QVariant(favoriteIdFromUrl(url(index)));
112}
113
114bool FavoritePlacesModel::trigger(int row)
115{
116 QModelIndex idx = index(row, 0);
117
118 KUrl theUrl = idx.data(KFilePlacesModel::UrlRole).value<QUrl>();
119 theUrl.adjustPath(KUrl::AddTrailingSlash);
120 QString rootName = idx.data(Qt::DisplayRole).toString();
121 openSourceRequested("Dir", DirModel::sourceArguments(theUrl, rootName, theUrl));
122
123 return false;
124}
125
126QString FavoritePlacesModel::name() const
127{
128 return i18n("Favorite Places");
129}
130
131int FavoritePlacesModel::count() const
132{
133 return rowCount(QModelIndex());
134}
135
136} // namespace Homerun
137
138#include "favoriteplacesmodel.moc"
1390
=== removed file 'components/favoriteplacesmodel.h'
--- components/favoriteplacesmodel.h 2012-11-14 21:30:06 +0000
+++ components/favoriteplacesmodel.h 1970-01-01 00:00:00 +0000
@@ -1,75 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef PLACESMODEL_H
21#define PLACESMODEL_H
22
23// Local
24
25// Qt
26
27// KDE
28#include <KFilePlacesModel>
29
30namespace Homerun {
31
32/**
33 * Adapts KFilePlacesModel to make it usable as a Homerun favorite model
34 */
35class FavoritePlacesModel : public KFilePlacesModel
36{
37 Q_OBJECT
38 Q_PROPERTY(QString favoritePrefix READ favoritePrefix CONSTANT)
39 Q_PROPERTY(int count READ count NOTIFY countChanged)
40 Q_PROPERTY(QString name READ name CONSTANT)
41
42public:
43 enum {
44 FavoriteIdRole = Qt::UserRole + 1,
45 };
46
47 FavoritePlacesModel(QObject *parent = 0);
48
49 Q_INVOKABLE bool isFavorite(const QString &favoriteId) const;
50 Q_INVOKABLE void addFavorite(const QString &favoriteId);
51 Q_INVOKABLE void removeFavorite(const QString &favoriteId);
52 Q_INVOKABLE bool trigger(int row);
53
54 QString favoritePrefix() const;
55
56 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; // reimp
57
58 QString name() const;
59
60 int count() const;
61
62 static KUrl urlFromFavoriteId(const QString &favoriteId);
63 static QString favoriteIdFromUrl(const KUrl &url);
64
65Q_SIGNALS:
66 void openSourceRequested(const QString &sourceId, const QVariantMap &sourceArguments);
67 void countChanged();
68
69private:
70 QModelIndex indexForFavoriteId(const QString &favoriteId) const;
71};
72
73} // namespace Homerun
74
75#endif /* PLACESMODEL_H */
760
=== removed file 'components/groupedinstalledappsmodel.cpp'
--- components/groupedinstalledappsmodel.cpp 2012-11-14 21:30:06 +0000
+++ components/groupedinstalledappsmodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,134 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Self
21#include <groupedinstalledappsmodel.h>
22
23// Local
24#include <abstractsourceregistry.h>
25#include <installedappsmodel.h>
26
27// KDE
28#include <KConfigGroup>
29#include <KDebug>
30
31// Qt
32
33namespace Homerun {
34
35GroupedInstalledAppsModel::GroupedInstalledAppsModel(const QString &installer, QObject *parent)
36: QAbstractListModel(parent)
37, m_installer(installer)
38{
39 loadRootEntries();
40}
41
42GroupedInstalledAppsModel::~GroupedInstalledAppsModel()
43{
44}
45
46QObject *GroupedInstalledAppsModel::modelForRow(int row) const
47{
48 if (row < 0 || row >= m_models.count()) {
49 kWarning() << "No model for row" << row << "!";
50 return 0;
51 }
52 return m_models.value(row);
53}
54
55void GroupedInstalledAppsModel::loadRootEntries()
56{
57 KServiceGroup::Ptr group = KServiceGroup::root();
58 KServiceGroup::List list = group->entries(false /* sorted: set to false as it does not seem to work */);
59
60 QMap<QString, KServiceGroup::Ptr> groupMap;
61 for( KServiceGroup::List::ConstIterator it = list.constBegin(); it != list.constEnd(); it++) {
62 const KSycocaEntry::Ptr p = (*it);
63
64 if (p->isType(KST_KServiceGroup)) {
65 KServiceGroup::Ptr subGroup = KServiceGroup::Ptr::staticCast(p);
66
67 if (!subGroup->noDisplay() && subGroup->childCount() > 0) {
68 groupMap.insert(subGroup->caption().toLower(), subGroup);
69 }
70 }
71 }
72 m_pendingGroupList = groupMap.values();
73 QMetaObject::invokeMethod(this, "loadNextGroup", Qt::QueuedConnection);
74}
75
76void GroupedInstalledAppsModel::loadNextGroup()
77{
78 if (m_pendingGroupList.isEmpty()) {
79 return;
80 }
81 KServiceGroup::Ptr group = m_pendingGroupList.takeFirst();
82 InstalledAppsModel *model = createInstalledAppsModel(group);
83 beginInsertRows(QModelIndex(), m_models.count(), m_models.count());
84 m_models << model;
85 endInsertRows();
86 QMetaObject::invokeMethod(this, "loadNextGroup", Qt::QueuedConnection);
87}
88
89int GroupedInstalledAppsModel::rowCount(const QModelIndex &parent) const
90{
91 if (parent.isValid()) {
92 return 0;
93 }
94 return m_models.count();
95}
96
97QVariant GroupedInstalledAppsModel::data(const QModelIndex &index, int role) const
98{
99 if (index.parent().isValid()) {
100 return QVariant();
101 }
102
103 InstalledAppsModel *model = m_models.value(index.row());
104 if (!model) {
105 return QVariant();
106 }
107
108 if (role == Qt::DisplayRole) {
109 return model->name();
110 } else {
111 return QVariant();
112 }
113}
114
115InstalledAppsModel *GroupedInstalledAppsModel::createInstalledAppsModel(KServiceGroup::Ptr group)
116{
117 return new InstalledAppsModel(group->entryPath(), m_installer, this);
118}
119
120//- GroupedInstalledAppsSource --------------------------------------
121GroupedInstalledAppsSource::GroupedInstalledAppsSource(QObject *parent)
122: AbstractSource(parent)
123{}
124
125QAbstractItemModel *GroupedInstalledAppsSource::createModelFromConfigGroup(const KConfigGroup &)
126{
127 KConfigGroup group(config(), "PackageManagement");
128 QString installer = group.readEntry("categoryInstaller");
129 return new GroupedInstalledAppsModel(installer);
130}
131
132} // namespace Homerun
133
134#include <groupedinstalledappsmodel.moc>
1350
=== removed file 'components/groupedinstalledappsmodel.h'
--- components/groupedinstalledappsmodel.h 2012-11-14 21:30:06 +0000
+++ components/groupedinstalledappsmodel.h 1970-01-01 00:00:00 +0000
@@ -1,75 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef GROUPEDINSTALLEDAPPSMODEL_H
21#define GROUPEDINSTALLEDAPPSMODEL_H
22
23// Local
24#include <abstractsource.h>
25
26// Qt
27#include <QAbstractListModel>
28
29// KDE
30#include <KServiceGroup>
31
32namespace Homerun {
33
34class InstalledAppsModel;
35
36/**
37 * A model which returns all services in grouped sub-models
38 */
39class GroupedInstalledAppsModel : public QAbstractListModel
40{
41 Q_OBJECT
42public:
43 explicit GroupedInstalledAppsModel(const QString &installer, QObject *parent = 0);
44 ~GroupedInstalledAppsModel();
45
46 int rowCount(const QModelIndex &parent = QModelIndex()) const; // reimp
47 QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const; // reimp
48
49 Q_INVOKABLE QObject *modelForRow(int row) const;
50
51Q_SIGNALS:
52 void installerChanged(const QString &);
53
54private Q_SLOTS:
55 void loadRootEntries();
56 void loadNextGroup();
57
58private:
59 QString m_installer;
60 QList<KServiceGroup::Ptr> m_pendingGroupList;
61 QList<InstalledAppsModel *> m_models;
62
63 InstalledAppsModel *createInstalledAppsModel(KServiceGroup::Ptr group);
64};
65
66class GroupedInstalledAppsSource : public AbstractSource
67{
68public:
69 GroupedInstalledAppsSource(QObject *parent);
70 QAbstractItemModel *createModelFromConfigGroup(const KConfigGroup &);
71};
72
73} // namespace Homerun
74
75#endif /* GROUPEDINSTALLEDAPPSMODEL_H */
760
=== removed file 'components/installedappsconfigurationwidget.cpp'
--- components/installedappsconfigurationwidget.cpp 2012-11-14 21:30:06 +0000
+++ components/installedappsconfigurationwidget.cpp 1970-01-01 00:00:00 +0000
@@ -1,145 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Self
21#include <installedappsconfigurationwidget.h>
22
23// Local
24#include <ui_installedappsconfigurationwidget.h>
25
26// KDE
27#include <KDebug>
28#include <KIcon>
29#include <KServiceGroup>
30#include <KSycocaEntry>
31
32// Qt
33#include <QStandardItem>
34#include <QStandardItemModel>
35
36enum {
37 EntryPathRole = Qt::UserRole + 1,
38 SortRole,
39};
40
41namespace Homerun
42{
43
44InstalledAppsConfigurationWidget::InstalledAppsConfigurationWidget(const KConfigGroup &group)
45: SourceConfigurationWidget(group)
46, m_ui(new Ui_InstalledAppsConfigurationWidget)
47, m_model(new QStandardItemModel(this))
48{
49 // Init model
50 QStandardItem *defaultItem = fillModel(group.readEntry("entryPath"));
51 m_model->setSortRole(SortRole);
52 m_model->sort(0);
53
54 m_ui->setupUi(this);
55 m_ui->treeView->setModel(m_model);
56
57 // Select currently configured item
58 Q_ASSERT(defaultItem);
59 QModelIndex index = defaultItem->index();
60 m_ui->treeView->selectionModel()->select(index, QItemSelectionModel::Select);
61
62 // Expand up to the configured item
63 index = index.parent();
64 for (; index.isValid(); index = index.parent()) {
65 m_ui->treeView->setExpanded(index, true);
66 }
67
68 // Always expand top level
69 m_ui->treeView->setExpanded(m_model->index(0, 0), true);
70}
71
72InstalledAppsConfigurationWidget::~InstalledAppsConfigurationWidget()
73{
74 delete m_ui;
75}
76
77void InstalledAppsConfigurationWidget::save()
78{
79 QModelIndex index = m_ui->treeView->selectionModel()->currentIndex();
80 if (!index.isValid()) {
81 kWarning() << "No item selected!";
82 return;
83 }
84 QString entryPath = index.data(EntryPathRole).toString();
85 configGroup().writeEntry("entryPath", entryPath);
86}
87
88
89// Helper struct for fillModel
90struct ItemCreator
91{
92 ItemCreator()
93 : m_item(0)
94 {}
95 QString m_entryPath;
96 QStandardItem *m_item;
97
98 void createItemChildren(QStandardItem *parent, KServiceGroup::Ptr parentGroup)
99 {
100 KServiceGroup::List list = parentGroup->entries(false /* sorted: set to false as it does not seem to work */);
101
102 Q_FOREACH(const KSycocaEntry::Ptr entry, list) {
103 if (!entry->isType(KST_KServiceGroup)) {
104 continue;
105 }
106 KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast(entry);
107
108 if (group->noDisplay() || group->childCount() == 0) {
109 continue;
110 }
111 QString entryPath = group->entryPath();
112
113 QStandardItem *item = new QStandardItem;
114 item->setText(group->caption());
115 item->setIcon(KIcon(group->icon()));
116 item->setData(entryPath, EntryPathRole);
117 item->setData(group->caption().toLower(), SortRole);
118
119 parent->appendRow(item);
120 createItemChildren(item, group);
121
122 if (m_entryPath == entryPath) {
123 m_item = item;
124 }
125 }
126 }
127};
128
129QStandardItem *InstalledAppsConfigurationWidget::fillModel(const QString &entryPath)
130{
131 KServiceGroup::Ptr group = KServiceGroup::root();
132 QStandardItem *rootItem = new QStandardItem;
133 rootItem->setText(i18n("All Applications"));
134 rootItem->setData(QString(), EntryPathRole);
135 m_model->appendRow(rootItem);
136
137 ItemCreator creator;
138 creator.m_entryPath = entryPath;
139 creator.createItemChildren(rootItem, group);
140 return creator.m_item ? creator.m_item : rootItem;
141}
142
143} // namespace Homerun
144
145#include <installedappsconfigurationwidget.moc>
1460
=== removed file 'components/installedappsconfigurationwidget.h'
--- components/installedappsconfigurationwidget.h 2012-11-14 21:30:06 +0000
+++ components/installedappsconfigurationwidget.h 1970-01-01 00:00:00 +0000
@@ -1,63 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef INSTALLEDAPPSCONFIGURATIONWIDGET_H
21#define INSTALLEDAPPSCONFIGURATIONWIDGET_H
22
23// Local
24#include <sourceconfigurationwidget.h>
25
26// Qt
27
28// KDE
29#include <KServiceGroup>
30
31class QStandardItem;
32class QStandardItemModel;
33
34class Ui_InstalledAppsConfigurationWidget;
35
36namespace Homerun
37{
38
39/**
40 * Configuration widget for the InstalledApps source
41 */
42class InstalledAppsConfigurationWidget : public SourceConfigurationWidget
43{
44 Q_OBJECT
45public:
46 explicit InstalledAppsConfigurationWidget(const KConfigGroup &group);
47 ~InstalledAppsConfigurationWidget();
48
49 void save(); // reimp
50
51private:
52 Ui_InstalledAppsConfigurationWidget *m_ui;
53 QStandardItemModel *m_model;
54
55 /**
56 * Fill m_model, returns the item which corresponds to defaultEntryPath
57 */
58 QStandardItem *fillModel(const QString &defaultEntryPath);
59};
60
61} // namespace Homerun
62
63#endif /* INSTALLEDAPPSCONFIGURATIONWIDGET_H */
640
=== removed file 'components/installedappsconfigurationwidget.ui'
--- components/installedappsconfigurationwidget.ui 2012-11-14 21:30:06 +0000
+++ components/installedappsconfigurationwidget.ui 1970-01-01 00:00:00 +0000
@@ -1,50 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>InstalledAppsConfigurationWidget</class>
4 <widget class="QWidget" name="InstalledAppsConfigurationWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>408</width>
10 <height>327</height>
11 </rect>
12 </property>
13 <layout class="QVBoxLayout" name="verticalLayout">
14 <item>
15 <widget class="QLabel" name="label">
16 <property name="text">
17 <string>Pick the application folder to display:</string>
18 </property>
19 <property name="buddy">
20 <cstring>treeView</cstring>
21 </property>
22 </widget>
23 </item>
24 <item>
25 <widget class="QTreeView" name="treeView">
26 <property name="minimumSize">
27 <size>
28 <width>400</width>
29 <height>300</height>
30 </size>
31 </property>
32 <property name="editTriggers">
33 <set>QAbstractItemView::NoEditTriggers</set>
34 </property>
35 <property name="showDropIndicator" stdset="0">
36 <bool>false</bool>
37 </property>
38 <property name="rootIsDecorated">
39 <bool>false</bool>
40 </property>
41 <property name="headerHidden">
42 <bool>true</bool>
43 </property>
44 </widget>
45 </item>
46 </layout>
47 </widget>
48 <resources/>
49 <connections/>
50</ui>
510
=== removed file 'components/installedappsmodel.cpp'
--- components/installedappsmodel.cpp 2012-11-14 21:30:06 +0000
+++ components/installedappsmodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,319 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Local
21#include <pathmodel.h>
22#include <installedappsmodel.h>
23#include <installedappsconfigurationwidget.h>
24#include <sourceregistry.h>
25
26// Qt
27#include <QIcon>
28#include <QAction>
29#include <QTimer>
30
31// KDE
32#include <KDebug>
33#include <KLocale>
34#include <kmacroexpander.h>
35#include <KRun>
36#include <KService>
37#include <KServiceTypeTrader>
38#include <KSycocaEntry>
39
40#include <Plasma/RunnerManager>
41
42namespace Homerun {
43
44static const char *SOURCE_ID = "InstalledApps";
45
46//- AbstractNode ---------------------------------------------------------------
47AbstractNode::~AbstractNode()
48{
49}
50
51bool AbstractNode::lessThan(AbstractNode *n1, AbstractNode *n2)
52{
53 Q_ASSERT(n1);
54 Q_ASSERT(n2);
55 return n1->m_sortKey < n2->m_sortKey;
56}
57
58//- GroupNode ------------------------------------------------------------------
59GroupNode::GroupNode(KServiceGroup::Ptr group, InstalledAppsModel *model)
60: m_model(model)
61{
62 m_icon = group->icon();
63 m_name = group->caption();
64 m_entryPath = group->entryPath();
65 m_sortKey = m_name.toLower();
66}
67
68bool GroupNode::trigger()
69{
70 QVariantMap args;
71 args.insert("entryPath", m_entryPath);
72 m_model->openSourceRequested(SOURCE_ID, args);
73 return false;
74}
75
76//- AppNode --------------------------------------------------------------------
77AppNode::AppNode(KService::Ptr service)
78: m_service(service)
79{
80 m_icon = service->icon();
81 m_name = service->name();
82 m_service = service;
83 m_sortKey = m_name.toLower();
84}
85
86bool AppNode::trigger()
87{
88 return KRun::run(*m_service, KUrl::List(), 0);
89}
90
91QString AppNode::favoriteId() const
92{
93 return QString("app:") + m_service->storageId();
94}
95
96//- InstallerNode --------------------------------------------------------------
97InstallerNode::InstallerNode(KServiceGroup::Ptr group, KService::Ptr installerService)
98: m_group(group)
99, m_service(installerService)
100{
101 m_icon = m_service->icon();
102 m_name = m_service->name();
103}
104
105bool InstallerNode::trigger()
106{
107 QHash<QString, QString> map;
108 QString category = m_group->entryPath();
109 if (category.endsWith('/')) {
110 category.truncate(category.length() - 1);
111 }
112 map.insert("category", category);
113
114 QString command = KMacroExpander::expandMacros(m_service->exec(), map, '@');
115 return KRun::run(command, KUrl::List(), 0, m_service->name(), m_service->icon());
116}
117
118//- InstalledAppsModel ------------------------------------------------------------
119InstalledAppsModel::InstalledAppsModel(const QString &entryPath, const QString &installer, QObject *parent)
120: QAbstractListModel(parent)
121, m_pathModel(new PathModel(this))
122, m_installer(installer)
123{
124 QHash<int, QByteArray> roles;
125 roles.insert(Qt::DisplayRole, "display");
126 roles.insert(Qt::DecorationRole, "decoration");
127 roles.insert(FavoriteIdRole, "favoriteId");
128
129 setRoleNames(roles);
130
131 load(entryPath);
132}
133
134InstalledAppsModel::~InstalledAppsModel()
135{
136 qDeleteAll(m_nodeList);
137}
138
139int InstalledAppsModel::rowCount(const QModelIndex& index) const
140{
141 return index.isValid() ? 0 : m_nodeList.count();
142}
143
144int InstalledAppsModel::count() const
145{
146 return m_nodeList.count();
147}
148
149QVariant InstalledAppsModel::data(const QModelIndex &index, int role) const
150{
151 if (!index.isValid() || index.row() >= m_nodeList.count()) {
152 return QVariant();
153 }
154
155 const AbstractNode *node = m_nodeList.at(index.row());
156 if (role == Qt::DisplayRole) {
157 return node->name();
158 } else if (role == Qt::DecorationRole) {
159 // at least show the oxygen question-mark, otherwise it looks weird blank.
160 return node->icon().isEmpty() ? QLatin1String("unknown") : node->icon();
161 } else if (role == FavoriteIdRole) {
162 return node->favoriteId();
163 }
164
165 return QVariant();
166}
167
168bool InstalledAppsModel::trigger(int row)
169{
170 return m_nodeList.at(row)->trigger();
171}
172
173void InstalledAppsModel::load(const QString &entryPath)
174{
175 m_pathModel->clear();
176 beginResetModel();
177 qDeleteAll(m_nodeList);
178 m_nodeList.clear();
179
180 if (entryPath.isEmpty()) {
181 loadRootEntries();
182 } else {
183 KServiceGroup::Ptr group = KServiceGroup::group(entryPath);
184 loadServiceGroup(group);
185 QVariantMap args;
186 args.insert("entryPath", entryPath);
187 m_pathModel->addPath(group->caption(), SOURCE_ID, args);
188 }
189
190 endResetModel();
191
192 emit countChanged();
193}
194
195void InstalledAppsModel::loadRootEntries()
196{
197 KServiceGroup::Ptr group = KServiceGroup::root();
198 KServiceGroup::List list = group->entries(false /* sorted: set to false as it does not seem to work */);
199
200 for( KServiceGroup::List::ConstIterator it = list.constBegin(); it != list.constEnd(); it++) {
201 const KSycocaEntry::Ptr p = (*it);
202
203 if (p->isType(KST_KServiceGroup)) {
204 KServiceGroup::Ptr subGroup = KServiceGroup::Ptr::staticCast(p);
205
206 if (!subGroup->noDisplay() && subGroup->childCount() > 0) {
207 m_nodeList << new GroupNode(subGroup, this);
208 }
209 }
210 }
211 qSort(m_nodeList.begin(), m_nodeList.end(), AbstractNode::lessThan);
212}
213
214void InstalledAppsModel::loadServiceGroup(KServiceGroup::Ptr group)
215{
216 doLoadServiceGroup(group);
217
218 qSort(m_nodeList.begin(), m_nodeList.end(), AbstractNode::lessThan);
219
220 if (!m_installer.isEmpty()) {
221 KService::Ptr service = KService::serviceByDesktopName(m_installer);
222 if (service) {
223 m_nodeList << new InstallerNode(group, service);
224 } else {
225 kWarning() << "Could not find service for" << m_installer;
226 }
227 }
228}
229
230void InstalledAppsModel::doLoadServiceGroup(KServiceGroup::Ptr group)
231{
232 /* This method is separate from loadServiceGroup so that
233 * - only one installer node is added at the end
234 * - sorting is done only once
235 */
236 if (!group || !group->isValid()) {
237 return;
238 }
239
240 KServiceGroup::List list = group->entries(false /* see above */);
241
242 for( KServiceGroup::List::ConstIterator it = list.constBegin();
243 it != list.constEnd(); it++) {
244 const KSycocaEntry::Ptr p = (*it);
245
246 if (p->isType(KST_KService)) {
247 const KService::Ptr service = KService::Ptr::staticCast(p);
248
249 if (!service->noDisplay()) {
250 QString genericName = service->genericName();
251 if (genericName.isNull()) {
252 genericName = service->comment();
253 }
254 m_nodeList << new AppNode(service);
255 }
256
257 } else if (p->isType(KST_KServiceGroup)) {
258 const KServiceGroup::Ptr subGroup = KServiceGroup::Ptr::staticCast(p);
259
260 if (!subGroup->noDisplay() && subGroup->childCount() > 0) {
261 doLoadServiceGroup(subGroup);
262 }
263 }
264 }
265}
266
267PathModel *InstalledAppsModel::pathModel() const
268{
269 return m_pathModel;
270}
271
272QString InstalledAppsModel::name() const
273{
274 if (m_pathModel->count() > 0) {
275 QModelIndex index = m_pathModel->index(m_pathModel->count() - 1, 0);
276 return index.data().toString();
277 } else {
278 return i18n("Applications");
279 }
280}
281
282//- InstalledAppsSource ---------------------------------------------
283InstalledAppsSource::InstalledAppsSource(QObject *parent)
284: AbstractSource(parent)
285{}
286
287QAbstractItemModel *InstalledAppsSource::createModelFromConfigGroup(const KConfigGroup &group)
288{
289 QString entryPath = group.readEntry("entryPath");
290 return createModel(entryPath);
291}
292
293QAbstractItemModel *InstalledAppsSource::createModelFromArguments(const QVariantMap &arguments)
294{
295 QString entryPath = arguments.value("entryPath").toString();
296 return createModel(entryPath);
297}
298
299QAbstractItemModel *InstalledAppsSource::createModel(const QString &entryPath)
300{
301 KConfigGroup group(config(), "PackageManagement");
302 QString installer = group.readEntry("categoryInstaller");
303
304 return new InstalledAppsModel(entryPath, installer);
305}
306
307bool InstalledAppsSource::isConfigurable() const
308{
309 return true;
310}
311
312SourceConfigurationWidget *InstalledAppsSource::createConfigurationWidget(const KConfigGroup &group)
313{
314 return new InstalledAppsConfigurationWidget(group);
315}
316
317} // namespace Homerun
318
319#include "installedappsmodel.moc"
3200
=== removed file 'components/installedappsmodel.h'
--- components/installedappsmodel.h 2012-11-14 21:30:06 +0000
+++ components/installedappsmodel.h 1970-01-01 00:00:00 +0000
@@ -1,159 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef INSTALLEDAPPSMODEL_H
21#define INSTALLEDAPPSMODEL_H
22
23// Local
24#include <abstractsource.h>
25
26// Qt
27#include <QAbstractListModel>
28#include <QStringList>
29
30// KDE
31#include <KIcon>
32#include <KService>
33#include <KServiceGroup>
34#include <KUrl>
35
36namespace Homerun {
37
38class PathModel;
39
40class InstalledAppsModel;
41class InstalledAppsSource;
42
43class AbstractNode
44{
45public:
46 virtual ~AbstractNode();
47
48 virtual bool trigger() = 0;
49 virtual QString favoriteId() const { return QString(); }
50
51 QString icon() const { return m_icon; }
52 QString name() const { return m_name; }
53
54 static bool lessThan(AbstractNode *n1, AbstractNode *n2);
55
56protected:
57 QString m_sortKey;
58 QString m_icon;
59 QString m_name;
60};
61
62class GroupNode : public AbstractNode
63{
64public:
65 GroupNode(KServiceGroup::Ptr group, InstalledAppsModel *model);
66
67 bool trigger(); // reimp
68
69private:
70 InstalledAppsModel *m_model;
71 QString m_entryPath;
72};
73
74class AppNode : public AbstractNode
75{
76public:
77 AppNode(KService::Ptr service);
78
79 bool trigger(); // reimp;
80 QString favoriteId() const; // reimp
81
82private:
83 KService::Ptr m_service;
84};
85
86class InstallerNode : public AbstractNode
87{
88public:
89 InstallerNode(KServiceGroup::Ptr group, KService::Ptr installerService);
90
91 bool trigger(); // reimp
92
93private:
94 InstalledAppsModel *m_model;
95 KServiceGroup::Ptr m_group;
96 KService::Ptr m_service;
97};
98
99class InstalledAppsModel : public QAbstractListModel
100{
101 Q_OBJECT
102 Q_PROPERTY(int count READ count NOTIFY countChanged)
103 Q_PROPERTY(QObject* pathModel READ pathModel CONSTANT)
104 Q_PROPERTY(QString name READ name CONSTANT)
105
106public:
107 enum Roles {
108 FavoriteIdRole = Qt::UserRole + 1,
109 };
110
111 InstalledAppsModel(const QString &entryPath, const QString &installer, QObject *parent = 0);
112 ~InstalledAppsModel();
113
114 int rowCount(const QModelIndex&) const;
115 int count() const;
116 QVariant data(const QModelIndex&, int) const;
117
118 PathModel *pathModel() const;
119
120 Q_INVOKABLE bool trigger(int row);
121
122 QString name() const;
123
124Q_SIGNALS:
125 void countChanged();
126 void openSourceRequested(const QString &sourceId, const QVariantMap &args);
127
128private:
129 void loadRootEntries();
130 void loadServiceGroup(KServiceGroup::Ptr group);
131 void doLoadServiceGroup(KServiceGroup::Ptr group);
132
133 PathModel *m_pathModel;
134 QList<AbstractNode *> m_nodeList;
135 QString m_installer;
136 QString m_arguments;
137
138 void load(const QString &entryPath);
139
140 friend class GroupNode;
141};
142
143class InstalledAppsSource : public AbstractSource
144{
145public:
146 InstalledAppsSource(QObject *parent);
147 QAbstractItemModel *createModelFromConfigGroup(const KConfigGroup &group); // reimp
148 QAbstractItemModel *createModelFromArguments(const QVariantMap &arguments); // reimp
149
150 bool isConfigurable() const; // reimp
151 SourceConfigurationWidget *createConfigurationWidget(const KConfigGroup &group); // reimp
152
153private:
154 QAbstractItemModel *createModel(const QString &entryPath);
155};
156
157} // namespace Homerun
158
159#endif
1600
=== added file 'components/messagebox.cpp'
--- components/messagebox.cpp 1970-01-01 00:00:00 +0000
+++ components/messagebox.cpp 2013-03-01 15:15:27 +0000
@@ -0,0 +1,45 @@
1/*
2Copyright 2013 Aurélien Gâteau <agateau@kde.org>
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License as
6published by the Free Software Foundation; either version 2 of
7the License or (at your option) version 3 or any later version
8accepted by the membership of KDE e.V. (or its successor approved
9by the membership of KDE e.V.), which shall act as a proxy
10defined in Section 14 of version 3 of the license.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Self
21#include <messagebox.h>
22
23// Local
24
25// KDE
26
27// Qt
28#include <QApplication>
29
30MessageBox::MessageBox(QObject *parent)
31: QObject(parent)
32{
33}
34
35int MessageBox::warningContinueCancel(const QString& text, const QString& caption, const QString& continueText, const QString& cancelText)
36{
37 KGuiItem cont = continueText.isEmpty() ? KStandardGuiItem::cont() : KGuiItem(continueText);
38 KGuiItem cancel = cancelText.isEmpty() ? KStandardGuiItem::cancel() : KGuiItem(cancelText);
39 int ret = KMessageBox::warningContinueCancel(QApplication::activeWindow(),
40 text, caption, cont, cancel);
41
42 return ret;
43}
44
45#include <messagebox.moc>
046
=== added file 'components/messagebox.h'
--- components/messagebox.h 1970-01-01 00:00:00 +0000
+++ components/messagebox.h 2013-03-01 15:15:27 +0000
@@ -0,0 +1,60 @@
1/*
2Copyright 2013 Aurélien Gâteau <agateau@kde.org>
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License as
6published by the Free Software Foundation; either version 2 of
7the License or (at your option) version 3 or any later version
8accepted by the membership of KDE e.V. (or its successor approved
9by the membership of KDE e.V.), which shall act as a proxy
10defined in Section 14 of version 3 of the license.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef MESSAGEBOX_H
21#define MESSAGEBOX_H
22
23// Local
24
25// Qt
26#include <QObject>
27
28// KDE
29#include <KMessageBox>
30
31/**
32 * Wrapper around KMessageBox
33 */
34class MessageBox : public QObject
35{
36 Q_OBJECT
37 Q_ENUMS(ButtonCode)
38public:
39 explicit MessageBox(QObject *parent = 0);
40
41 enum ButtonCode {
42 Ok = KMessageBox::Ok,
43 Cancel = KMessageBox::Cancel,
44 Yes = KMessageBox::Yes,
45 No = KMessageBox::No,
46 Continue = KMessageBox::Continue,
47 };
48
49 /**
50 * Return value is a MessageBox::ButtonCode
51 */
52 Q_INVOKABLE int warningContinueCancel(
53 const QString &text,
54 const QString &caption = QString(),
55 const QString &continueText = QString(),
56 const QString &cancelText = QString()
57 );
58};
59
60#endif /* MESSAGEBOX_H */
061
=== removed file 'components/powermodel.cpp'
--- components/powermodel.cpp 2012-12-18 19:55:12 +0000
+++ components/powermodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,143 +0,0 @@
1/*
2 Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3 Copyright (C) 2012 Shaun Reich <shaun.reich@blue-systems.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21// Own
22#include "powermodel.h"
23
24//Qt
25#include <QDBusMessage>
26#include <QDBusConnection>
27#include <QDBusPendingCall>
28
29// KDE
30#include <KDebug>
31#include <KIcon>
32#include <KLocale>
33#include <KRun>
34#include <KService>
35#include <kworkspace/kworkspace.h>
36
37//Plasma
38#include <Plasma/AbstractRunner>
39#include <Plasma/RunnerManager>
40
41namespace Homerun {
42
43PowerModel::PowerModel(QObject *parent)
44: QAbstractListModel(parent)
45{
46 PowerAction suspend;
47 suspend.name = i18nc("an action", "Suspend");
48 suspend.type = Suspend;
49 suspend.iconName = "system-suspend";
50 m_powerList.append(suspend);
51
52 PowerAction hibernate;
53 hibernate.name = i18nc("an action", "Hibernate");
54 hibernate.type = Hibernate;
55 hibernate.iconName = "system-suspend-hibernate";
56 m_powerList.append(hibernate);
57
58 PowerAction restart;
59 restart.name = i18nc("an action", "Restart");
60 restart.type = Restart;
61 restart.iconName = "system-reboot";
62 m_powerList.append(restart);
63
64 PowerAction shutdown;
65 shutdown.name = i18nc("an action", "Shutdown");
66 shutdown.type = Shutdown;
67 shutdown.iconName = "system-shutdown";
68 m_powerList.append(shutdown);
69}
70
71PowerModel::~PowerModel()
72{
73}
74
75int PowerModel::count() const
76{
77 return m_powerList.count();
78}
79
80QString PowerModel::name() const
81{
82 return i18n("Power");
83}
84
85int PowerModel::rowCount(const QModelIndex &index) const
86{
87 if (index.isValid()) {
88 return 0;
89 }
90 return m_powerList.count();
91}
92
93QVariant PowerModel::data(const QModelIndex &index, int role) const
94{
95 PowerAction action = m_powerList.value(index.row());
96
97 if (role == Qt::DisplayRole) {
98 return action.name;
99 } else if (role == Qt::DecorationRole) {
100 return KIcon(action.iconName);
101 } else {
102 kWarning() << "Unhandled role" << role;
103 return QVariant();
104 }
105}
106
107bool PowerModel::trigger(int row)
108{
109 PowerAction action = m_powerList.value(row);
110
111 switch (action.type) {
112 case Shutdown:
113 KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeHalt);
114 break;
115
116 case Restart:
117 KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeReboot);
118 break;
119
120 case Suspend:
121 suspend("suspendToRam");
122 break;
123
124 case Hibernate:
125 suspend("suspendToDisk");
126 break;
127 }
128
129 return true;
130}
131
132void PowerModel::suspend(const QString& type)
133{
134 QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement",
135 "/org/kde/Solid/PowerManagement",
136 "org.kde.Solid.PowerManagement",
137 type);
138 QDBusConnection::sessionBus().asyncCall(msg);
139}
140
141} // namespace Homerun
142
143#include "powermodel.moc"
1440
=== removed file 'components/powermodel.h'
--- components/powermodel.h 2012-11-14 21:30:06 +0000
+++ components/powermodel.h 1970-01-01 00:00:00 +0000
@@ -1,75 +0,0 @@
1/*
2 Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3 Copyright 2012 (C) Shaun Reich <shaun.reich@blue-systems.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef POWERMODEL_H
22#define POWERMODEL_H
23
24#include <QAbstractListModel>
25
26#include <KService>
27
28class QString;
29
30namespace Homerun {
31
32enum PowerType {
33 Shutdown,
34 Restart,
35 Hibernate,
36 Suspend
37};
38
39struct PowerAction
40{
41 QString name;
42 QString iconName;
43 PowerType type;
44};
45
46class PowerModel : public QAbstractListModel
47{
48 Q_OBJECT
49 Q_PROPERTY(QString name READ name CONSTANT)
50 Q_PROPERTY(int count READ count NOTIFY countChanged)
51
52public:
53 PowerModel(QObject *parent = 0);
54 ~PowerModel();
55
56 int count() const;
57 QString name() const;
58
59 int rowCount(const QModelIndex & = QModelIndex()) const;
60 QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const;
61
62 Q_INVOKABLE bool trigger(int row);
63
64 void suspend(const QString& type);
65
66Q_SIGNALS:
67 void countChanged();
68
69private:
70 QList<PowerAction> m_powerList;
71};
72
73} // namespace Homerun
74
75#endif
760
=== added file 'components/qml/Label.qml'
--- components/qml/Label.qml 1970-01-01 00:00:00 +0000
+++ components/qml/Label.qml 2013-03-01 15:15:27 +0000
@@ -0,0 +1,68 @@
1/*
2Copyright 2013 Aurélien Gâteau <agateau@kde.org>
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License as
6published by the Free Software Foundation; either version 2 of
7the License or (at your option) version 3 or any later version
8accepted by the membership of KDE e.V. (or its successor approved
9by the membership of KDE e.V.), which shall act as a proxy
10defined in Section 14 of version 3 of the license.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20import QtQuick 1.1
21import org.kde.homerun.components 0.1 as HomerunComponents
22import org.kde.plasma.components 0.1 as PlasmaComponents
23
24/**
25 * A label which uses Plasma colors by default, but appears differently when
26 * run as a containment: it shows a shadow behind itself and both shadow and
27 * text colors can be customized.
28 */
29PlasmaComponents.Label {
30 id: main
31
32 Component {
33 id: shadowComponent
34 HomerunComponents.ShadowEffect {
35 xOffset: 0
36 yOffset: 1
37 blurRadius: 2
38 }
39 }
40
41 Component.onCompleted: {
42 var isContainment = "plasmoid" in this;
43 if (isContainment) {
44 readConfig();
45 plasmoid.addEventListener("ConfigChanged", readConfig);
46 } else {
47 main.color = theme.textColor;
48 }
49 }
50
51 function readConfig() {
52 main.color = plasmoid.readConfig("textColor");
53 if (plasmoid.readConfig("shadowModeNone") == true) {
54 if (main.effect) {
55 main.effect.destroy();
56 }
57 return;
58 }
59 if (!main.effect) {
60 main.effect = shadowComponent.createObject(main);
61 }
62 if (plasmoid.readConfig("shadowModeCustom") == true) {
63 main.effect.color = plasmoid.readConfig("shadowColor");
64 } else {
65 main.effect.resetColor();
66 }
67 }
68}
069
=== modified file 'components/qml/TabButton.qml'
--- components/qml/TabButton.qml 2012-11-14 21:30:06 +0000
+++ components/qml/TabButton.qml 2013-03-01 15:15:27 +0000
@@ -81,7 +81,7 @@
81**/81**/
8282
83import QtQuick 1.183import QtQuick 1.1
84import org.kde.plasma.components 0.184import org.kde.plasma.components 0.1 as PlasmaComponents
85import "private" as Private85import "private" as Private
8686
87Item {87Item {
@@ -127,6 +127,15 @@
127 }127 }
128 }128 }
129129
130 /*
131 HACK: We use a HomerunComponents.Label for the normal text and
132 a PlasmaComponents.Label for the current text.
133
134 This is necessary for containment mode:
135 It makes it possible to have custom color + shadow for normal text (to
136 ensure it remains readable) and buttonTextColor + no-shadow for button text
137 (because it is drawn on top of a button frame)
138 */
130 Label {139 Label {
131 id: label140 id: label
132141
@@ -144,7 +153,24 @@
144 horizontalAlignment: Text.AlignLeft153 horizontalAlignment: Text.AlignLeft
145 verticalAlignment: Text.AlignVCenter154 verticalAlignment: Text.AlignVCenter
146155
147 color: root.ListView.isCurrentItem ? theme.buttonTextColor : theme.textColor156 color: theme.textColor
157 opacity: root.ListView.isCurrentItem ? 0 : 1
158 Behavior on opacity { NumberAnimation { duration: 250 }}
159 }
160
161 PlasmaComponents.Label {
162 id: currentLabel
163 text: label.text
164
165 anchors.fill: label
166
167 elide: label.elide
168 horizontalAlignment: label.horizontalAlignment
169 verticalAlignment: label.verticalAlignment
170
171 color: theme.buttonTextColor
172 opacity: root.ListView.isCurrentItem ? 1 : 0
173 Behavior on opacity { NumberAnimation { duration: 250 }}
148 }174 }
149175
150 MouseArea {176 MouseArea {
151177
=== modified file 'components/qml/qmldir'
--- components/qml/qmldir 2012-11-14 21:30:06 +0000
+++ components/qml/qmldir 2013-03-01 15:15:27 +0000
@@ -3,3 +3,4 @@
3TabBar 0.1 TabBar.qml3TabBar 0.1 TabBar.qml
4TabButton 0.1 TabButton.qml4TabButton 0.1 TabButton.qml
5TabGroup 0.1 TabGroup.qml5TabGroup 0.1 TabGroup.qml
6Label 0.1 Label.qml
67
=== removed file 'components/runnerconfigurationwidget.cpp'
--- components/runnerconfigurationwidget.cpp 2012-11-14 21:30:06 +0000
+++ components/runnerconfigurationwidget.cpp 1970-01-01 00:00:00 +0000
@@ -1,105 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Self
21#include <runnerconfigurationwidget.h>
22
23// Local
24
25// KDE
26#include <KDebug>
27#include <KPluginInfo>
28#include <Plasma/RunnerManager>
29
30// Qt
31#include <QListWidgetItem>
32
33Q_DECLARE_METATYPE(KPluginInfo)
34
35static const char *WHITELIST_KEY = "whitelist";
36
37namespace Homerun
38{
39
40static QListWidgetItem *createWidgetItem(const KPluginInfo &info)
41{
42 QListWidgetItem *item = new QListWidgetItem(info.name());
43 item->setIcon(KIcon(info.icon()));
44 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
45 item->setData(Qt::UserRole, QVariant::fromValue(info));
46 return item;
47}
48
49RunnerConfigurationWidget::RunnerConfigurationWidget(const KConfigGroup &group)
50: SourceConfigurationWidget(group)
51{
52 setupUi(this);
53 m_searchLine->setListWidget(m_listWidget);
54
55 // A runner is enabled if there is either a whitelist and it is part of it
56 // or if there is no whitelist and its EnabledByDefault key is true
57
58 QStringList whiteList = group.readEntry(WHITELIST_KEY, QStringList());
59 bool hasWhiteList = !whiteList.isEmpty();
60
61 KPluginInfo::List list = Plasma::RunnerManager::listRunnerInfo();
62 Q_FOREACH(const KPluginInfo &info, list) {
63 QListWidgetItem *item = createWidgetItem(info);
64 bool selected;
65 if (hasWhiteList) {
66 selected = whiteList.contains(info.pluginName());
67 } else {
68 selected = info.isPluginEnabledByDefault();
69 }
70 item->setCheckState(selected ? Qt::Checked : Qt::Unchecked);
71 m_listWidget->addItem(item);
72 }
73 m_listWidget->sortItems();
74}
75
76void RunnerConfigurationWidget::save()
77{
78 QStringList whiteList;
79 bool hasChanges = false;
80
81 // Only write a whiteList if the selected runner list is not the same as
82 // the list of all EnabledByDefault runners
83
84 for (int idx = 0; idx < m_listWidget->count(); ++idx) {
85 QListWidgetItem *item = m_listWidget->item(idx);
86 KPluginInfo info = item->data(Qt::UserRole).value<KPluginInfo>();
87
88 bool selected = item->checkState() == Qt::Checked;
89 if (selected != info.isPluginEnabledByDefault()) {
90 hasChanges = true;
91 }
92 if (selected) {
93 whiteList << info.pluginName();
94 }
95 }
96 if (hasChanges) {
97 configGroup().writeEntry(WHITELIST_KEY, whiteList);
98 } else {
99 configGroup().deleteEntry(WHITELIST_KEY);
100 }
101}
102
103} // namespace Homerun
104
105#include <runnerconfigurationwidget.moc>
1060
=== removed file 'components/runnerconfigurationwidget.h'
--- components/runnerconfigurationwidget.h 2012-11-14 21:30:06 +0000
+++ components/runnerconfigurationwidget.h 1970-01-01 00:00:00 +0000
@@ -1,48 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef RUNNERCONFIGURATIONWIDGET_H
21#define RUNNERCONFIGURATIONWIDGET_H
22
23// Local
24#include <sourceconfigurationwidget.h>
25#include <ui_runnerconfigurationwidget.h>
26
27// Qt
28
29// KDE
30
31namespace Homerun
32{
33
34/**
35 * A configuration widget for the Runner source
36 */
37class RunnerConfigurationWidget : public SourceConfigurationWidget, private Ui_RunnerConfigurationWidget
38{
39 Q_OBJECT
40public:
41 explicit RunnerConfigurationWidget(const KConfigGroup &);
42
43 void save(); // reimp
44};
45
46} // namespace
47
48#endif /* RUNNERCONFIGURATIONWIDGET_H */
490
=== removed file 'components/runnerconfigurationwidget.ui'
--- components/runnerconfigurationwidget.ui 2012-11-14 21:30:06 +0000
+++ components/runnerconfigurationwidget.ui 1970-01-01 00:00:00 +0000
@@ -1,48 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>RunnerConfigurationWidget</class>
4 <widget class="QWidget" name="RunnerConfigurationWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>400</width>
10 <height>300</height>
11 </rect>
12 </property>
13 <layout class="QVBoxLayout" name="verticalLayout">
14 <item>
15 <widget class="QLabel" name="label">
16 <property name="text">
17 <string>Pick the runners you would like to use in this source:</string>
18 </property>
19 </widget>
20 </item>
21 <item>
22 <widget class="KListWidgetSearchLine" name="m_searchLine"/>
23 </item>
24 <item>
25 <widget class="KListWidget" name="m_listWidget"/>
26 </item>
27 </layout>
28 </widget>
29 <customwidgets>
30 <customwidget>
31 <class>KListWidgetSearchLine</class>
32 <extends>KLineEdit</extends>
33 <header>klistwidgetsearchline.h</header>
34 </customwidget>
35 <customwidget>
36 <class>KLineEdit</class>
37 <extends>QLineEdit</extends>
38 <header>klineedit.h</header>
39 </customwidget>
40 <customwidget>
41 <class>KListWidget</class>
42 <extends>QListWidget</extends>
43 <header>klistwidget.h</header>
44 </customwidget>
45 </customwidgets>
46 <resources/>
47 <connections/>
48</ui>
490
=== removed file 'components/runnermodel.cpp'
--- components/runnermodel.cpp 2012-11-14 21:30:06 +0000
+++ components/runnermodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,408 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4Based on RunnerModel class. RunnerModel class copyright:
5
6Copyright 2011 Aaron Seigo <aseigo@kde.org>
7
8This library is free software; you can redistribute it and/or
9modify it under the terms of the GNU Library General Public
10License as published by the Free Software Foundation; either
11version 2 of the License, or (at your option) any later version.
12
13This library is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16Library General Public License for more details.
17
18You should have received a copy of the GNU Library General Public License
19along with this library; see the file COPYING.LIB. If not, write to
20the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21Boston, MA 02110-1301, USA.
22*/
23// Self
24#include <runnermodel.h>
25
26// Local
27#include <runnerconfigurationwidget.h>
28
29// KDE
30#include <KDebug>
31#include <KPluginInfo>
32#include <Plasma/AbstractRunner>
33#include <Plasma/RunnerManager>
34
35// Qt
36#include <QStandardItemModel>
37#include <QTimer>
38
39static const char *WHITELIST_KEY = "whitelist";
40
41namespace Homerun {
42
43RunnerSubModel::RunnerSubModel(const QString &runnerId, const QString &name, QObject *parent)
44: QAbstractListModel(parent)
45, m_runnerId(runnerId)
46, m_name(name)
47{
48 QHash<int, QByteArray> roles;
49 roles.insert(Qt::DisplayRole, "display");
50 roles.insert(Qt::DecorationRole, "decoration");
51 roles.insert(FavoriteIdRole, "favoriteId");
52 /*
53 roles.insert(Type, "type");
54 roles.insert(Relevance, "relevance");
55 roles.insert(Data, "data");
56 roles.insert(Id, "id");
57 roles.insert(SubText, "description");
58 roles.insert(Enabled, "enabled");
59 roles.insert(RunnerId, "runnerid");
60 roles.insert(RunnerName, "runnerName");
61 roles.insert(Actions, "actions");
62 */
63 setRoleNames(roles);
64}
65
66int RunnerSubModel::count() const
67{
68 return m_matches.count();
69}
70
71int RunnerSubModel::rowCount(const QModelIndex& parent) const
72{
73 return parent.isValid() ? 0 : m_matches.count();
74}
75
76QVariant RunnerSubModel::data(const QModelIndex &index, int role) const
77{
78 if (!index.isValid() || index.parent().isValid() ||
79 index.column() > 0 || index.row() < 0 || index.row() >= m_matches.count()) {
80 // index requested must be valid, but we have no child items!
81 //kDebug() << "invalid index requested";
82 return QVariant();
83 }
84
85 const Plasma::QueryMatch &match = m_matches.at(index.row());
86 if (role == Qt::DisplayRole) {
87 return match.text();
88 } else if (role == Qt::DecorationRole) {
89 return match.icon();
90 } else if (role == FavoriteIdRole) {
91 QString runnerId = match.runner()->id();
92 if (runnerId == "services") {
93 return QVariant("app:" + match.data().toString());
94 } else if (runnerId == "locations") {
95 KUrl url(match.data().toString());
96 return QVariant("place:" + url.url());
97 } else {
98 return QString();
99 }
100 } /*else if (role == Type) {
101 return m_matches.at(index.row()).type();
102 } else if (role == Relevance) {
103 return m_matches.at(index.row()).relevance();
104 } else if (role == Data) {
105 return m_matches.at(index.row()).data();
106 } else if (role == Id) {
107 return m_matches.at(index.row()).id();
108 } else if (role == SubText) {
109 return m_matches.at(index.row()).subtext();
110 } else if (role == Enabled) {
111 return m_matches.at(index.row()).isEnabled();
112 } else if (role == RunnerId) {
113 return m_matches.at(index.row()).runner()->id();
114 } else if (role == RunnerName) {
115 return m_matches.at(index.row()).runner()->name();
116 } else if (role == Actions) {
117 QVariantList actions;
118 Plasma::QueryMatch amatch = m_matches.at(index.row());
119 QList<QAction*> theactions = m_manager->actionsForMatch(amatch);
120 foreach(QAction* action, theactions) {
121 actions += qVariantFromValue<QObject*>(action);
122 }
123 return actions;
124 }*/
125
126 return QVariant();
127}
128
129void RunnerSubModel::setMatches(const QList<Plasma::QueryMatch> &matches)
130{
131 bool fullReset = false;
132 int oldCount = m_matches.count();
133 int newCount = matches.count();
134 if (newCount > oldCount) {
135 // We received more matches than we had. If all common matches are the
136 // same, we can just append new matches instead of resetting the whole
137 // model
138 for (int row = 0; row < oldCount; ++row) {
139 if (!(m_matches.at(row) == matches.at(row))) {
140 fullReset = true;
141 break;
142 }
143 }
144 if (!fullReset) {
145 // Not a full reset, inserting rows
146 beginInsertRows(QModelIndex(), oldCount, newCount);
147 m_matches = matches;
148 endInsertRows();
149 emit countChanged();
150 }
151 } else {
152 fullReset = true;
153 }
154
155 if (fullReset) {
156 beginResetModel();
157 m_matches = matches;
158 endResetModel();
159 emit countChanged();
160 }
161}
162
163bool RunnerSubModel::trigger(int row)
164{
165 if (row >= 0 && row < m_matches.count()) {
166 triggerRequested(m_matches.at(row));
167 }
168 return true;
169}
170
171//--------------------------------------------------------------------
172
173RunnerModel::RunnerModel(QObject *parent)
174: QAbstractListModel(parent)
175, m_manager(0)
176, m_startQueryTimer(new QTimer(this))
177, m_runningChangedTimeout(new QTimer(this))
178, m_running(false)
179{
180 m_startQueryTimer->setSingleShot(true);
181 m_startQueryTimer->setInterval(10);
182 connect(m_startQueryTimer, SIGNAL(timeout()), this, SLOT(startQuery()));
183
184 //FIXME: HACK: some runners stay in a running but finished state, not possible to say if it's actually over
185 m_runningChangedTimeout->setSingleShot(true);
186 connect(m_runningChangedTimeout, SIGNAL(timeout()), this, SLOT(queryHasFinished()));
187}
188
189RunnerModel::~RunnerModel()
190{
191}
192
193int RunnerModel::rowCount(const QModelIndex &parent) const
194{
195 if (parent.isValid()) {
196 return 0;
197 }
198 return m_models.count();
199}
200
201QVariant RunnerModel::data(const QModelIndex &index, int role) const
202{
203 if (index.parent().isValid()) {
204 return QVariant();
205 }
206
207 RunnerSubModel *model = m_models.value(index.row());
208 if (!model) {
209 return QVariant();
210 }
211
212 if (role == Qt::DisplayRole) {
213 return model->name();
214 } else {
215 return QVariant();
216 }
217}
218
219bool RunnerModel::running() const
220{
221 return m_running;
222}
223
224QObject *RunnerModel::modelForRow(int row) const
225{
226 if (row < 0 || row >= m_models.count()) {
227 kWarning() << "No model for row" << row << "!";
228 return 0;
229 }
230 return m_models.value(row);
231}
232
233void RunnerModel::setAllowedRunners(const QStringList &list)
234{
235 QStringList existingList = m_manager ? m_manager->allowedRunners() : m_pendingRunnersList;
236
237 if (existingList.toSet() == list.toSet()) {
238 return;
239 }
240 m_pendingRunnersList = list;
241 if (m_manager) {
242 loadRunners();
243 }
244}
245
246QString RunnerModel::currentQuery() const
247{
248 return m_manager ? m_manager->query() : QString();
249}
250
251void RunnerModel::scheduleQuery(const QString &query)
252{
253 m_pendingQuery = query;
254 m_startQueryTimer->start();
255}
256
257void RunnerModel::startQuery()
258{
259 if (m_pendingQuery.isEmpty()) {
260 clear();
261 }
262
263 if (!m_manager && m_pendingQuery.isEmpty()) {
264 // avoid creating a manager just so we can run nothing
265 return;
266 }
267
268 createManager();
269 /* DEBUG
270 kWarning() << "Start query" << m_pendingQuery << "on runners:";
271 Q_FOREACH(Plasma::AbstractRunner *runner, m_manager->runners()) {
272 kWarning() << "-" << runner->name();
273 }
274 */
275 m_manager->launchQuery(m_pendingQuery);
276 emit queryChanged();
277 m_running = true;
278 emit runningChanged(true);
279}
280
281void RunnerModel::createManager()
282{
283 if (!m_manager) {
284 m_manager = new Plasma::RunnerManager(this);
285 connect(m_manager, SIGNAL(matchesChanged(QList<Plasma::QueryMatch>)),
286 this, SLOT(matchesChanged(QList<Plasma::QueryMatch>)));
287 connect(m_manager, SIGNAL(queryFinished()),
288 this, SLOT(queryHasFinished()));
289
290 if (!m_pendingRunnersList.isEmpty()) {
291 loadRunners();
292 }
293 //connect(m_manager, SIGNAL(queryFinished()), this, SLOT(queryFinished()));
294 }
295}
296
297void RunnerModel::matchesChanged(const QList<Plasma::QueryMatch> &matches)
298{
299 // Group matches by runner
300 // We do not use a QMultiHash here because it keeps values in LIFO order, while we want FIFO.
301 QHash<QString, QList<Plasma::QueryMatch> > matchesForRunner;
302 Q_FOREACH(const Plasma::QueryMatch &match, matches) {
303 QString runnerId = match.runner()->id();
304 auto it = matchesForRunner.find(runnerId);
305 if (it == matchesForRunner.end()) {
306 it = matchesForRunner.insert(runnerId, QList<Plasma::QueryMatch>());
307 }
308 it.value().append(match);
309 }
310
311 // Assign matches to existing models. If there is no match for a model, delete it.
312 for (int row = m_models.count() - 1; row >= 0; --row) {
313 RunnerSubModel *subModel = m_models.at(row);
314 QList<Plasma::QueryMatch> matches = matchesForRunner.take(subModel->runnerId());
315 if (matches.isEmpty()) {
316 beginRemoveRows(QModelIndex(), row, row);
317 m_models.removeAt(row);
318 delete subModel;
319 endRemoveRows();
320 } else {
321 subModel->setMatches(matches);
322 }
323 }
324
325 // At this point, matchesForRunner contains only matches for runners which
326 // do not have a model yet. Create new models for them.
327 if (!matchesForRunner.isEmpty()) {
328 beginInsertRows(QModelIndex(), rowCount(), rowCount() + matchesForRunner.size() - 1);
329 auto it = matchesForRunner.constBegin();
330 auto end = matchesForRunner.constEnd();
331 for (; it != end; ++it) {
332 QList<Plasma::QueryMatch> matches = it.value();
333 Q_ASSERT(!matches.isEmpty());
334 QString name = matches.first().runner()->name();
335 RunnerSubModel *subModel = new RunnerSubModel(it.key(), name, this);
336 connect(subModel, SIGNAL(triggerRequested(Plasma::QueryMatch)), SLOT(trigger(Plasma::QueryMatch)));
337 subModel->setMatches(matches);
338 m_models.append(subModel);
339 }
340 endInsertRows();
341 }
342
343 m_runningChangedTimeout->start(3000);
344}
345
346void RunnerModel::queryHasFinished()
347{
348 m_running = false;
349 emit runningChanged(false);
350}
351
352void RunnerModel::clear()
353{
354 if (m_models.isEmpty()) {
355 return;
356 }
357 beginResetModel();
358 qDeleteAll(m_models);
359 m_models.clear();
360 endResetModel();
361}
362
363void RunnerModel::trigger(const Plasma::QueryMatch& match)
364{
365 m_manager->run(match);
366}
367
368void RunnerModel::loadRunners()
369{
370 Q_ASSERT(m_manager);
371 if (m_pendingRunnersList.count() > 0) {
372 KPluginInfo::List list = Plasma::RunnerManager::listRunnerInfo();
373 Q_FOREACH(const KPluginInfo &info, list) {
374 if (m_pendingRunnersList.contains(info.pluginName())) {
375 m_manager->loadRunner(info.service());
376 }
377 }
378 }
379 m_manager->setSingleMode(m_pendingRunnersList.count() == 1);
380 m_pendingRunnersList.clear();
381}
382
383//- RunnerSource ------------------------------
384RunnerSource::RunnerSource(QObject *parent)
385: AbstractSource(parent)
386{}
387
388QAbstractItemModel *RunnerSource::createModelFromConfigGroup(const KConfigGroup &group)
389{
390 RunnerModel *model = new RunnerModel;
391 QStringList lst = group.readEntry(WHITELIST_KEY, QStringList());
392 model->setAllowedRunners(lst);
393 return model;
394};
395
396bool RunnerSource::isConfigurable() const
397{
398 return true;
399}
400
401SourceConfigurationWidget *RunnerSource::createConfigurationWidget(const KConfigGroup &group)
402{
403 return new RunnerConfigurationWidget(group);
404}
405
406} // namespace Homerun
407
408#include <runnermodel.moc>
4090
=== removed file 'components/runnermodel.h'
--- components/runnermodel.h 2012-11-14 21:30:06 +0000
+++ components/runnermodel.h 1970-01-01 00:00:00 +0000
@@ -1,150 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4Based on RunnerModel class. RunnerModel class copyright:
5
6Copyright 2011 Aaron Seigo <aseigo@kde.org>
7
8This library is free software; you can redistribute it and/or
9modify it under the terms of the GNU Library General Public
10License as published by the Free Software Foundation; either
11version 2 of the License, or (at your option) any later version.
12
13This library is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16Library General Public License for more details.
17
18You should have received a copy of the GNU Library General Public License
19along with this library; see the file COPYING.LIB. If not, write to
20the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21Boston, MA 02110-1301, USA.
22*/
23#ifndef RUNNERMODEL_H
24#define RUNNERMODEL_H
25
26// Local
27#include <abstractsource.h>
28
29// Qt
30#include <QAbstractListModel>
31#include <QStringList>
32
33// KDE
34#include <KConfig>
35#include <KConfigGroup>
36#include <Plasma/QueryMatch>
37
38class QTimer;
39
40namespace Plasma {
41class RunnerManager;
42}
43
44namespace Homerun {
45
46class RunnerSubModel : public QAbstractListModel
47{
48 Q_OBJECT
49 Q_PROPERTY(QString name READ name CONSTANT)
50 Q_PROPERTY(int count READ count NOTIFY countChanged)
51public:
52 explicit RunnerSubModel(const QString &runnerId, const QString &name, QObject *parent = 0);
53
54 enum {
55 FavoriteIdRole = Qt::UserRole + 1
56 };
57
58 QString runnerId() const { return m_runnerId; }
59 QString name() const { return m_name; }
60
61 void setMatches(const QList<Plasma::QueryMatch> &matches);
62
63 int count() const;
64
65 int rowCount(const QModelIndex &parent = QModelIndex()) const;
66
67 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
68
69 Q_INVOKABLE bool trigger(int row);
70
71Q_SIGNALS:
72 void countChanged();
73
74 void triggerRequested(const Plasma::QueryMatch&);
75
76private:
77 QString m_runnerId;
78 QString m_name;
79
80 QList<Plasma::QueryMatch> m_matches;
81};
82
83/**
84 *
85 */
86class RunnerModel : public QAbstractListModel
87{
88 Q_OBJECT
89 /**
90 * @property string set the KRunner query
91 */
92 Q_PROPERTY(QString query WRITE scheduleQuery READ currentQuery NOTIFY queryChanged)
93
94 Q_PROPERTY(bool running READ running NOTIFY runningChanged)
95
96public:
97 explicit RunnerModel(QObject *parent = 0);
98 ~RunnerModel();
99
100 Q_INVOKABLE QObject *modelForRow(int row) const;
101
102 void setAllowedRunners(const QStringList &runners);
103
104 int rowCount(const QModelIndex &parent = QModelIndex()) const; // reimp
105 QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const; // reimp
106
107 bool running() const;
108
109 QString currentQuery() const;
110
111public Q_SLOTS:
112 void scheduleQuery(const QString &query);
113
114Q_SIGNALS:
115 void queryChanged();
116 void runningChanged(bool);
117
118private Q_SLOTS:
119 void startQuery();
120 void queryHasFinished();
121 void matchesChanged(const QList<Plasma::QueryMatch> &matches);
122 void trigger(const Plasma::QueryMatch&);
123
124private:
125 void createManager();
126 void loadRunners();
127 void clear();
128
129 Plasma::RunnerManager *m_manager;
130 QTimer *m_startQueryTimer;
131 QTimer *m_runningChangedTimeout;
132
133 QList<RunnerSubModel *> m_models;
134 QStringList m_pendingRunnersList;
135 bool m_running;
136 QString m_pendingQuery;
137};
138
139class RunnerSource : public AbstractSource
140{
141public:
142 RunnerSource(QObject *parent);
143 QAbstractItemModel *createModelFromConfigGroup(const KConfigGroup &group);
144 SourceConfigurationWidget *createConfigurationWidget(const KConfigGroup &group);
145 bool isConfigurable() const;
146};
147
148} // namespace Homerun
149
150#endif /* RUNNERMODEL_H */
1510
=== removed file 'components/sessionmodel.cpp'
--- components/sessionmodel.cpp 2012-11-14 21:30:06 +0000
+++ components/sessionmodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,137 +0,0 @@
1/*
2 Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3 Copyright (C) 2012 Shaun Reich <shaun.reich@blue-systems.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21// Own
22#include "sessionmodel.h"
23
24//Qt
25#include <QDBusConnection>
26#include <QDBusInterface>
27#include <QDBusPendingCall>
28
29// KDE
30#include <KAuthorized>
31#include <KDebug>
32#include <KIcon>
33#include <KLocale>
34#include <kworkspace/kdisplaymanager.h>
35#include <kworkspace/kworkspace.h>
36
37namespace Homerun {
38
39SessionModel::SessionModel(QObject *parent)
40: QAbstractListModel(parent)
41{
42 //FIXME: instead of just hiding these things..it'd be awesome if we could grey them out and/or provide a reason why they're not there.
43 //otherwise the user is hunting for the power buttons and for some reason it isn't where it should be.
44 if (KAuthorized::authorizeKAction("lock_screen")) {
45 SessionAction lock;
46 lock.name = i18nc("an action", "Lock");
47 lock.type = Lock;
48 lock.iconName = "system-lock-screen";
49 m_sessionList.append(lock);
50 }
51
52 if (KDisplayManager().isSwitchable() && KAuthorized::authorize(QLatin1String("switch_user"))) {
53 SessionAction switchUser;
54 switchUser.name = i18nc("an action", "Switch User");
55 switchUser.type = SwitchUser;
56 switchUser.iconName = "system-switch-user";
57 m_sessionList.append(switchUser);
58 }
59
60 const bool canLogout = KAuthorized::authorizeKAction("logout") && KAuthorized::authorize("logout");
61 if (canLogout) {
62 SessionAction logout;
63 logout.name = i18nc("an action", "Logout");
64 logout.type = Logout;
65 logout.iconName = "system-log-out";
66 m_sessionList.append(logout);
67 }
68}
69
70SessionModel::~SessionModel()
71{
72}
73
74int SessionModel::count() const
75{
76 return m_sessionList.count();
77}
78
79QString SessionModel::name() const
80{
81 return i18n("Session");
82}
83
84int SessionModel::rowCount(const QModelIndex &index) const
85{
86 if (index.isValid()) {
87 return 0;
88 }
89 return m_sessionList.count();
90}
91
92QVariant SessionModel::data(const QModelIndex &index, int role) const
93{
94 SessionAction action = m_sessionList.value(index.row());
95
96 if (role == Qt::DisplayRole) {
97 return action.name;
98 } else if (role == Qt::DecorationRole) {
99 return KIcon(action.iconName);
100 } else {
101 kWarning() << "Unhandled role" << role;
102 return QVariant();
103 }
104}
105
106bool SessionModel::trigger(int row)
107{
108 SessionAction action = m_sessionList.value(row);
109
110 switch (action.type) {
111 case Logout:
112 KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeNone);
113 break;
114
115 case SwitchUser: {
116 QDBusConnection bus = QDBusConnection::sessionBus();
117 QDBusInterface interface("org.kde.krunner", "/App", "org.kde.krunner", bus);
118
119 interface.asyncCall("switchUser");
120 }
121 break;
122
123 case Lock: {
124 QDBusConnection bus = QDBusConnection::sessionBus();
125 QDBusInterface interface("org.freedesktop.ScreenSaver", "/ScreenSaver", "org.freedesktop.ScreenSaver", bus);
126
127 interface.asyncCall("Lock");
128 }
129 break;
130 }
131
132 return true;
133}
134
135} // namespace Homerun
136
137#include "sessionmodel.moc"
1380
=== removed file 'components/sessionmodel.h'
--- components/sessionmodel.h 2012-11-14 21:30:06 +0000
+++ components/sessionmodel.h 1970-01-01 00:00:00 +0000
@@ -1,72 +0,0 @@
1/*
2 Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3 Copyright 2012 (C) Shaun Reich <shaun.reich@blue-systems.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef SESSIONMODEL_H
22#define SESSIONMODEL_H
23
24#include <QAbstractListModel>
25
26#include <KService>
27
28class QString;
29
30namespace Homerun {
31
32enum ActionType {
33 Logout,
34 SwitchUser,
35 Lock
36};
37
38struct SessionAction
39{
40 QString name;
41 QString iconName;
42 ActionType type;
43};
44
45class SessionModel : public QAbstractListModel
46{
47 Q_OBJECT
48 Q_PROPERTY(QString name READ name CONSTANT)
49 Q_PROPERTY(int count READ count NOTIFY countChanged)
50
51public:
52 SessionModel(QObject *parent = 0);
53 ~SessionModel();
54
55 int count() const;
56 QString name() const;
57
58 int rowCount(const QModelIndex & = QModelIndex()) const;
59 QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const;
60
61 Q_INVOKABLE bool trigger(int row);
62
63Q_SIGNALS:
64 void countChanged();
65
66private:
67 QList<SessionAction> m_sessionList;
68};
69
70} // namespace Homerun
71
72#endif
730
=== added file 'components/shadoweffect.cpp'
--- components/shadoweffect.cpp 1970-01-01 00:00:00 +0000
+++ components/shadoweffect.cpp 2013-03-01 15:15:27 +0000
@@ -0,0 +1,222 @@
1/*
2 * Copyright 2013 Aurélien Gâteau <agateau@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19// Self
20#include <shadoweffect.h>
21
22// Local
23
24// KDE
25#include <KDebug>
26#include <Plasma/PaintUtils>
27
28// Qt
29#include <QPainter>
30#include <QPaintEngine>
31
32ShadowEffect::ShadowEffect(QObject *parent)
33: QGraphicsEffect(parent)
34, m_xOffset(0)
35, m_yOffset(1)
36, m_blurRadius(3)
37{
38}
39
40ShadowEffect::~ShadowEffect()
41{
42}
43
44qreal ShadowEffect::xOffset() const
45{
46 return m_xOffset;
47}
48
49qreal ShadowEffect::yOffset() const
50{
51 return m_yOffset;
52}
53
54qreal ShadowEffect::blurRadius() const
55{
56 return m_blurRadius;
57}
58
59QColor ShadowEffect::color() const
60{
61 return m_color;
62}
63
64#define SETTER(prop) \
65 if (prop == value) { \
66 return; \
67 } \
68 prop = value;
69
70#define SETTER_REAL(prop) \
71 if (qFuzzyCompare(prop, value)) { \
72 return; \
73 } \
74 prop = value;
75
76void ShadowEffect::setXOffset(qreal value)
77{
78 SETTER_REAL(m_xOffset);
79 m_shadow = QImage();
80 updateBoundingRect();
81 xOffsetChanged(m_xOffset);
82}
83
84void ShadowEffect::setYOffset(qreal value)
85{
86 SETTER_REAL(m_yOffset);
87 m_shadow = QImage();
88 updateBoundingRect();
89 yOffsetChanged(m_yOffset);
90}
91
92void ShadowEffect::setBlurRadius(qreal value)
93{
94 SETTER_REAL(m_blurRadius);
95 m_shadow = QImage();
96 updateBoundingRect();
97 blurRadiusChanged(m_blurRadius);
98}
99
100void ShadowEffect::setColor(const QColor &value)
101{
102 SETTER(m_color);
103 m_shadow = QImage();
104 update();
105 colorChanged(m_color);
106}
107
108void ShadowEffect::resetColor()
109{
110 setColor(QColor());
111}
112
113QRectF ShadowEffect::boundingRectFor(const QRectF &rect) const
114{
115 qreal padding = m_blurRadius * 2;
116 return rect.united(
117 rect.translated(m_xOffset, m_yOffset)
118 .adjusted(-padding, -padding, padding, padding)
119 );
120}
121
122QImage ShadowEffect::generateShadow(const QPixmap &px) const
123{
124 if (px.isNull()) {
125 return QImage();
126 }
127
128 // Generate shadow in tmp
129 QImage tmp(px.size(), QImage::Format_ARGB32_Premultiplied);
130 tmp.fill(0);
131 QPainter tmpPainter(&tmp);
132 tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
133 tmpPainter.drawPixmap(m_xOffset, m_yOffset, px);
134 tmpPainter.end();
135 QColor color = m_color.isValid() ? m_color : computeColorFromSource();
136 Plasma::PaintUtils::shadowBlur(tmp, m_blurRadius, color);
137 return tmp;
138}
139
140void ShadowEffect::draw(QPainter *painter)
141{
142 if (m_blurRadius <= 0 && qFuzzyIsNull(m_xOffset) && qFuzzyIsNull(m_yOffset)) {
143 drawSource(painter);
144 return;
145 }
146
147 PixmapPadMode mode = PadToEffectiveBoundingRect;
148 if (painter->paintEngine()->type() == QPaintEngine::OpenGL2) {
149 mode = NoPad;
150 }
151
152 // Draw pixmap in device coordinates to avoid pixmap scaling.
153 QPoint offset;
154 const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);
155 if (pixmap.isNull()) {
156 return;
157 }
158
159 QTransform restoreTransform = painter->worldTransform();
160 painter->setWorldTransform(QTransform());
161 if (m_shadow.isNull()) {
162 m_shadow = generateShadow(pixmap);
163 }
164 // Draw shadow (draw it twice to darken it)
165 painter->drawImage(offset, m_shadow);
166 painter->drawImage(offset, m_shadow);
167 // Draw the actual pixmap
168 painter->drawPixmap(offset, pixmap);
169 painter->setWorldTransform(restoreTransform);
170}
171
172void ShadowEffect::sourceChanged(ChangeFlags flags)
173{
174 switch (flags) {
175 case SourceAttached:
176 case SourceBoundingRectChanged:
177 case SourceInvalidated:
178 m_shadow = QImage();
179 break;
180 case SourceDetached:
181 break;
182 }
183}
184
185
186/**********************************************************
187 * UGLYNESS
188 * This is a severely trimmed copy of an internal class defined in qt:
189 * src/gui/effects/qgraphicseffect_p.h
190 *********************************************************/
191class QGraphicsEffectSource
192{
193public:
194 const QGraphicsItem *graphicsItem() const;
195};
196/**********************************************************
197 * /UGLYNESS
198 *********************************************************/
199
200
201QColor ShadowEffect::computeColorFromSource() const
202{
203 const QGraphicsItem *item = source()->graphicsItem();
204 if (!item) {
205 kWarning() << "No source item!";
206 return Qt::black;
207 }
208 const QGraphicsObject *obj = item->toGraphicsObject();
209 if (!obj) {
210 kWarning() << "Source is not a QGraphicsObject";
211 return Qt::black;
212 }
213 QVariant variant = obj->property("color");
214 if (!variant.canConvert<QColor>()) {
215 kWarning() << "Source has no 'color' property, or its 'color' property is not a QColor!";
216 return Qt::black;
217 }
218 int value = variant.value<QColor>().value();
219 return value > 128 ? Qt::black : Qt::white;
220}
221
222#include <shadoweffect.moc>
0223
=== added file 'components/shadoweffect.h'
--- components/shadoweffect.h 1970-01-01 00:00:00 +0000
+++ components/shadoweffect.h 2013-03-01 15:15:27 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright 2013 Aurélien Gâteau <agateau@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#ifndef SHADOWEFFECT_H
20#define SHADOWEFFECT_H
21
22// Local
23
24// Qt
25#include <QGraphicsEffect>
26
27// KDE
28
29/**
30 * An effect which draws a halo
31 */
32class ShadowEffect : public QGraphicsEffect
33{
34 Q_OBJECT
35 Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY xOffsetChanged)
36 Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY yOffsetChanged)
37 Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
38 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
39public:
40 explicit ShadowEffect(QObject *parent = 0);
41 ~ShadowEffect();
42
43 QRectF boundingRectFor(const QRectF &rect) const; // reimp
44
45 qreal xOffset() const;
46
47 qreal yOffset() const;
48
49 qreal blurRadius() const;
50 QColor color() const;
51
52 /**
53 * Use this method if you set the color manually and now want ShadowEffect
54 * to pick the color automatically, based on the source object.
55 */
56 Q_INVOKABLE void resetColor();
57
58public Q_SLOTS:
59 void setXOffset(qreal dx);
60 void setYOffset(qreal dy);
61 void setBlurRadius(qreal blurRadius);
62 void setColor(const QColor &color);
63
64Q_SIGNALS:
65 void xOffsetChanged(qreal);
66 void yOffsetChanged(qreal);
67 void blurRadiusChanged(qreal blurRadius);
68 void colorChanged(const QColor &color);
69
70protected:
71 void draw(QPainter *painter); // reimp
72 void sourceChanged(ChangeFlags flags); // reimp
73
74private:
75 qreal m_xOffset;
76 qreal m_yOffset;
77 qreal m_blurRadius;
78 QColor m_color;
79
80 QImage m_shadow;
81
82 QImage generateShadow(const QPixmap &px) const;
83
84 QColor computeColorFromSource() const;
85};
86
87#endif /* SHADOWEFFECT_H */
088
=== removed file 'components/sourceid.cpp'
--- components/sourceid.cpp 2012-11-14 21:30:06 +0000
+++ components/sourceid.cpp 1970-01-01 00:00:00 +0000
@@ -1,163 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Self
21#include <sourceid.h>
22
23// Local
24
25// KDE
26#include <KDebug>
27
28// Qt
29#include <QStringList>
30
31static const char SOURCE_NAME_SEPARATOR = ':';
32
33#define ARG_SEPARATOR ';'
34#define ARG_SEPARATOR_STR ";"
35static const char ARG_KEY_VALUE_SEPARATOR = '=';
36
37//- SourceId ----------------------------------
38QString SourceId::name() const
39{
40 return m_name;
41}
42
43void SourceId::setName(const QString &name)
44{
45 m_name = name;
46}
47
48SourceArguments &SourceId::arguments()
49{
50 return m_arguments;
51}
52
53const SourceArguments &SourceId::arguments() const
54{
55 return m_arguments;
56}
57
58QString SourceId::toString() const
59{
60 if (m_arguments.isEmpty()) {
61 return m_name;
62 }
63 return m_name % SOURCE_NAME_SEPARATOR % m_arguments.toString();
64}
65
66SourceId SourceId::fromString(const QString &sourceString, bool *ok)
67{
68 *ok = true;
69 SourceId sourceId;
70
71 int idx = sourceString.indexOf(SOURCE_NAME_SEPARATOR);
72 if (idx == -1) {
73 sourceId.setName(sourceString);
74 return sourceId;
75 }
76
77 sourceId.m_name = sourceString.left(idx);
78 QString args = sourceString.mid(idx + 1);
79
80 sourceId.m_arguments = SourceArguments::fromString(args, ok);
81 if (!*ok) {
82 return SourceId();
83 }
84 return sourceId;
85}
86
87bool SourceId::isValid() const
88{
89 return !m_name.isEmpty();
90}
91
92//- SourceArguments ---------------------------
93static QString escapeValue(const QString &src)
94{
95 QString dst = src;
96 dst.replace('\\', "\\\\"); // must be done first
97 dst.replace(ARG_SEPARATOR, "\\" ARG_SEPARATOR_STR);
98 return dst;
99}
100
101static QStringList split(const QString &src)
102{
103 bool escaped = false;
104 QStringList lst;
105 QString token;
106 auto it = src.constBegin(), end = src.constEnd();
107 for (; it != end; ++it) {
108 const QChar ch = *it;
109 if (escaped) {
110 escaped = false;
111 } else if (ch == '\\') {
112 escaped = true;
113 continue;
114 } else if (ch == ARG_SEPARATOR) {
115 lst.append(token);
116 token.clear();
117 continue;
118 }
119 token.append(ch);
120 }
121 lst.append(token);
122 return lst;
123}
124
125SourceArguments SourceArguments::fromString(const QString &str, bool *ok)
126{
127 Q_ASSERT(ok);
128 *ok = true;
129 SourceArguments args;
130 if (str.isEmpty()) {
131 return args;
132 }
133
134 QStringList tokens = split(str);
135 Q_FOREACH(const QString &token, tokens) {
136 int idx = token.indexOf(ARG_KEY_VALUE_SEPARATOR);
137 if (idx == -1) {
138 kWarning() << "Invalid argument" << token << "in" << str;
139 *ok = false;
140 return SourceArguments();
141 }
142 QString key = token.left(idx);
143 QString value = token.mid(idx + 1);
144 args.insert(key, value);
145 }
146 return args;
147}
148
149SourceArguments &SourceArguments::add(const QString &key, const QString &value)
150{
151 insert(key, value);
152 return *this;
153}
154
155QString SourceArguments::toString() const
156{
157 QStringList lst;
158 auto it = constBegin(), end = constEnd();
159 for (; it != end ; ++it) {
160 lst << it.key() % ARG_KEY_VALUE_SEPARATOR % escapeValue(it.value());
161 }
162 return lst.join(ARG_SEPARATOR_STR);
163}
1640
=== removed file 'components/sourceid.h'
--- components/sourceid.h 2012-11-14 21:30:06 +0000
+++ components/sourceid.h 1970-01-01 00:00:00 +0000
@@ -1,66 +0,0 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef SOURCEID_H
21#define SOURCEID_H
22
23// Local
24
25// Qt
26#include <QHash>
27#include <QString>
28
29// KDE
30
31/**
32 * The arguments of a source. Used within a SourceId instance.
33 */
34class SourceArguments : public QHash<QString, QString>
35{
36public:
37 SourceArguments &add(const QString &key, const QString &value);
38
39 QString toString() const;
40
41 static SourceArguments fromString(const QString &, bool *ok);
42};
43
44/**
45 * Represents a source and its optional arguments
46 */
47class SourceId
48{
49public:
50 void setName(const QString &);
51 QString name() const;
52 SourceArguments &arguments();
53 const SourceArguments &arguments() const;
54
55 QString toString() const;
56
57 static SourceId fromString(const QString &, bool *ok);
58
59 bool isValid() const;
60
61private:
62 QString m_name;
63 SourceArguments m_arguments;
64};
65
66#endif /* SOURCEID_H */
670
=== modified file 'components/sourceregistry.cpp'
--- components/sourceregistry.cpp 2012-11-14 21:30:06 +0000
+++ components/sourceregistry.cpp 2013-03-01 15:15:27 +0000
@@ -23,18 +23,20 @@
23// Local23// Local
24#include <abstractsource.h>24#include <abstractsource.h>
25#include <customtypes.h>25#include <customtypes.h>
26#include <dirmodel.h>
27#include <favoriteappsmodel.h>
28
29#include <groupedinstalledappsmodel.h>
30#include <libhomerun_config.h>26#include <libhomerun_config.h>
31#include <favoriteplacesmodel.h>
32#include <powermodel.h>
33#include <runnermodel.h>
34#include <installedappsmodel.h>
35#include <sessionmodel.h>
36#include <sourceconfigurationdialog.h>27#include <sourceconfigurationdialog.h>
3728
29#include <sources/dir/dirmodel.h>
30#include <sources/favorites/favoriteappsmodel.h>
31#include <sources/favorites/favoriteplacesmodel.h>
32#include <sources/installedapps/installedappsmodel.h>
33#include <sources/installedapps/groupedinstalledappsmodel.h>
34#include <sources/power/powermodel.h>
35#include <sources/runners/singlerunnermodel.h>
36#include <sources/runners/runnermodel.h>
37#include <sources/session/openedsessionsmodel.h>
38#include <sources/session/sessionmodel.h>
39
38// KDE40// KDE
39#include <KConfigGroup>41#include <KConfigGroup>
40#include <KDebug>42#include <KDebug>
@@ -42,6 +44,7 @@
42#include <KPluginInfo>44#include <KPluginInfo>
43#include <KPluginLoader>45#include <KPluginLoader>
44#include <KServiceTypeTrader>46#include <KServiceTypeTrader>
47#include <Plasma/PluginLoader>
4548
46// Qt49// Qt
47#include <QApplication>50#include <QApplication>
@@ -218,6 +221,20 @@
218 }221 }
219 return sourceInfo->source;222 return sourceInfo->source;
220 }223 }
224
225 void registerSingleRunnerSources()
226 {
227 KPluginInfo::List list = Plasma::PluginLoader::pluginLoader()->listRunnerInfo();
228 Q_FOREACH(const KPluginInfo &info, list) {
229 if (!info.property("X-Plasma-AdvertiseSingleRunnerQueryMode").toBool()) {
230 continue;
231 }
232 QString runnerId = info.pluginName();
233 SingleRunnerSource *source = new SingleRunnerSource(runnerId, q);
234 QString name = i18n("Runner: %1", info.name());
235 registerSource("SingleRunner/" + runnerId, source, name, info.comment());
236 }
237 }
221};238};
222239
223//- SourceRegistry --------------------------------------------240//- SourceRegistry --------------------------------------------
@@ -259,11 +276,17 @@
259 i18n("Session"),276 i18n("Session"),
260 i18n("Provide buttons to lock the screen, log out, or switch to another user")277 i18n("Provide buttons to lock the screen, log out, or switch to another user")
261 );278 );
279 d->registerSource("OpenedSessions", new SimpleSource<OpenedSessionsModel>(this),
280 i18n("Opened Sessions"),
281 i18n("Provide buttons to switch to opened sessions")
282 );
262 d->registerSource("Runner", new RunnerSource(this),283 d->registerSource("Runner", new RunnerSource(this),
263 i18n("KRunner"),284 i18n("KRunner"),
264 i18n("Perform searchs using a selection of runners")285 i18n("Perform searchs using a selection of runners")
265 );286 );
266287
288 d->registerSingleRunnerSources();
289
267 d->listSourcePlugins();290 d->listSourcePlugins();
268}291}
269292
270293
=== added directory 'components/sources'
=== added directory 'components/sources/dir'
=== added file 'components/sources/dir/dirconfigurationwidget.cpp'
--- components/sources/dir/dirconfigurationwidget.cpp 1970-01-01 00:00:00 +0000
+++ components/sources/dir/dirconfigurationwidget.cpp 2013-03-01 15:15:27 +0000
@@ -0,0 +1,67 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Self
21#include <dirconfigurationwidget.h>
22
23// Local
24#include <ui_dirconfigurationwidget.h>
25
26// KDE
27#include <KGlobalSettings>
28#include <KUrlRequester>
29
30// Qt
31#include <QDir>
32#include <QVBoxLayout>
33
34using namespace Homerun;
35
36DirConfigurationWidget::DirConfigurationWidget(const KConfigGroup &group)
37: SourceConfigurationWidget(group)
38, m_ui(new Ui_DirConfigurationWidget)
39{
40 m_ui->setupUi(this);
41
42 QFont helpFont = KGlobalSettings::smallestReadableFont();
43 m_ui->titleHelpLabel->setFont(helpFont);
44
45 KUrl url = group.readPathEntry("rootUrl", QDir::homePath());
46 if (url.isValid()) {
47 m_ui->urlRequester->setUrl(url);
48 }
49
50 m_ui->titleLineEdit->setText(group.readEntry("rootName", QString()));
51}
52
53DirConfigurationWidget::~DirConfigurationWidget()
54{
55 delete m_ui;
56}
57
58void DirConfigurationWidget::save()
59{
60 KUrl url = m_ui->urlRequester->url().url();
61 QString title = m_ui->titleLineEdit->text();
62
63 configGroup().writePathEntry("rootUrl", url.url());
64 configGroup().writeEntry("rootName", title);
65}
66
67#include <dirconfigurationwidget.moc>
068
=== added file 'components/sources/dir/dirconfigurationwidget.h'
--- components/sources/dir/dirconfigurationwidget.h 1970-01-01 00:00:00 +0000
+++ components/sources/dir/dirconfigurationwidget.h 2013-03-01 15:15:27 +0000
@@ -0,0 +1,48 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef DIRCONFIGURATIONWIDGET_H
21#define DIRCONFIGURATIONWIDGET_H
22
23// Local
24#include <sourceconfigurationwidget.h>
25
26// Qt
27
28// KDE
29
30class Ui_DirConfigurationWidget;
31
32/**
33 * Configuration widget for the Dir source
34 */
35class DirConfigurationWidget : public Homerun::SourceConfigurationWidget
36{
37 Q_OBJECT
38public:
39 DirConfigurationWidget(const KConfigGroup &group);
40 ~DirConfigurationWidget();
41
42 void save(); // reimp
43
44private:
45 Ui_DirConfigurationWidget *m_ui;
46};
47
48#endif /* DIRCONFIGURATIONWIDGET_H */
049
=== added file 'components/sources/dir/dirconfigurationwidget.ui'
--- components/sources/dir/dirconfigurationwidget.ui 1970-01-01 00:00:00 +0000
+++ components/sources/dir/dirconfigurationwidget.ui 2013-03-01 15:15:27 +0000
@@ -0,0 +1,83 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>DirConfigurationWidget</class>
4 <widget class="QWidget" name="DirConfigurationWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>400</width>
10 <height>85</height>
11 </rect>
12 </property>
13 <property name="sizePolicy">
14 <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
15 <horstretch>0</horstretch>
16 <verstretch>0</verstretch>
17 </sizepolicy>
18 </property>
19 <property name="minimumSize">
20 <size>
21 <width>400</width>
22 <height>0</height>
23 </size>
24 </property>
25 <property name="windowTitle">
26 <string/>
27 </property>
28 <layout class="QFormLayout" name="formLayout">
29 <item row="1" column="0">
30 <widget class="QLabel" name="label_2">
31 <property name="text">
32 <string>Folder to show:</string>
33 </property>
34 <property name="buddy">
35 <cstring>urlRequester</cstring>
36 </property>
37 </widget>
38 </item>
39 <item row="1" column="1">
40 <widget class="KUrlRequester" name="urlRequester">
41 <property name="mode">
42 <set>KFile::Directory|KFile::ExistingOnly</set>
43 </property>
44 </widget>
45 </item>
46 <item row="2" column="1">
47 <widget class="QLineEdit" name="titleLineEdit"/>
48 </item>
49 <item row="2" column="0">
50 <widget class="QLabel" name="label">
51 <property name="text">
52 <string>Title:</string>
53 </property>
54 <property name="buddy">
55 <cstring>titleLineEdit</cstring>
56 </property>
57 </widget>
58 </item>
59 <item row="3" column="1">
60 <widget class="QLabel" name="titleHelpLabel">
61 <property name="sizePolicy">
62 <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
63 <horstretch>0</horstretch>
64 <verstretch>0</verstretch>
65 </sizepolicy>
66 </property>
67 <property name="text">
68 <string>If title is left empty, the folder name will be used</string>
69 </property>
70 </widget>
71 </item>
72 </layout>
73 </widget>
74 <customwidgets>
75 <customwidget>
76 <class>KUrlRequester</class>
77 <extends>QFrame</extends>
78 <header>kurlrequester.h</header>
79 </customwidget>
80 </customwidgets>
81 <resources/>
82 <connections/>
83</ui>
084
=== added file 'components/sources/dir/dirmodel.cpp'
--- components/sources/dir/dirmodel.cpp 1970-01-01 00:00:00 +0000
+++ components/sources/dir/dirmodel.cpp 2013-03-01 15:15:27 +0000
@@ -0,0 +1,259 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20// Self
21#include <dirmodel.h>
22
23// Local
24#include <dirconfigurationwidget.h>
25#include <favoriteplacesmodel.h>
26
27// libhomerun
28#include <actionlist.h>
29#include <pathmodel.h>
30
31// KDE
32#include <KConfigGroup>
33#include <KDebug>
34#include <KDirModel>
35#include <KDirLister>
36
37// Qt
38#include <QDir>
39
40namespace Homerun
41{
42
43static const char *SOURCE_ID = "Dir";
44
45static inline KFileItem itemForIndex(const QModelIndex &index)
46{
47 return index.data(KDirModel::FileItemRole).value<KFileItem>();
48}
49
50//- DirModel ------------------------------------------------------
51QVariantMap DirModel::sourceArguments(const KUrl &rootUrl, const QString &rootName, const KUrl &url)
52{
53 QVariantMap args;
54 args.insert("rootUrl", rootUrl.url());
55 args.insert("rootName", rootName);
56 args.insert("url", url.url());
57 return args;
58}
59
60
61DirModel::DirModel(QObject *parent)
62: KDirSortFilterProxyModel(parent)
63, m_pathModel(new PathModel(this))
64{
65 setSourceModel(new KDirModel(this));
66 setSortFoldersFirst(true);
67
68 QHash<int, QByteArray> roles;
69 roles.insert(Qt::DisplayRole, "display");
70 roles.insert(Qt::DecorationRole, "decoration");
71 roles.insert(DirModel::FavoriteIdRole, "favoriteId");
72 roles.insert(DirModel::HasActionListRole, "hasActionList");
73 roles.insert(DirModel::ActionListRole, "actionList");
74 setRoleNames(roles);
75
76 dirLister()->setDelayedMimeTypes(true);
77 connect(dirLister(), SIGNAL(started(KUrl)), SLOT(emitRunningChanged()));
78 connect(dirLister(), SIGNAL(completed()), SLOT(emitRunningChanged()));
79}
80
81void DirModel::init(const KUrl &rootUrl, const QString &rootName, const KUrl &url)
82{
83 m_rootUrl = rootUrl;
84 m_rootName = rootName;
85 initPathModel(url);
86 dirLister()->openUrl(url);
87}
88
89void DirModel::initPathModel(const KUrl &openedUrl)
90{
91 QVariantMap args = sourceArguments(m_rootUrl, m_rootName, m_rootUrl);
92 m_pathModel->addPath(m_rootName, SOURCE_ID, args);
93
94 KUrl rootUrl = m_rootUrl;
95 // Needed for KUrl::relativeUrl
96 rootUrl.adjustPath(KUrl::AddTrailingSlash);
97 QString relativePath = KUrl::relativeUrl(rootUrl, openedUrl);
98 if (relativePath == "./") {
99 return;
100 }
101 KUrl url = m_rootUrl;
102 Q_FOREACH(const QString &token, relativePath.split('/')) {
103 if (token.isEmpty()) {
104 // Just in case relativePath ends with '/'
105 continue;
106 }
107 url.addPath(token);
108 args["url"] = url.url();
109 m_pathModel->addPath(token, SOURCE_ID, args);
110 }
111}
112
113KDirLister *DirModel::dirLister() const
114{
115 return static_cast<KDirModel *>(sourceModel())->dirLister();
116}
117
118QVariant DirModel::data(const QModelIndex &index, int role) const
119{
120 if (role != FavoriteIdRole && role != HasActionListRole && role != ActionListRole) {
121 return QSortFilterProxyModel::data(index, role);
122 }
123 if (index.row() < 0 || index.row() >= rowCount()) {
124 return QVariant();
125 }
126 if (role == HasActionListRole) {
127 return true;
128 }
129 KFileItem item = itemForIndex(index);
130 if (role == FavoriteIdRole) {
131 if (item.isDir()) {
132 return FavoritePlacesModel::favoriteIdFromUrl(item.url());
133 } else {
134 return QString();
135 }
136 } else if (role == ActionListRole) {
137 return ActionList::createListForFileItem(item);
138 }
139 // Never reached
140 return QVariant();
141}
142
143int DirModel::count() const
144{
145 return rowCount(QModelIndex());
146}
147
148QString DirModel::name() const
149{
150 return m_rootName;
151}
152
153bool DirModel::running() const
154{
155 return !dirLister()->isFinished();
156}
157
158PathModel *DirModel::pathModel() const
159{
160 return m_pathModel;
161}
162
163QString DirModel::query() const
164{
165 return filterRegExp().pattern();
166}
167
168void DirModel::setQuery(const QString &value)
169{
170 if (value == query()) {
171 return;
172 }
173 setFilterRegExp(QRegExp(value, Qt::CaseInsensitive));
174 queryChanged(value);
175}
176
177void DirModel::emitRunningChanged()
178{
179 runningChanged(running());
180}
181
182bool DirModel::trigger(int row, const QString &actionId, const QVariant &actionArg)
183{
184 QModelIndex idx = index(row, 0);
185 KFileItem item = itemForIndex(idx);
186
187 if (actionId.isEmpty()) {
188 if (item.isDir()) {
189 openSourceRequested(SOURCE_ID, sourceArguments(m_rootUrl, m_rootName, item.url()));
190 return false;
191 } else {
192 item.run();
193 return true;
194 }
195 }
196 bool close = false;
197 if (ActionList::handleFileItemAction(item, actionId, actionArg, &close)) {
198 return close;
199 }
200 return false;
201}
202
203//- DirSource -------------------------------------------------------
204DirSource::DirSource(QObject *parent)
205: AbstractSource(parent)
206{}
207
208QAbstractItemModel *DirSource::createModelFromArguments(const QVariantMap &args)
209{
210 KUrl rootUrl = args.value("rootUrl").toString();
211 QString rootName = args.value("rootName").toString();
212 KUrl url = args.value("url").toString();
213 return createModel(rootUrl, rootName, url);
214}
215
216QAbstractItemModel *DirSource::createModelFromConfigGroup(const KConfigGroup &group)
217{
218 KUrl rootUrl = group.readPathEntry("rootUrl", QDir::homePath());
219 QString rootName = group.readEntry("rootName", QString());
220 return createModel(rootUrl, rootName, KUrl());
221}
222
223QAbstractItemModel *DirSource::createModel(const KUrl &rootUrl_, const QString &rootName_, const KUrl &url_)
224{
225 KUrl rootUrl = rootUrl_;
226 QString rootName = rootName_;
227 KUrl url = url_;
228 if (!rootUrl.isValid()) {
229 rootUrl = KUrl::fromPath(QDir::homePath());
230 }
231
232 if (rootName.isEmpty()) {
233 rootName = rootUrl.fileName();
234 if (rootName.isEmpty()) {
235 rootName = rootUrl.prettyUrl();
236 }
237 }
238 if (!url.isValid()) {
239 url = rootUrl;
240 }
241
242 DirModel *model = new DirModel;
243 model->init(rootUrl, rootName, url);
244 return model;
245}
246
247bool DirSource::isConfigurable() const
248{
249 return true;
250}
251
252SourceConfigurationWidget *DirSource::createConfigurationWidget(const KConfigGroup &group)
253{
254 return new DirConfigurationWidget(group);
255}
256
257} // namespace Homerun
258
259#include <dirmodel.moc>
0260
=== added file 'components/sources/dir/dirmodel.h'
--- components/sources/dir/dirmodel.h 1970-01-01 00:00:00 +0000
+++ components/sources/dir/dirmodel.h 2013-03-01 15:15:27 +0000
@@ -0,0 +1,113 @@
1/*
2Copyright 2012 Aurélien Gâteau <agateau@kde.org>
3
4This library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Lesser General Public
6License as published by the Free Software Foundation; either
7version 2.1 of the License, or (at your option) version 3, or any
8later version accepted by the membership of KDE e.V. (or its
9successor approved by the membership of KDE e.V.), which shall
10act as a proxy defined in Section 6 of version 3 of the license.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef DIRMODEL_H
21#define DIRMODEL_H
22
23// Local
24#include <abstractsource.h>
25
26// Qt
27
28// KDE
29#include <KDirSortFilterProxyModel>
30#include <KUrl>
31
32class KDirLister;
33
34namespace Homerun {
35
36class PathModel;
37
38/**
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: