Merge lp:~smartboyhw/ubuntu/raring/homerun/0.2.1-0ubuntu1-version-1 into lp:ubuntu/raring/homerun
- Raring (13.04)
- 0.2.1-0ubuntu1-version-1
- Merge into raring
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 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Philip Muškovac (community) | Approve | ||
Review via email: mp+151266@code.launchpad.net |
Commit message
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 : | # |
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
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2012-12-18 19:55:12 +0000 | |||
3 | +++ CMakeLists.txt 2013-03-01 15:15:27 +0000 | |||
4 | @@ -3,7 +3,7 @@ | |||
5 | 3 | SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH}) | 3 | SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH}) |
6 | 4 | 4 | ||
7 | 5 | # Packaging | 5 | # Packaging |
9 | 6 | set(HOMERUN_VERSION "0.1.1") | 6 | set(HOMERUN_VERSION "0.2.1") |
10 | 7 | 7 | ||
11 | 8 | set(HOMERUN_SOURCE_VERSION "") | 8 | set(HOMERUN_SOURCE_VERSION "") |
12 | 9 | set(HOMERUN_SOURCE_DATE "") | 9 | set(HOMERUN_SOURCE_DATE "") |
13 | @@ -23,23 +23,11 @@ | |||
14 | 23 | message(STATUS "Source date: ${HOMERUN_SOURCE_DATE}") | 23 | message(STATUS "Source date: ${HOMERUN_SOURCE_DATE}") |
15 | 24 | 24 | ||
16 | 25 | # Dependencies | 25 | # Dependencies |
18 | 26 | find_package(KDE4 ${KDE_MIN_VERSION} REQUIRED) | 26 | find_package(KDE4 4.9.97 REQUIRED) |
19 | 27 | include(KDE4Defaults) | 27 | include(KDE4Defaults) |
20 | 28 | find_package(KDE4Workspace REQUIRED) | 28 | find_package(KDE4Workspace REQUIRED) |
21 | 29 | find_package(KDeclarative REQUIRED) | 29 | find_package(KDeclarative REQUIRED) |
22 | 30 | 30 | ||
23 | 31 | # Check whether KDeclarative::setupQmlJsDebugger() exists | ||
24 | 32 | set(CMAKE_REQUIRED_INCLUDES "${KDE4_INCLUDES}") | ||
25 | 33 | set(CMAKE_REQUIRED_LIBRARIES "${KDECLARATIVE_LIBRARIES}") | ||
26 | 34 | check_cxx_source_compiles(" | ||
27 | 35 | #include <kdeclarative.h> | ||
28 | 36 | int main() | ||
29 | 37 | { | ||
30 | 38 | KDeclarative::setupQmlJsDebugger(); | ||
31 | 39 | return 0; | ||
32 | 40 | } | ||
33 | 41 | " HAVE_KDECLARATIVE_SETUPQMLJSDEBUGGER) | ||
34 | 42 | |||
35 | 43 | # Compile options | 31 | # Compile options |
36 | 44 | add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) | 32 | add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) |
37 | 45 | add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) | 33 | add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) |
38 | 46 | 34 | ||
39 | === removed file 'ExtraDesktop.sh' | |||
40 | --- ExtraDesktop.sh 2012-11-14 21:30:06 +0000 | |||
41 | +++ ExtraDesktop.sh 1970-01-01 00:00:00 +0000 | |||
42 | @@ -1,6 +0,0 @@ | |||
43 | 1 | #! /bin/sh | ||
44 | 2 | #This file outputs in a separate line each file with a .desktop syntax | ||
45 | 3 | #that needs to be translated but has a non .desktop extension | ||
46 | 4 | |||
47 | 5 | #We output homerunrc because we want the title of Homerun tabs to be translated | ||
48 | 6 | echo ./config/homerunrc | ||
49 | 7 | 0 | ||
50 | === modified file 'NEWS' | |||
51 | --- NEWS 2012-12-18 19:55:12 +0000 | |||
52 | +++ NEWS 2013-03-01 15:15:27 +0000 | |||
53 | @@ -1,3 +1,27 @@ | |||
54 | 1 | # 2013.02.27 - 0.2.1 | ||
55 | 2 | |||
56 | 3 | - Fix shutdown and halt items in the Power source | ||
57 | 4 | - Improve appearance of header titles | ||
58 | 5 | |||
59 | 6 | # 2013.02.26 - 0.2.0 | ||
60 | 7 | |||
61 | 8 | - Support for single runners | ||
62 | 9 | - Items can now have more than one action. The other actions are accessible | ||
63 | 10 | through a context menu, which can be triggered by: | ||
64 | 11 | - Left-clicking the arrow in the top-right corner of the item | ||
65 | 12 | - Long-clicking the item | ||
66 | 13 | - Right-clicking the item | ||
67 | 14 | - Pressing M or the "Menu" key | ||
68 | 15 | - Some sources expose more actions: | ||
69 | 16 | - Recent documents can now forget items | ||
70 | 17 | - Items from the Dir and FavoritePlaces sources show the relevant "Open with" actions | ||
71 | 18 | - Add a "Reset tabs to default" action to the configuration menu | ||
72 | 19 | - Fix window not showing on correct desktop at startup | ||
73 | 20 | - Improved session handling: opened sessions are now listed in the "Power" tab | ||
74 | 21 | - Hide unavailable sleep modes in Power source | ||
75 | 22 | - No more border around full view | ||
76 | 23 | - Show a shadow behind text in containment mode | ||
77 | 24 | |||
78 | 1 | # 2012.12.18 - 0.1.1 | 25 | # 2012.12.18 - 0.1.1 |
79 | 2 | 26 | ||
80 | 3 | - Add support for selecting the launcher icon | 27 | - Add support for selecting the launcher icon |
81 | 4 | 28 | ||
82 | === modified file 'README.md' | |||
83 | --- README.md 2012-11-14 21:30:06 +0000 | |||
84 | +++ README.md 2013-03-01 15:15:27 +0000 | |||
85 | @@ -21,16 +21,34 @@ | |||
86 | 21 | 21 | ||
87 | 22 | ## Dependencies | 22 | ## Dependencies |
88 | 23 | 23 | ||
92 | 24 | kdelibs 4.8 | 24 | kdelibs 4.10 |
93 | 25 | 25 | ||
94 | 26 | ## Package Manager integration | 26 | ## Build instructions |
95 | 27 | |||
96 | 28 | Homerun currently requires kdelibs and kde-runtime 4.10. | ||
97 | 29 | |||
98 | 30 | To build it, do the following: | ||
99 | 31 | |||
100 | 32 | mkdir build | ||
101 | 33 | cd build | ||
102 | 34 | cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` .. | ||
103 | 35 | |||
104 | 36 | Assuming cmake did not complain about missing dependencies, run: | ||
105 | 37 | |||
106 | 38 | make | ||
107 | 39 | |||
108 | 40 | Then to install it, run as root: | ||
109 | 41 | |||
110 | 42 | make install | ||
111 | 43 | |||
112 | 44 | ## For packagers: Package manager integration | ||
113 | 27 | 45 | ||
114 | 28 | You can integrate your package manager with Homerun. | 46 | You can integrate your package manager with Homerun. |
115 | 29 | 47 | ||
116 | 30 | When browsing installed applications by category, Homerun can provide an item to | 48 | When browsing installed applications by category, Homerun can provide an item to |
117 | 31 | install more applications from this category. To do so you need to: | 49 | install more applications from this category. To do so you need to: |
118 | 32 | 50 | ||
120 | 33 | First, Create a .desktop file whose Exec= line contains a "@category" placeholder. | 51 | First, create a .desktop file whose Exec= line contains a "@category" placeholder. |
121 | 34 | This placeholder will be replaced by the category Homerun is browsing. | 52 | This placeholder will be replaced by the category Homerun is browsing. |
122 | 35 | 53 | ||
123 | 36 | For example, here is muon-discover-category.desktop: | 54 | For example, here is muon-discover-category.desktop: |
124 | 37 | 55 | ||
125 | === modified file 'applet/plasma-applet-homerunlauncher.desktop.cmake' | |||
126 | --- applet/plasma-applet-homerunlauncher.desktop.cmake 2012-12-18 19:55:12 +0000 | |||
127 | +++ applet/plasma-applet-homerunlauncher.desktop.cmake 2013-03-01 15:15:27 +0000 | |||
128 | @@ -4,32 +4,45 @@ | |||
129 | 4 | Name=KDE Homerun Launcher | 4 | Name=KDE Homerun Launcher |
130 | 5 | Name[da]=KDE Homerun-startmenu | 5 | Name[da]=KDE Homerun-startmenu |
131 | 6 | Name[el]=Εκτελεστής KDE Homerun | 6 | Name[el]=Εκτελεστής KDE Homerun |
132 | 7 | Name[es]=Lanzador Homerun de KDE | ||
133 | 7 | Name[et]=KDE Homeruni käivitaja | 8 | Name[et]=KDE Homeruni käivitaja |
134 | 9 | Name[fi]=KDE Homerun -käynnistin | ||
135 | 8 | Name[fr]=Lanceur Homerun pour KDE | 10 | Name[fr]=Lanceur Homerun pour KDE |
136 | 11 | Name[gl]=Lanzador de KDE Homerun | ||
137 | 9 | Name[hu]=KDE Homerun indító | 12 | Name[hu]=KDE Homerun indító |
138 | 13 | Name[lt]=KDE Homerun leidiklis | ||
139 | 10 | Name[nl]=Programmastarter van KDE Homerun | 14 | Name[nl]=Programmastarter van KDE Homerun |
140 | 11 | Name[pa]=ਕੇਡੀਈ ਹੋਮਰਨ ਲਾਂਚਰ | 15 | Name[pa]=ਕੇਡੀਈ ਹੋਮਰਨ ਲਾਂਚਰ |
141 | 12 | Name[pt]=Lançador Homerun do KDE | 16 | Name[pt]=Lançador Homerun do KDE |
142 | 13 | Name[pt_BR]=Lançador Homerun do KDE | 17 | Name[pt_BR]=Lançador Homerun do KDE |
143 | 18 | Name[ro]=Lansator KDE Homerun | ||
144 | 14 | Name[sk]=Spúšťač KDE Homerun | 19 | Name[sk]=Spúšťač KDE Homerun |
145 | 15 | Name[sv]=KDE Homerun startprogram | 20 | Name[sv]=KDE Homerun startprogram |
146 | 16 | Name[uk]=Засіб запуску KDE Homerun | 21 | Name[uk]=Засіб запуску KDE Homerun |
147 | 17 | Name[x-test]=xxKDE Homerun Launcherxx | 22 | Name[x-test]=xxKDE Homerun Launcherxx |
148 | 23 | Name[zh_CN]=KDE Homerun 启动器 | ||
149 | 18 | 24 | ||
150 | 19 | Comment=An application launcher | 25 | Comment=An application launcher |
151 | 20 | Comment[da]=Programstarter | 26 | Comment[da]=Programstarter |
152 | 27 | Comment[de]=Ein Anwendungsstarter | ||
153 | 21 | Comment[el]=Ένας εκτελεστής εφαρμογών | 28 | Comment[el]=Ένας εκτελεστής εφαρμογών |
154 | 29 | Comment[es]=Un lanzador de aplicaciones | ||
155 | 22 | Comment[et]=Rakenduste käivitaja | 30 | Comment[et]=Rakenduste käivitaja |
156 | 31 | Comment[fi]=Sovelluskäynnistin | ||
157 | 23 | Comment[fr]=Un lanceur d'applications | 32 | Comment[fr]=Un lanceur d'applications |
158 | 33 | Comment[gl]=Un lanzador de aplicativos | ||
159 | 24 | Comment[hu]=Egy alkalmazásindító | 34 | Comment[hu]=Egy alkalmazásindító |
160 | 35 | Comment[lt]=Programų leidiklis | ||
161 | 25 | Comment[nl]=Een programmastarter | 36 | Comment[nl]=Een programmastarter |
162 | 26 | Comment[pa]=ਐਪਲੀਕੇਸ਼ਨ ਲਾਂਚਰ | 37 | Comment[pa]=ਐਪਲੀਕੇਸ਼ਨ ਲਾਂਚਰ |
163 | 27 | Comment[pt]=Um lançador de aplicações | 38 | Comment[pt]=Um lançador de aplicações |
164 | 28 | Comment[pt_BR]=Um lançador de aplicativos | 39 | Comment[pt_BR]=Um lançador de aplicativos |
165 | 40 | Comment[ro]=Lansator de aplicații | ||
166 | 29 | Comment[sk]=Spúšťač aplikácií | 41 | Comment[sk]=Spúšťač aplikácií |
167 | 30 | Comment[sv]=Ett startprogram | 42 | Comment[sv]=Ett startprogram |
168 | 31 | Comment[uk]=Засіб для запуску програм | 43 | Comment[uk]=Засіб для запуску програм |
169 | 32 | Comment[x-test]=xxAn application launcherxx | 44 | Comment[x-test]=xxAn application launcherxx |
170 | 45 | Comment[zh_CN]=一个应用程序启动器 | ||
171 | 33 | 46 | ||
172 | 34 | Type=Service | 47 | Type=Service |
173 | 35 | ServiceTypes=Plasma/Applet | 48 | ServiceTypes=Plasma/Applet |
174 | 36 | 49 | ||
175 | === modified file 'components/CMakeLists.txt' | |||
176 | --- components/CMakeLists.txt 2012-11-14 21:30:06 +0000 | |||
177 | +++ components/CMakeLists.txt 2013-03-01 15:15:27 +0000 | |||
178 | @@ -4,30 +4,36 @@ | |||
179 | 4 | ${CMAKE_SOURCE_DIR}/internal/aboutdata.cpp | 4 | ${CMAKE_SOURCE_DIR}/internal/aboutdata.cpp |
180 | 5 | abstractsourceregistry.cpp | 5 | abstractsourceregistry.cpp |
181 | 6 | componentsplugin.cpp | 6 | componentsplugin.cpp |
182 | 7 | dirconfigurationwidget.cpp | ||
183 | 8 | dirmodel.cpp | ||
184 | 9 | favoriteappsmodel.cpp | ||
185 | 10 | favoriteplacesmodel.cpp | ||
186 | 11 | groupedinstalledappsmodel.cpp | ||
187 | 12 | helpmenuactions.cpp | 7 | helpmenuactions.cpp |
188 | 13 | icondialog.cpp | 8 | icondialog.cpp |
195 | 14 | installedappsconfigurationwidget.cpp | 9 | messagebox.cpp |
196 | 15 | installedappsmodel.cpp | 10 | shadoweffect.cpp |
191 | 16 | powermodel.cpp | ||
192 | 17 | runnerconfigurationwidget.cpp | ||
193 | 18 | runnermodel.cpp | ||
194 | 19 | sessionmodel.cpp | ||
197 | 20 | sourceconfigurationdialog.cpp | 11 | sourceconfigurationdialog.cpp |
198 | 21 | sourceid.cpp | ||
199 | 22 | sourcemodel.cpp | 12 | sourcemodel.cpp |
200 | 23 | sourceregistry.cpp | 13 | sourceregistry.cpp |
201 | 14 | sources/dir/dirconfigurationwidget.cpp | ||
202 | 15 | sources/dir/dirmodel.cpp | ||
203 | 16 | sources/favorites/favoriteappsmodel.cpp | ||
204 | 17 | sources/favorites/favoriteplacesmodel.cpp | ||
205 | 18 | sources/installedapps/groupedinstalledappsmodel.cpp | ||
206 | 19 | sources/installedapps/installedappsconfigurationwidget.cpp | ||
207 | 20 | sources/installedapps/installedappsmodel.cpp | ||
208 | 21 | sources/power/powermodel.cpp | ||
209 | 22 | sources/runners/querymatchmodel.cpp | ||
210 | 23 | sources/runners/singlerunnermodel.cpp | ||
211 | 24 | sources/runners/runnerconfigurationwidget.cpp | ||
212 | 25 | sources/runners/runnermodel.cpp | ||
213 | 26 | sources/session/openedsessionsmodel.cpp | ||
214 | 27 | sources/session/sessionmodel.cpp | ||
215 | 28 | sources/session/sessionswatcher.cpp | ||
216 | 29 | standarditemmodel.cpp | ||
217 | 24 | tabmodel.cpp | 30 | tabmodel.cpp |
218 | 25 | ) | 31 | ) |
219 | 26 | 32 | ||
220 | 27 | kde4_add_ui_files(components_SRCS | 33 | kde4_add_ui_files(components_SRCS |
224 | 28 | dirconfigurationwidget.ui | 34 | sources/dir/dirconfigurationwidget.ui |
225 | 29 | installedappsconfigurationwidget.ui | 35 | sources/installedapps/installedappsconfigurationwidget.ui |
226 | 30 | runnerconfigurationwidget.ui | 36 | sources/runners/runnerconfigurationwidget.ui |
227 | 31 | ) | 37 | ) |
228 | 32 | 38 | ||
229 | 33 | qt4_automoc(${components_SRCS}) | 39 | qt4_automoc(${components_SRCS}) |
230 | @@ -36,6 +42,12 @@ | |||
231 | 36 | ${lib_BINARY_DIR} | 42 | ${lib_BINARY_DIR} |
232 | 37 | ${lib_SOURCE_DIR} | 43 | ${lib_SOURCE_DIR} |
233 | 38 | ${CMAKE_SOURCE_DIR}/internal | 44 | ${CMAKE_SOURCE_DIR}/internal |
234 | 45 | ${CMAKE_CURRENT_SOURCE_DIR}/sources/dir | ||
235 | 46 | ${CMAKE_CURRENT_SOURCE_DIR}/sources/favorites | ||
236 | 47 | ${CMAKE_CURRENT_SOURCE_DIR}/sources/installedapps | ||
237 | 48 | ${CMAKE_CURRENT_SOURCE_DIR}/sources/power | ||
238 | 49 | ${CMAKE_CURRENT_SOURCE_DIR}/sources/runners | ||
239 | 50 | ${CMAKE_CURRENT_SOURCE_DIR}/sources/session | ||
240 | 39 | ) | 51 | ) |
241 | 40 | 52 | ||
242 | 41 | kde4_add_library(componentsplugin SHARED ${components_SRCS}) | 53 | kde4_add_library(componentsplugin SHARED ${components_SRCS}) |
243 | @@ -46,6 +58,7 @@ | |||
244 | 46 | ${KDE4_PLASMA_LIBS} | 58 | ${KDE4_PLASMA_LIBS} |
245 | 47 | ${KDE4_KIO_LIBS} | 59 | ${KDE4_KIO_LIBS} |
246 | 48 | ${KDE4_KFILE_LIBS} | 60 | ${KDE4_KFILE_LIBS} |
247 | 61 | ${KDE4_SOLID_LIBS} | ||
248 | 49 | ${KDE4WORKSPACE_KWORKSPACE_LIBS} | 62 | ${KDE4WORKSPACE_KWORKSPACE_LIBS} |
249 | 50 | homerun | 63 | homerun |
250 | 51 | ) | 64 | ) |
251 | 52 | 65 | ||
252 | === modified file 'components/componentsplugin.cpp' | |||
253 | --- components/componentsplugin.cpp 2012-11-14 21:30:06 +0000 | |||
254 | +++ components/componentsplugin.cpp 2013-03-01 15:15:27 +0000 | |||
255 | @@ -24,14 +24,18 @@ | |||
256 | 24 | 24 | ||
257 | 25 | #include <helpmenuactions.h> | 25 | #include <helpmenuactions.h> |
258 | 26 | #include <icondialog.h> | 26 | #include <icondialog.h> |
259 | 27 | #include <messagebox.h> | ||
260 | 28 | #include <shadoweffect.h> | ||
261 | 27 | #include <sourceregistry.h> | 29 | #include <sourceregistry.h> |
262 | 28 | #include <tabmodel.h> | 30 | #include <tabmodel.h> |
263 | 29 | 31 | ||
264 | 30 | void ComponentsPlugin::registerTypes(const char *uri) | 32 | void ComponentsPlugin::registerTypes(const char *uri) |
265 | 31 | { | 33 | { |
266 | 32 | Q_ASSERT(uri == QLatin1String("org.kde.homerun.components")); | 34 | Q_ASSERT(uri == QLatin1String("org.kde.homerun.components")); |
267 | 35 | qmlRegisterType<ShadowEffect>(uri, 0, 1, "ShadowEffect"); | ||
268 | 33 | qmlRegisterType<HelpMenuActions>(uri, 0, 1, "HelpMenuActions"); | 36 | qmlRegisterType<HelpMenuActions>(uri, 0, 1, "HelpMenuActions"); |
269 | 34 | qmlRegisterType<IconDialog>(uri, 0, 1, "IconDialog"); | 37 | qmlRegisterType<IconDialog>(uri, 0, 1, "IconDialog"); |
270 | 38 | qmlRegisterType<MessageBox>(uri, 0, 1, "MessageBox"); | ||
271 | 35 | qmlRegisterType<Homerun::AbstractSourceRegistry>(uri, 0, 1, "AbstractSourceRegistry"); | 39 | qmlRegisterType<Homerun::AbstractSourceRegistry>(uri, 0, 1, "AbstractSourceRegistry"); |
272 | 36 | qmlRegisterType<Homerun::SourceRegistry>(uri, 0, 1, "SourceRegistry"); | 40 | qmlRegisterType<Homerun::SourceRegistry>(uri, 0, 1, "SourceRegistry"); |
273 | 37 | qmlRegisterType<TabModel>(uri, 0, 1, "TabModel"); | 41 | qmlRegisterType<TabModel>(uri, 0, 1, "TabModel"); |
274 | 38 | 42 | ||
275 | === removed file 'components/dirconfigurationwidget.cpp' | |||
276 | --- components/dirconfigurationwidget.cpp 2012-11-14 21:30:06 +0000 | |||
277 | +++ components/dirconfigurationwidget.cpp 1970-01-01 00:00:00 +0000 | |||
278 | @@ -1,67 +0,0 @@ | |||
279 | 1 | /* | ||
280 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
281 | 3 | |||
282 | 4 | This library is free software; you can redistribute it and/or | ||
283 | 5 | modify it under the terms of the GNU Lesser General Public | ||
284 | 6 | License as published by the Free Software Foundation; either | ||
285 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
286 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
287 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
288 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
289 | 11 | |||
290 | 12 | This library is distributed in the hope that it will be useful, | ||
291 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
292 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
293 | 15 | Lesser General Public License for more details. | ||
294 | 16 | |||
295 | 17 | You should have received a copy of the GNU Lesser General Public | ||
296 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
297 | 19 | */ | ||
298 | 20 | // Self | ||
299 | 21 | #include <dirconfigurationwidget.h> | ||
300 | 22 | |||
301 | 23 | // Local | ||
302 | 24 | #include <ui_dirconfigurationwidget.h> | ||
303 | 25 | |||
304 | 26 | // KDE | ||
305 | 27 | #include <KGlobalSettings> | ||
306 | 28 | #include <KUrlRequester> | ||
307 | 29 | |||
308 | 30 | // Qt | ||
309 | 31 | #include <QDir> | ||
310 | 32 | #include <QVBoxLayout> | ||
311 | 33 | |||
312 | 34 | using namespace Homerun; | ||
313 | 35 | |||
314 | 36 | DirConfigurationWidget::DirConfigurationWidget(const KConfigGroup &group) | ||
315 | 37 | : SourceConfigurationWidget(group) | ||
316 | 38 | , m_ui(new Ui_DirConfigurationWidget) | ||
317 | 39 | { | ||
318 | 40 | m_ui->setupUi(this); | ||
319 | 41 | |||
320 | 42 | QFont helpFont = KGlobalSettings::smallestReadableFont(); | ||
321 | 43 | m_ui->titleHelpLabel->setFont(helpFont); | ||
322 | 44 | |||
323 | 45 | KUrl url = group.readPathEntry("rootUrl", QDir::homePath()); | ||
324 | 46 | if (url.isValid()) { | ||
325 | 47 | m_ui->urlRequester->setUrl(url); | ||
326 | 48 | } | ||
327 | 49 | |||
328 | 50 | m_ui->titleLineEdit->setText(group.readEntry("rootName", QString())); | ||
329 | 51 | } | ||
330 | 52 | |||
331 | 53 | DirConfigurationWidget::~DirConfigurationWidget() | ||
332 | 54 | { | ||
333 | 55 | delete m_ui; | ||
334 | 56 | } | ||
335 | 57 | |||
336 | 58 | void DirConfigurationWidget::save() | ||
337 | 59 | { | ||
338 | 60 | KUrl url = m_ui->urlRequester->url().url(); | ||
339 | 61 | QString title = m_ui->titleLineEdit->text(); | ||
340 | 62 | |||
341 | 63 | configGroup().writePathEntry("rootUrl", url.url()); | ||
342 | 64 | configGroup().writeEntry("rootName", title); | ||
343 | 65 | } | ||
344 | 66 | |||
345 | 67 | #include <dirconfigurationwidget.moc> | ||
346 | 68 | 0 | ||
347 | === removed file 'components/dirconfigurationwidget.h' | |||
348 | --- components/dirconfigurationwidget.h 2012-11-14 21:30:06 +0000 | |||
349 | +++ components/dirconfigurationwidget.h 1970-01-01 00:00:00 +0000 | |||
350 | @@ -1,48 +0,0 @@ | |||
351 | 1 | /* | ||
352 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
353 | 3 | |||
354 | 4 | This library is free software; you can redistribute it and/or | ||
355 | 5 | modify it under the terms of the GNU Lesser General Public | ||
356 | 6 | License as published by the Free Software Foundation; either | ||
357 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
358 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
359 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
360 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
361 | 11 | |||
362 | 12 | This library is distributed in the hope that it will be useful, | ||
363 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
364 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
365 | 15 | Lesser General Public License for more details. | ||
366 | 16 | |||
367 | 17 | You should have received a copy of the GNU Lesser General Public | ||
368 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
369 | 19 | */ | ||
370 | 20 | #ifndef DIRCONFIGURATIONWIDGET_H | ||
371 | 21 | #define DIRCONFIGURATIONWIDGET_H | ||
372 | 22 | |||
373 | 23 | // Local | ||
374 | 24 | #include <sourceconfigurationwidget.h> | ||
375 | 25 | |||
376 | 26 | // Qt | ||
377 | 27 | |||
378 | 28 | // KDE | ||
379 | 29 | |||
380 | 30 | class Ui_DirConfigurationWidget; | ||
381 | 31 | |||
382 | 32 | /** | ||
383 | 33 | * Configuration widget for the Dir source | ||
384 | 34 | */ | ||
385 | 35 | class DirConfigurationWidget : public Homerun::SourceConfigurationWidget | ||
386 | 36 | { | ||
387 | 37 | Q_OBJECT | ||
388 | 38 | public: | ||
389 | 39 | DirConfigurationWidget(const KConfigGroup &group); | ||
390 | 40 | ~DirConfigurationWidget(); | ||
391 | 41 | |||
392 | 42 | void save(); // reimp | ||
393 | 43 | |||
394 | 44 | private: | ||
395 | 45 | Ui_DirConfigurationWidget *m_ui; | ||
396 | 46 | }; | ||
397 | 47 | |||
398 | 48 | #endif /* DIRCONFIGURATIONWIDGET_H */ | ||
399 | 49 | 0 | ||
400 | === removed file 'components/dirconfigurationwidget.ui' | |||
401 | --- components/dirconfigurationwidget.ui 2012-11-14 21:30:06 +0000 | |||
402 | +++ components/dirconfigurationwidget.ui 1970-01-01 00:00:00 +0000 | |||
403 | @@ -1,83 +0,0 @@ | |||
404 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
405 | 2 | <ui version="4.0"> | ||
406 | 3 | <class>DirConfigurationWidget</class> | ||
407 | 4 | <widget class="QWidget" name="DirConfigurationWidget"> | ||
408 | 5 | <property name="geometry"> | ||
409 | 6 | <rect> | ||
410 | 7 | <x>0</x> | ||
411 | 8 | <y>0</y> | ||
412 | 9 | <width>400</width> | ||
413 | 10 | <height>85</height> | ||
414 | 11 | </rect> | ||
415 | 12 | </property> | ||
416 | 13 | <property name="sizePolicy"> | ||
417 | 14 | <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | ||
418 | 15 | <horstretch>0</horstretch> | ||
419 | 16 | <verstretch>0</verstretch> | ||
420 | 17 | </sizepolicy> | ||
421 | 18 | </property> | ||
422 | 19 | <property name="minimumSize"> | ||
423 | 20 | <size> | ||
424 | 21 | <width>400</width> | ||
425 | 22 | <height>0</height> | ||
426 | 23 | </size> | ||
427 | 24 | </property> | ||
428 | 25 | <property name="windowTitle"> | ||
429 | 26 | <string/> | ||
430 | 27 | </property> | ||
431 | 28 | <layout class="QFormLayout" name="formLayout"> | ||
432 | 29 | <item row="1" column="0"> | ||
433 | 30 | <widget class="QLabel" name="label_2"> | ||
434 | 31 | <property name="text"> | ||
435 | 32 | <string>Folder to show:</string> | ||
436 | 33 | </property> | ||
437 | 34 | <property name="buddy"> | ||
438 | 35 | <cstring>urlRequester</cstring> | ||
439 | 36 | </property> | ||
440 | 37 | </widget> | ||
441 | 38 | </item> | ||
442 | 39 | <item row="1" column="1"> | ||
443 | 40 | <widget class="KUrlRequester" name="urlRequester"> | ||
444 | 41 | <property name="mode"> | ||
445 | 42 | <set>KFile::Directory|KFile::ExistingOnly</set> | ||
446 | 43 | </property> | ||
447 | 44 | </widget> | ||
448 | 45 | </item> | ||
449 | 46 | <item row="2" column="1"> | ||
450 | 47 | <widget class="QLineEdit" name="titleLineEdit"/> | ||
451 | 48 | </item> | ||
452 | 49 | <item row="2" column="0"> | ||
453 | 50 | <widget class="QLabel" name="label"> | ||
454 | 51 | <property name="text"> | ||
455 | 52 | <string>Title:</string> | ||
456 | 53 | </property> | ||
457 | 54 | <property name="buddy"> | ||
458 | 55 | <cstring>titleLineEdit</cstring> | ||
459 | 56 | </property> | ||
460 | 57 | </widget> | ||
461 | 58 | </item> | ||
462 | 59 | <item row="3" column="1"> | ||
463 | 60 | <widget class="QLabel" name="titleHelpLabel"> | ||
464 | 61 | <property name="sizePolicy"> | ||
465 | 62 | <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> | ||
466 | 63 | <horstretch>0</horstretch> | ||
467 | 64 | <verstretch>0</verstretch> | ||
468 | 65 | </sizepolicy> | ||
469 | 66 | </property> | ||
470 | 67 | <property name="text"> | ||
471 | 68 | <string>If title is left empty, the folder name will be used</string> | ||
472 | 69 | </property> | ||
473 | 70 | </widget> | ||
474 | 71 | </item> | ||
475 | 72 | </layout> | ||
476 | 73 | </widget> | ||
477 | 74 | <customwidgets> | ||
478 | 75 | <customwidget> | ||
479 | 76 | <class>KUrlRequester</class> | ||
480 | 77 | <extends>QFrame</extends> | ||
481 | 78 | <header>kurlrequester.h</header> | ||
482 | 79 | </customwidget> | ||
483 | 80 | </customwidgets> | ||
484 | 81 | <resources/> | ||
485 | 82 | <connections/> | ||
486 | 83 | </ui> | ||
487 | 84 | 0 | ||
488 | === removed file 'components/dirmodel.cpp' | |||
489 | --- components/dirmodel.cpp 2012-12-18 19:55:12 +0000 | |||
490 | +++ components/dirmodel.cpp 1970-01-01 00:00:00 +0000 | |||
491 | @@ -1,240 +0,0 @@ | |||
492 | 1 | /* | ||
493 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
494 | 3 | |||
495 | 4 | This library is free software; you can redistribute it and/or | ||
496 | 5 | modify it under the terms of the GNU Lesser General Public | ||
497 | 6 | License as published by the Free Software Foundation; either | ||
498 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
499 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
500 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
501 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
502 | 11 | |||
503 | 12 | This library is distributed in the hope that it will be useful, | ||
504 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
505 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
506 | 15 | Lesser General Public License for more details. | ||
507 | 16 | |||
508 | 17 | You should have received a copy of the GNU Lesser General Public | ||
509 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
510 | 19 | */ | ||
511 | 20 | // Self | ||
512 | 21 | #include <dirmodel.h> | ||
513 | 22 | |||
514 | 23 | // Local | ||
515 | 24 | #include <dirconfigurationwidget.h> | ||
516 | 25 | #include <pathmodel.h> | ||
517 | 26 | #include <favoriteplacesmodel.h> | ||
518 | 27 | |||
519 | 28 | // KDE | ||
520 | 29 | #include <KConfigGroup> | ||
521 | 30 | #include <KDebug> | ||
522 | 31 | #include <KDirModel> | ||
523 | 32 | #include <KDirLister> | ||
524 | 33 | |||
525 | 34 | // Qt | ||
526 | 35 | #include <QDir> | ||
527 | 36 | |||
528 | 37 | namespace Homerun | ||
529 | 38 | { | ||
530 | 39 | |||
531 | 40 | static const char *SOURCE_ID = "Dir"; | ||
532 | 41 | |||
533 | 42 | static inline KFileItem itemForIndex(const QModelIndex &index) | ||
534 | 43 | { | ||
535 | 44 | return index.data(KDirModel::FileItemRole).value<KFileItem>(); | ||
536 | 45 | } | ||
537 | 46 | |||
538 | 47 | //- DirModel ------------------------------------------------------ | ||
539 | 48 | QVariantMap DirModel::sourceArguments(const KUrl &rootUrl, const QString &rootName, const KUrl &url) | ||
540 | 49 | { | ||
541 | 50 | QVariantMap args; | ||
542 | 51 | args.insert("rootUrl", rootUrl.url()); | ||
543 | 52 | args.insert("rootName", rootName); | ||
544 | 53 | args.insert("url", url.url()); | ||
545 | 54 | return args; | ||
546 | 55 | } | ||
547 | 56 | |||
548 | 57 | |||
549 | 58 | DirModel::DirModel(QObject *parent) | ||
550 | 59 | : KDirSortFilterProxyModel(parent) | ||
551 | 60 | , m_pathModel(new PathModel(this)) | ||
552 | 61 | { | ||
553 | 62 | setSourceModel(new KDirModel(this)); | ||
554 | 63 | setSortFoldersFirst(true); | ||
555 | 64 | |||
556 | 65 | QHash<int, QByteArray> roles; | ||
557 | 66 | roles.insert(Qt::DisplayRole, "display"); | ||
558 | 67 | roles.insert(Qt::DecorationRole, "decoration"); | ||
559 | 68 | roles.insert(DirModel::FavoriteIdRole, "favoriteId"); | ||
560 | 69 | setRoleNames(roles); | ||
561 | 70 | |||
562 | 71 | dirLister()->setDelayedMimeTypes(true); | ||
563 | 72 | connect(dirLister(), SIGNAL(started(KUrl)), SLOT(emitRunningChanged())); | ||
564 | 73 | connect(dirLister(), SIGNAL(completed()), SLOT(emitRunningChanged())); | ||
565 | 74 | } | ||
566 | 75 | |||
567 | 76 | void DirModel::init(const KUrl &rootUrl, const QString &rootName, const KUrl &url) | ||
568 | 77 | { | ||
569 | 78 | m_rootUrl = rootUrl; | ||
570 | 79 | m_rootName = rootName; | ||
571 | 80 | initPathModel(url); | ||
572 | 81 | dirLister()->openUrl(url); | ||
573 | 82 | } | ||
574 | 83 | |||
575 | 84 | void DirModel::initPathModel(const KUrl &openedUrl) | ||
576 | 85 | { | ||
577 | 86 | QVariantMap args = sourceArguments(m_rootUrl, m_rootName, m_rootUrl); | ||
578 | 87 | m_pathModel->addPath(m_rootName, SOURCE_ID, args); | ||
579 | 88 | |||
580 | 89 | KUrl rootUrl = m_rootUrl; | ||
581 | 90 | // Needed for KUrl::relativeUrl | ||
582 | 91 | rootUrl.adjustPath(KUrl::AddTrailingSlash); | ||
583 | 92 | QString relativePath = KUrl::relativeUrl(rootUrl, openedUrl); | ||
584 | 93 | if (relativePath == "./") { | ||
585 | 94 | return; | ||
586 | 95 | } | ||
587 | 96 | KUrl url = m_rootUrl; | ||
588 | 97 | Q_FOREACH(const QString &token, relativePath.split('/')) { | ||
589 | 98 | if (token.isEmpty()) { | ||
590 | 99 | // Just in case relativePath ends with '/' | ||
591 | 100 | continue; | ||
592 | 101 | } | ||
593 | 102 | url.addPath(token); | ||
594 | 103 | args["url"] = url.url(); | ||
595 | 104 | m_pathModel->addPath(token, SOURCE_ID, args); | ||
596 | 105 | } | ||
597 | 106 | } | ||
598 | 107 | |||
599 | 108 | KDirLister *DirModel::dirLister() const | ||
600 | 109 | { | ||
601 | 110 | return static_cast<KDirModel *>(sourceModel())->dirLister(); | ||
602 | 111 | } | ||
603 | 112 | |||
604 | 113 | QVariant DirModel::data(const QModelIndex &index, int role) const | ||
605 | 114 | { | ||
606 | 115 | if (role != FavoriteIdRole) { | ||
607 | 116 | return QSortFilterProxyModel::data(index, role); | ||
608 | 117 | } | ||
609 | 118 | if (index.row() < 0 || index.row() >= rowCount()) { | ||
610 | 119 | return QVariant(); | ||
611 | 120 | } | ||
612 | 121 | |||
613 | 122 | KFileItem item = itemForIndex(index); | ||
614 | 123 | if (item.isDir()) { | ||
615 | 124 | return FavoritePlacesModel::favoriteIdFromUrl(item.url()); | ||
616 | 125 | } else { | ||
617 | 126 | return QString(); | ||
618 | 127 | } | ||
619 | 128 | } | ||
620 | 129 | |||
621 | 130 | int DirModel::count() const | ||
622 | 131 | { | ||
623 | 132 | return rowCount(QModelIndex()); | ||
624 | 133 | } | ||
625 | 134 | |||
626 | 135 | QString DirModel::name() const | ||
627 | 136 | { | ||
628 | 137 | return m_rootName; | ||
629 | 138 | } | ||
630 | 139 | |||
631 | 140 | bool DirModel::running() const | ||
632 | 141 | { | ||
633 | 142 | return !dirLister()->isFinished(); | ||
634 | 143 | } | ||
635 | 144 | |||
636 | 145 | PathModel *DirModel::pathModel() const | ||
637 | 146 | { | ||
638 | 147 | return m_pathModel; | ||
639 | 148 | } | ||
640 | 149 | |||
641 | 150 | QString DirModel::query() const | ||
642 | 151 | { | ||
643 | 152 | return filterRegExp().pattern(); | ||
644 | 153 | } | ||
645 | 154 | |||
646 | 155 | void DirModel::setQuery(const QString &value) | ||
647 | 156 | { | ||
648 | 157 | if (value == query()) { | ||
649 | 158 | return; | ||
650 | 159 | } | ||
651 | 160 | setFilterRegExp(QRegExp(value, Qt::CaseInsensitive)); | ||
652 | 161 | queryChanged(value); | ||
653 | 162 | } | ||
654 | 163 | |||
655 | 164 | void DirModel::emitRunningChanged() | ||
656 | 165 | { | ||
657 | 166 | runningChanged(running()); | ||
658 | 167 | } | ||
659 | 168 | |||
660 | 169 | bool DirModel::trigger(int row) | ||
661 | 170 | { | ||
662 | 171 | bool closed = false; | ||
663 | 172 | QModelIndex idx = index(row, 0); | ||
664 | 173 | |||
665 | 174 | KFileItem item = itemForIndex(idx); | ||
666 | 175 | if (item.isDir()) { | ||
667 | 176 | openSourceRequested(SOURCE_ID, sourceArguments(m_rootUrl, m_rootName, item.url())); | ||
668 | 177 | } else { | ||
669 | 178 | item.run(); | ||
670 | 179 | closed = true; | ||
671 | 180 | } | ||
672 | 181 | return closed; | ||
673 | 182 | } | ||
674 | 183 | |||
675 | 184 | //- DirSource ------------------------------------------------------- | ||
676 | 185 | DirSource::DirSource(QObject *parent) | ||
677 | 186 | : AbstractSource(parent) | ||
678 | 187 | {} | ||
679 | 188 | |||
680 | 189 | QAbstractItemModel *DirSource::createModelFromArguments(const QVariantMap &args) | ||
681 | 190 | { | ||
682 | 191 | KUrl rootUrl = args.value("rootUrl").toString(); | ||
683 | 192 | QString rootName = args.value("rootName").toString(); | ||
684 | 193 | KUrl url = args.value("url").toString(); | ||
685 | 194 | return createModel(rootUrl, rootName, url); | ||
686 | 195 | } | ||
687 | 196 | |||
688 | 197 | QAbstractItemModel *DirSource::createModelFromConfigGroup(const KConfigGroup &group) | ||
689 | 198 | { | ||
690 | 199 | KUrl rootUrl = group.readPathEntry("rootUrl", QDir::homePath()); | ||
691 | 200 | QString rootName = group.readEntry("rootName", QString()); | ||
692 | 201 | return createModel(rootUrl, rootName, KUrl()); | ||
693 | 202 | } | ||
694 | 203 | |||
695 | 204 | QAbstractItemModel *DirSource::createModel(const KUrl &rootUrl_, const QString &rootName_, const KUrl &url_) | ||
696 | 205 | { | ||
697 | 206 | KUrl rootUrl = rootUrl_; | ||
698 | 207 | QString rootName = rootName_; | ||
699 | 208 | KUrl url = url_; | ||
700 | 209 | if (!rootUrl.isValid()) { | ||
701 | 210 | rootUrl = KUrl::fromPath(QDir::homePath()); | ||
702 | 211 | } | ||
703 | 212 | |||
704 | 213 | if (rootName.isEmpty()) { | ||
705 | 214 | rootName = rootUrl.fileName(); | ||
706 | 215 | if (rootName.isEmpty()) { | ||
707 | 216 | rootName = rootUrl.prettyUrl(); | ||
708 | 217 | } | ||
709 | 218 | } | ||
710 | 219 | if (!url.isValid()) { | ||
711 | 220 | url = rootUrl; | ||
712 | 221 | } | ||
713 | 222 | |||
714 | 223 | DirModel *model = new DirModel; | ||
715 | 224 | model->init(rootUrl, rootName, url); | ||
716 | 225 | return model; | ||
717 | 226 | } | ||
718 | 227 | |||
719 | 228 | bool DirSource::isConfigurable() const | ||
720 | 229 | { | ||
721 | 230 | return true; | ||
722 | 231 | } | ||
723 | 232 | |||
724 | 233 | SourceConfigurationWidget *DirSource::createConfigurationWidget(const KConfigGroup &group) | ||
725 | 234 | { | ||
726 | 235 | return new DirConfigurationWidget(group); | ||
727 | 236 | } | ||
728 | 237 | |||
729 | 238 | } // namespace Homerun | ||
730 | 239 | |||
731 | 240 | #include <dirmodel.moc> | ||
732 | 241 | 0 | ||
733 | === removed file 'components/dirmodel.h' | |||
734 | --- components/dirmodel.h 2012-11-14 21:30:06 +0000 | |||
735 | +++ components/dirmodel.h 1970-01-01 00:00:00 +0000 | |||
736 | @@ -1,111 +0,0 @@ | |||
737 | 1 | /* | ||
738 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
739 | 3 | |||
740 | 4 | This library is free software; you can redistribute it and/or | ||
741 | 5 | modify it under the terms of the GNU Lesser General Public | ||
742 | 6 | License as published by the Free Software Foundation; either | ||
743 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
744 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
745 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
746 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
747 | 11 | |||
748 | 12 | This library is distributed in the hope that it will be useful, | ||
749 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
750 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
751 | 15 | Lesser General Public License for more details. | ||
752 | 16 | |||
753 | 17 | You should have received a copy of the GNU Lesser General Public | ||
754 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
755 | 19 | */ | ||
756 | 20 | #ifndef DIRMODEL_H | ||
757 | 21 | #define DIRMODEL_H | ||
758 | 22 | |||
759 | 23 | // Local | ||
760 | 24 | #include <abstractsource.h> | ||
761 | 25 | |||
762 | 26 | // Qt | ||
763 | 27 | |||
764 | 28 | // KDE | ||
765 | 29 | #include <KDirSortFilterProxyModel> | ||
766 | 30 | #include <KUrl> | ||
767 | 31 | |||
768 | 32 | class KDirLister; | ||
769 | 33 | |||
770 | 34 | namespace Homerun { | ||
771 | 35 | |||
772 | 36 | class PathModel; | ||
773 | 37 | |||
774 | 38 | /** | ||
775 | 39 | * Internal | ||
776 | 40 | */ | ||
777 | 41 | class DirModel : public KDirSortFilterProxyModel | ||
778 | 42 | { | ||
779 | 43 | Q_OBJECT | ||
780 | 44 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
781 | 45 | Q_PROPERTY(QString name READ name CONSTANT) | ||
782 | 46 | |||
783 | 47 | Q_PROPERTY(bool running READ running NOTIFY runningChanged) | ||
784 | 48 | Q_PROPERTY(QObject *pathModel READ pathModel CONSTANT) | ||
785 | 49 | Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) | ||
786 | 50 | public: | ||
787 | 51 | explicit DirModel(QObject *parent = 0); | ||
788 | 52 | |||
789 | 53 | void init(const KUrl &rootUrl, const QString &rootName, const KUrl &url); | ||
790 | 54 | |||
791 | 55 | enum { | ||
792 | 56 | FavoriteIdRole = Qt::UserRole + 1, | ||
793 | 57 | }; | ||
794 | 58 | |||
795 | 59 | Q_INVOKABLE bool trigger(int row); | ||
796 | 60 | |||
797 | 61 | KDirLister *dirLister() const; | ||
798 | 62 | |||
799 | 63 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; // reimp | ||
800 | 64 | |||
801 | 65 | PathModel *pathModel() const; | ||
802 | 66 | |||
803 | 67 | int count() const; | ||
804 | 68 | |||
805 | 69 | QString name() const; | ||
806 | 70 | |||
807 | 71 | bool running() const; | ||
808 | 72 | |||
809 | 73 | QString query() const; | ||
810 | 74 | |||
811 | 75 | void setQuery(const QString &query); | ||
812 | 76 | |||
813 | 77 | static QVariantMap sourceArguments(const KUrl &rootUrl, const QString &rootName, const KUrl &url); | ||
814 | 78 | |||
815 | 79 | Q_SIGNALS: | ||
816 | 80 | void countChanged(); | ||
817 | 81 | void runningChanged(bool); | ||
818 | 82 | void openSourceRequested(const QString &sourceId, const QVariantMap &sourceArguments); | ||
819 | 83 | void queryChanged(const QString &); | ||
820 | 84 | |||
821 | 85 | private Q_SLOTS: | ||
822 | 86 | void emitRunningChanged(); | ||
823 | 87 | |||
824 | 88 | private: | ||
825 | 89 | PathModel *m_pathModel; | ||
826 | 90 | KUrl m_rootUrl; | ||
827 | 91 | QString m_rootName; | ||
828 | 92 | |||
829 | 93 | void initPathModel(const KUrl &url); | ||
830 | 94 | }; | ||
831 | 95 | |||
832 | 96 | class DirSource : public AbstractSource | ||
833 | 97 | { | ||
834 | 98 | public: | ||
835 | 99 | DirSource(QObject *parent); | ||
836 | 100 | QAbstractItemModel *createModelFromConfigGroup(const KConfigGroup &group); | ||
837 | 101 | QAbstractItemModel *createModelFromArguments(const QVariantMap &args); | ||
838 | 102 | bool isConfigurable() const; | ||
839 | 103 | SourceConfigurationWidget *createConfigurationWidget(const KConfigGroup &group); | ||
840 | 104 | |||
841 | 105 | private: | ||
842 | 106 | QAbstractItemModel *createModel(const KUrl &rootUrl, const QString &rootName, const KUrl &url); | ||
843 | 107 | }; | ||
844 | 108 | |||
845 | 109 | } // namespace Homerun | ||
846 | 110 | |||
847 | 111 | #endif /* DIRMODEL_H */ | ||
848 | 112 | 0 | ||
849 | === removed file 'components/favoriteappsmodel.cpp' | |||
850 | --- components/favoriteappsmodel.cpp 2012-11-14 21:30:06 +0000 | |||
851 | +++ components/favoriteappsmodel.cpp 1970-01-01 00:00:00 +0000 | |||
852 | @@ -1,215 +0,0 @@ | |||
853 | 1 | /* | ||
854 | 2 | Copyright 2009 Ivan Cukic <ivan.cukic+kde@gmail.com> | ||
855 | 3 | Copyright 2010 Marco Martin <notmart@gmail.com> | ||
856 | 4 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
857 | 5 | |||
858 | 6 | This library is free software; you can redistribute it and/or | ||
859 | 7 | modify it under the terms of the GNU Library General Public | ||
860 | 8 | License as published by the Free Software Foundation; either | ||
861 | 9 | version 2 of the License, or (at your option) any later version. | ||
862 | 10 | |||
863 | 11 | This library is distributed in the hope that it will be useful, | ||
864 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
865 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
866 | 14 | Library General Public License for more details. | ||
867 | 15 | |||
868 | 16 | You should have received a copy of the GNU Library General Public License | ||
869 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
870 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
871 | 19 | Boston, MA 02110-1301, USA. | ||
872 | 20 | */ | ||
873 | 21 | |||
874 | 22 | // Own | ||
875 | 23 | #include "favoriteappsmodel.h" | ||
876 | 24 | |||
877 | 25 | // Qt | ||
878 | 26 | |||
879 | 27 | // KDE | ||
880 | 28 | #include <KDebug> | ||
881 | 29 | #include <KIcon> | ||
882 | 30 | #include <KConfigGroup> | ||
883 | 31 | #include <KLocale> | ||
884 | 32 | #include <KRun> | ||
885 | 33 | #include <KService> | ||
886 | 34 | |||
887 | 35 | namespace Homerun { | ||
888 | 36 | |||
889 | 37 | static QString serviceIdFromFavoriteId(const QString &favoriteId) | ||
890 | 38 | { | ||
891 | 39 | if (!favoriteId.startsWith("app:")) { | ||
892 | 40 | kWarning() << "Wrong favoriteId" << favoriteId; | ||
893 | 41 | return QString(); | ||
894 | 42 | } | ||
895 | 43 | return favoriteId.mid(4); | ||
896 | 44 | } | ||
897 | 45 | |||
898 | 46 | FavoriteAppsModel::FavoriteAppsModel(QObject *parent) | ||
899 | 47 | : QAbstractListModel(parent) | ||
900 | 48 | { | ||
901 | 49 | QHash<int, QByteArray> roles; | ||
902 | 50 | roles.insert(Qt::DisplayRole, "display"); | ||
903 | 51 | roles.insert(Qt::DecorationRole, "decoration"); | ||
904 | 52 | roles.insert(FavoriteIdRole, "favoriteId"); | ||
905 | 53 | setRoleNames(roles); | ||
906 | 54 | setConfig(KSharedConfig::openConfig("homerunrc")); | ||
907 | 55 | } | ||
908 | 56 | |||
909 | 57 | FavoriteAppsModel::~FavoriteAppsModel() | ||
910 | 58 | { | ||
911 | 59 | } | ||
912 | 60 | |||
913 | 61 | void FavoriteAppsModel::setConfig(const KSharedConfig::Ptr &ptr) | ||
914 | 62 | { | ||
915 | 63 | m_config = ptr; | ||
916 | 64 | |||
917 | 65 | KConfigGroup baseGroup(m_config, "favorites"); | ||
918 | 66 | |||
919 | 67 | // get all the favorites | ||
920 | 68 | QMap<int, KService::Ptr> favoriteMap; | ||
921 | 69 | foreach (const QString &favoriteGroup, baseGroup.groupList()) { | ||
922 | 70 | if (favoriteGroup.startsWith("favorite-")) { | ||
923 | 71 | KConfigGroup favoriteConfig(&baseGroup, favoriteGroup); | ||
924 | 72 | int rank = favoriteGroup.split("-").last().toInt(); | ||
925 | 73 | QString id = favoriteConfig.readEntry("serviceId"); | ||
926 | 74 | KService::Ptr service = KService::serviceByStorageId(id); | ||
927 | 75 | if (!service.isNull()) { | ||
928 | 76 | favoriteMap.insert(rank, service); | ||
929 | 77 | } | ||
930 | 78 | } | ||
931 | 79 | } | ||
932 | 80 | |||
933 | 81 | beginResetModel(); | ||
934 | 82 | m_favoriteList.clear(); | ||
935 | 83 | auto it = favoriteMap.constBegin(), end = favoriteMap.constEnd(); | ||
936 | 84 | for (; it != end; ++it) { | ||
937 | 85 | FavoriteInfo info = { it.key(), it.value() }; | ||
938 | 86 | m_favoriteList << info; | ||
939 | 87 | } | ||
940 | 88 | endResetModel(); | ||
941 | 89 | countChanged(); | ||
942 | 90 | } | ||
943 | 91 | |||
944 | 92 | void FavoriteAppsModel::addFavorite(const QString &favoriteId) | ||
945 | 93 | { | ||
946 | 94 | QString serviceId = serviceIdFromFavoriteId(favoriteId); | ||
947 | 95 | if (serviceId.isEmpty()) { | ||
948 | 96 | return; | ||
949 | 97 | } | ||
950 | 98 | KService::Ptr service = KService::serviceByStorageId(serviceId); | ||
951 | 99 | if (service.isNull()) { | ||
952 | 100 | kWarning() << "Could not find a service for" << serviceId; | ||
953 | 101 | return; | ||
954 | 102 | } | ||
955 | 103 | int rank; | ||
956 | 104 | if (!m_favoriteList.isEmpty()) { | ||
957 | 105 | rank = m_favoriteList.last().rank + 1; | ||
958 | 106 | } else { | ||
959 | 107 | rank = 0; | ||
960 | 108 | } | ||
961 | 109 | FavoriteInfo info = { rank, service }; | ||
962 | 110 | |||
963 | 111 | int row = m_favoriteList.count(); | ||
964 | 112 | beginInsertRows(QModelIndex(), row, row); | ||
965 | 113 | m_favoriteList << info; | ||
966 | 114 | endInsertRows(); | ||
967 | 115 | countChanged(); | ||
968 | 116 | |||
969 | 117 | KConfigGroup baseGroup(m_config, "favorites"); | ||
970 | 118 | KConfigGroup group(&baseGroup, QString("favorite-%1").arg(rank)); | ||
971 | 119 | group.writeEntry("serviceId", serviceId); | ||
972 | 120 | baseGroup.sync(); | ||
973 | 121 | } | ||
974 | 122 | |||
975 | 123 | void FavoriteAppsModel::removeFavorite(const QString &favoriteId) | ||
976 | 124 | { | ||
977 | 125 | int row = rowForFavoriteId(favoriteId); | ||
978 | 126 | if (row == -1) { | ||
979 | 127 | kWarning() << "Could not find favorite" << favoriteId; | ||
980 | 128 | return; | ||
981 | 129 | } | ||
982 | 130 | beginRemoveRows(QModelIndex(), row, row); | ||
983 | 131 | FavoriteInfo info = m_favoriteList.takeAt(row); | ||
984 | 132 | endRemoveRows(); | ||
985 | 133 | countChanged(); | ||
986 | 134 | |||
987 | 135 | KConfigGroup baseGroup(m_config, "favorites"); | ||
988 | 136 | KConfigGroup group(&baseGroup, QString("favorite-%1").arg(info.rank)); | ||
989 | 137 | group.deleteGroup(); | ||
990 | 138 | baseGroup.sync(); | ||
991 | 139 | } | ||
992 | 140 | |||
993 | 141 | bool FavoriteAppsModel::isFavorite(const QString &favoriteId) const | ||
994 | 142 | { | ||
995 | 143 | return rowForFavoriteId(favoriteId) != -1; | ||
996 | 144 | } | ||
997 | 145 | |||
998 | 146 | int FavoriteAppsModel::rowForFavoriteId(const QString& favoriteId) const | ||
999 | 147 | { | ||
1000 | 148 | QString serviceId = serviceIdFromFavoriteId(favoriteId); | ||
1001 | 149 | if (serviceId.isEmpty()) { | ||
1002 | 150 | return -1; | ||
1003 | 151 | } | ||
1004 | 152 | |||
1005 | 153 | for (int row = m_favoriteList.count() - 1; row >= 0; --row) { | ||
1006 | 154 | const FavoriteInfo& info = m_favoriteList.at(row); | ||
1007 | 155 | if (info.service->storageId() == serviceId) { | ||
1008 | 156 | return row; | ||
1009 | 157 | } | ||
1010 | 158 | } | ||
1011 | 159 | return -1; | ||
1012 | 160 | } | ||
1013 | 161 | |||
1014 | 162 | int FavoriteAppsModel::count() const | ||
1015 | 163 | { | ||
1016 | 164 | return m_favoriteList.count(); | ||
1017 | 165 | } | ||
1018 | 166 | |||
1019 | 167 | QString FavoriteAppsModel::name() const | ||
1020 | 168 | { | ||
1021 | 169 | return i18n("Favorite Applications"); | ||
1022 | 170 | } | ||
1023 | 171 | |||
1024 | 172 | QString FavoriteAppsModel::favoritePrefix() const | ||
1025 | 173 | { | ||
1026 | 174 | return "app"; | ||
1027 | 175 | } | ||
1028 | 176 | |||
1029 | 177 | int FavoriteAppsModel::rowCount(const QModelIndex &index) const | ||
1030 | 178 | { | ||
1031 | 179 | if (index.isValid()) { | ||
1032 | 180 | return 0; | ||
1033 | 181 | } | ||
1034 | 182 | return m_favoriteList.count(); | ||
1035 | 183 | } | ||
1036 | 184 | |||
1037 | 185 | QVariant FavoriteAppsModel::data(const QModelIndex &index, int role) const | ||
1038 | 186 | { | ||
1039 | 187 | KService::Ptr service = m_favoriteList.value(index.row()).service; | ||
1040 | 188 | if (service.isNull()) { | ||
1041 | 189 | return QVariant(); | ||
1042 | 190 | } | ||
1043 | 191 | if (role == Qt::DisplayRole) { | ||
1044 | 192 | return service->name(); | ||
1045 | 193 | } else if (role == Qt::DecorationRole) { | ||
1046 | 194 | return KIcon(service->icon()); | ||
1047 | 195 | } else if (role == FavoriteIdRole) { | ||
1048 | 196 | return QVariant("app:" + service->storageId()); | ||
1049 | 197 | } else { | ||
1050 | 198 | kWarning() << "Unhandled role" << role; | ||
1051 | 199 | return QVariant(); | ||
1052 | 200 | } | ||
1053 | 201 | } | ||
1054 | 202 | |||
1055 | 203 | bool FavoriteAppsModel::trigger(int row) | ||
1056 | 204 | { | ||
1057 | 205 | KService::Ptr service = m_favoriteList.value(row).service; | ||
1058 | 206 | if (service.isNull()) { | ||
1059 | 207 | kWarning() << "Invalid row"; | ||
1060 | 208 | return false; | ||
1061 | 209 | } | ||
1062 | 210 | return KRun::run(*service, KUrl::List(), 0); | ||
1063 | 211 | } | ||
1064 | 212 | |||
1065 | 213 | } // namespace Homerun | ||
1066 | 214 | |||
1067 | 215 | #include "favoriteappsmodel.moc" | ||
1068 | 216 | 0 | ||
1069 | === removed file 'components/favoriteappsmodel.h' | |||
1070 | --- components/favoriteappsmodel.h 2012-11-14 21:30:06 +0000 | |||
1071 | +++ components/favoriteappsmodel.h 1970-01-01 00:00:00 +0000 | |||
1072 | @@ -1,81 +0,0 @@ | |||
1073 | 1 | /* | ||
1074 | 2 | Copyright 2009 Ivan Cukic <ivan.cukic+kde@gmail.com> | ||
1075 | 3 | Copyright 2010 Marco Martin <notmart@gmail.com> | ||
1076 | 4 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
1077 | 5 | |||
1078 | 6 | This library is free software; you can redistribute it and/or | ||
1079 | 7 | modify it under the terms of the GNU Library General Public | ||
1080 | 8 | License as published by the Free Software Foundation; either | ||
1081 | 9 | version 2 of the License, or (at your option) any later version. | ||
1082 | 10 | |||
1083 | 11 | This library is distributed in the hope that it will be useful, | ||
1084 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1085 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1086 | 14 | Library General Public License for more details. | ||
1087 | 15 | |||
1088 | 16 | You should have received a copy of the GNU Library General Public License | ||
1089 | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
1090 | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1091 | 19 | Boston, MA 02110-1301, USA. | ||
1092 | 20 | */ | ||
1093 | 21 | |||
1094 | 22 | #ifndef FAVORITEAPPSMODEL_H | ||
1095 | 23 | #define FAVORITEAPPSMODEL_H | ||
1096 | 24 | |||
1097 | 25 | #include <QAbstractListModel> | ||
1098 | 26 | |||
1099 | 27 | #include <KService> | ||
1100 | 28 | #include <KSharedConfig> | ||
1101 | 29 | |||
1102 | 30 | namespace Homerun { | ||
1103 | 31 | |||
1104 | 32 | struct FavoriteInfo | ||
1105 | 33 | { | ||
1106 | 34 | int rank; | ||
1107 | 35 | KService::Ptr service; | ||
1108 | 36 | }; | ||
1109 | 37 | |||
1110 | 38 | class FavoriteAppsModel : public QAbstractListModel | ||
1111 | 39 | { | ||
1112 | 40 | Q_OBJECT | ||
1113 | 41 | Q_PROPERTY(QString name READ name CONSTANT) | ||
1114 | 42 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
1115 | 43 | |||
1116 | 44 | Q_PROPERTY(QString favoritePrefix READ favoritePrefix CONSTANT) | ||
1117 | 45 | |||
1118 | 46 | public: | ||
1119 | 47 | FavoriteAppsModel(QObject *parent = 0); | ||
1120 | 48 | ~FavoriteAppsModel(); | ||
1121 | 49 | |||
1122 | 50 | enum { | ||
1123 | 51 | FavoriteIdRole = Qt::UserRole + 1 | ||
1124 | 52 | }; | ||
1125 | 53 | |||
1126 | 54 | int count() const; | ||
1127 | 55 | QString name() const; | ||
1128 | 56 | QString favoritePrefix() const; | ||
1129 | 57 | |||
1130 | 58 | void setConfig(const KSharedConfig::Ptr &); | ||
1131 | 59 | |||
1132 | 60 | int rowCount(const QModelIndex & = QModelIndex()) const; | ||
1133 | 61 | QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const; | ||
1134 | 62 | |||
1135 | 63 | Q_INVOKABLE bool isFavorite(const QString &favoriteId) const; | ||
1136 | 64 | Q_INVOKABLE void addFavorite(const QString &favoriteId); | ||
1137 | 65 | Q_INVOKABLE void removeFavorite(const QString &favoriteId); | ||
1138 | 66 | |||
1139 | 67 | Q_INVOKABLE bool trigger(int row); | ||
1140 | 68 | |||
1141 | 69 | Q_SIGNALS: | ||
1142 | 70 | void countChanged(); | ||
1143 | 71 | |||
1144 | 72 | private: | ||
1145 | 73 | KSharedConfig::Ptr m_config; | ||
1146 | 74 | QList<FavoriteInfo> m_favoriteList; | ||
1147 | 75 | |||
1148 | 76 | int rowForFavoriteId(const QString &favoriteId) const; | ||
1149 | 77 | }; | ||
1150 | 78 | |||
1151 | 79 | } // namespace Homerun | ||
1152 | 80 | |||
1153 | 81 | #endif // FAVORITEAPPSMODEL_H | ||
1154 | 82 | 0 | ||
1155 | === removed file 'components/favoriteplacesmodel.cpp' | |||
1156 | --- components/favoriteplacesmodel.cpp 2012-11-14 21:30:06 +0000 | |||
1157 | +++ components/favoriteplacesmodel.cpp 1970-01-01 00:00:00 +0000 | |||
1158 | @@ -1,138 +0,0 @@ | |||
1159 | 1 | /* | ||
1160 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
1161 | 3 | |||
1162 | 4 | This library is free software; you can redistribute it and/or | ||
1163 | 5 | modify it under the terms of the GNU Lesser General Public | ||
1164 | 6 | License as published by the Free Software Foundation; either | ||
1165 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
1166 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
1167 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
1168 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
1169 | 11 | |||
1170 | 12 | This library is distributed in the hope that it will be useful, | ||
1171 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1172 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1173 | 15 | Lesser General Public License for more details. | ||
1174 | 16 | |||
1175 | 17 | You should have received a copy of the GNU Lesser General Public | ||
1176 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
1177 | 19 | */ | ||
1178 | 20 | #include "favoriteplacesmodel.h" | ||
1179 | 21 | |||
1180 | 22 | // Local | ||
1181 | 23 | #include <dirmodel.h> | ||
1182 | 24 | |||
1183 | 25 | // KDE | ||
1184 | 26 | #include <KDebug> | ||
1185 | 27 | #include <KLocale> | ||
1186 | 28 | |||
1187 | 29 | // Qt | ||
1188 | 30 | |||
1189 | 31 | namespace Homerun { | ||
1190 | 32 | |||
1191 | 33 | KUrl FavoritePlacesModel::urlFromFavoriteId(const QString &favoriteId) | ||
1192 | 34 | { | ||
1193 | 35 | if (!favoriteId.startsWith("place:")) { | ||
1194 | 36 | kWarning() << "Wrong favoriteId" << favoriteId; | ||
1195 | 37 | return QString(); | ||
1196 | 38 | } | ||
1197 | 39 | return KUrl(favoriteId.mid(6)); | ||
1198 | 40 | } | ||
1199 | 41 | |||
1200 | 42 | QString FavoritePlacesModel::favoriteIdFromUrl(const KUrl &url) | ||
1201 | 43 | { | ||
1202 | 44 | return "place:" + url.url(); | ||
1203 | 45 | } | ||
1204 | 46 | |||
1205 | 47 | //- FavoritePlacesModel ------------------------------------------------ | ||
1206 | 48 | FavoritePlacesModel::FavoritePlacesModel(QObject *parent) | ||
1207 | 49 | : KFilePlacesModel(parent) | ||
1208 | 50 | { | ||
1209 | 51 | QHash<int, QByteArray> roles; | ||
1210 | 52 | roles.insert(Qt::DisplayRole, "display"); | ||
1211 | 53 | roles.insert(Qt::DecorationRole, "decoration"); | ||
1212 | 54 | roles.insert(FavoritePlacesModel::FavoriteIdRole, "favoriteId"); | ||
1213 | 55 | setRoleNames(roles); | ||
1214 | 56 | } | ||
1215 | 57 | |||
1216 | 58 | QString FavoritePlacesModel::favoritePrefix() const | ||
1217 | 59 | { | ||
1218 | 60 | return "place"; | ||
1219 | 61 | } | ||
1220 | 62 | |||
1221 | 63 | bool FavoritePlacesModel::isFavorite(const QString &favoriteId) const | ||
1222 | 64 | { | ||
1223 | 65 | return indexForFavoriteId(favoriteId).isValid(); | ||
1224 | 66 | } | ||
1225 | 67 | |||
1226 | 68 | void FavoritePlacesModel::addFavorite(const QString &favoriteId) | ||
1227 | 69 | { | ||
1228 | 70 | KUrl favoriteUrl = urlFromFavoriteId(favoriteId); | ||
1229 | 71 | if (favoriteUrl.isEmpty()) { | ||
1230 | 72 | return; | ||
1231 | 73 | } | ||
1232 | 74 | addPlace(favoriteUrl.fileName(), favoriteUrl); | ||
1233 | 75 | } | ||
1234 | 76 | |||
1235 | 77 | void FavoritePlacesModel::removeFavorite(const QString &favoriteId) | ||
1236 | 78 | { | ||
1237 | 79 | QModelIndex index = indexForFavoriteId(favoriteId); | ||
1238 | 80 | if (!index.isValid()) { | ||
1239 | 81 | kWarning() << "No favorite place for" << favoriteId; | ||
1240 | 82 | return; | ||
1241 | 83 | } | ||
1242 | 84 | removePlace(index); | ||
1243 | 85 | } | ||
1244 | 86 | |||
1245 | 87 | QModelIndex FavoritePlacesModel::indexForFavoriteId(const QString &favoriteId) const | ||
1246 | 88 | { | ||
1247 | 89 | KUrl favoriteUrl = urlFromFavoriteId(favoriteId); | ||
1248 | 90 | if (favoriteUrl.isEmpty()) { | ||
1249 | 91 | return QModelIndex(); | ||
1250 | 92 | } | ||
1251 | 93 | for (int row = rowCount() - 1; row >= 0; --row) { | ||
1252 | 94 | QModelIndex idx = index(row, 0); | ||
1253 | 95 | if (url(idx).equals(favoriteUrl, KUrl::CompareWithoutTrailingSlash)) { | ||
1254 | 96 | return idx; | ||
1255 | 97 | } | ||
1256 | 98 | } | ||
1257 | 99 | return QModelIndex(); | ||
1258 | 100 | } | ||
1259 | 101 | |||
1260 | 102 | QVariant FavoritePlacesModel::data(const QModelIndex &index, int role) const | ||
1261 | 103 | { | ||
1262 | 104 | if (role != FavoriteIdRole) { | ||
1263 | 105 | return KFilePlacesModel::data(index, role); | ||
1264 | 106 | } | ||
1265 | 107 | |||
1266 | 108 | if (index.row() < 0 || index.row() >= rowCount()) { | ||
1267 | 109 | return QVariant(); | ||
1268 | 110 | } | ||
1269 | 111 | return QVariant(favoriteIdFromUrl(url(index))); | ||
1270 | 112 | } | ||
1271 | 113 | |||
1272 | 114 | bool FavoritePlacesModel::trigger(int row) | ||
1273 | 115 | { | ||
1274 | 116 | QModelIndex idx = index(row, 0); | ||
1275 | 117 | |||
1276 | 118 | KUrl theUrl = idx.data(KFilePlacesModel::UrlRole).value<QUrl>(); | ||
1277 | 119 | theUrl.adjustPath(KUrl::AddTrailingSlash); | ||
1278 | 120 | QString rootName = idx.data(Qt::DisplayRole).toString(); | ||
1279 | 121 | openSourceRequested("Dir", DirModel::sourceArguments(theUrl, rootName, theUrl)); | ||
1280 | 122 | |||
1281 | 123 | return false; | ||
1282 | 124 | } | ||
1283 | 125 | |||
1284 | 126 | QString FavoritePlacesModel::name() const | ||
1285 | 127 | { | ||
1286 | 128 | return i18n("Favorite Places"); | ||
1287 | 129 | } | ||
1288 | 130 | |||
1289 | 131 | int FavoritePlacesModel::count() const | ||
1290 | 132 | { | ||
1291 | 133 | return rowCount(QModelIndex()); | ||
1292 | 134 | } | ||
1293 | 135 | |||
1294 | 136 | } // namespace Homerun | ||
1295 | 137 | |||
1296 | 138 | #include "favoriteplacesmodel.moc" | ||
1297 | 139 | 0 | ||
1298 | === removed file 'components/favoriteplacesmodel.h' | |||
1299 | --- components/favoriteplacesmodel.h 2012-11-14 21:30:06 +0000 | |||
1300 | +++ components/favoriteplacesmodel.h 1970-01-01 00:00:00 +0000 | |||
1301 | @@ -1,75 +0,0 @@ | |||
1302 | 1 | /* | ||
1303 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
1304 | 3 | |||
1305 | 4 | This library is free software; you can redistribute it and/or | ||
1306 | 5 | modify it under the terms of the GNU Lesser General Public | ||
1307 | 6 | License as published by the Free Software Foundation; either | ||
1308 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
1309 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
1310 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
1311 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
1312 | 11 | |||
1313 | 12 | This library is distributed in the hope that it will be useful, | ||
1314 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1315 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1316 | 15 | Lesser General Public License for more details. | ||
1317 | 16 | |||
1318 | 17 | You should have received a copy of the GNU Lesser General Public | ||
1319 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
1320 | 19 | */ | ||
1321 | 20 | #ifndef PLACESMODEL_H | ||
1322 | 21 | #define PLACESMODEL_H | ||
1323 | 22 | |||
1324 | 23 | // Local | ||
1325 | 24 | |||
1326 | 25 | // Qt | ||
1327 | 26 | |||
1328 | 27 | // KDE | ||
1329 | 28 | #include <KFilePlacesModel> | ||
1330 | 29 | |||
1331 | 30 | namespace Homerun { | ||
1332 | 31 | |||
1333 | 32 | /** | ||
1334 | 33 | * Adapts KFilePlacesModel to make it usable as a Homerun favorite model | ||
1335 | 34 | */ | ||
1336 | 35 | class FavoritePlacesModel : public KFilePlacesModel | ||
1337 | 36 | { | ||
1338 | 37 | Q_OBJECT | ||
1339 | 38 | Q_PROPERTY(QString favoritePrefix READ favoritePrefix CONSTANT) | ||
1340 | 39 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
1341 | 40 | Q_PROPERTY(QString name READ name CONSTANT) | ||
1342 | 41 | |||
1343 | 42 | public: | ||
1344 | 43 | enum { | ||
1345 | 44 | FavoriteIdRole = Qt::UserRole + 1, | ||
1346 | 45 | }; | ||
1347 | 46 | |||
1348 | 47 | FavoritePlacesModel(QObject *parent = 0); | ||
1349 | 48 | |||
1350 | 49 | Q_INVOKABLE bool isFavorite(const QString &favoriteId) const; | ||
1351 | 50 | Q_INVOKABLE void addFavorite(const QString &favoriteId); | ||
1352 | 51 | Q_INVOKABLE void removeFavorite(const QString &favoriteId); | ||
1353 | 52 | Q_INVOKABLE bool trigger(int row); | ||
1354 | 53 | |||
1355 | 54 | QString favoritePrefix() const; | ||
1356 | 55 | |||
1357 | 56 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; // reimp | ||
1358 | 57 | |||
1359 | 58 | QString name() const; | ||
1360 | 59 | |||
1361 | 60 | int count() const; | ||
1362 | 61 | |||
1363 | 62 | static KUrl urlFromFavoriteId(const QString &favoriteId); | ||
1364 | 63 | static QString favoriteIdFromUrl(const KUrl &url); | ||
1365 | 64 | |||
1366 | 65 | Q_SIGNALS: | ||
1367 | 66 | void openSourceRequested(const QString &sourceId, const QVariantMap &sourceArguments); | ||
1368 | 67 | void countChanged(); | ||
1369 | 68 | |||
1370 | 69 | private: | ||
1371 | 70 | QModelIndex indexForFavoriteId(const QString &favoriteId) const; | ||
1372 | 71 | }; | ||
1373 | 72 | |||
1374 | 73 | } // namespace Homerun | ||
1375 | 74 | |||
1376 | 75 | #endif /* PLACESMODEL_H */ | ||
1377 | 76 | 0 | ||
1378 | === removed file 'components/groupedinstalledappsmodel.cpp' | |||
1379 | --- components/groupedinstalledappsmodel.cpp 2012-11-14 21:30:06 +0000 | |||
1380 | +++ components/groupedinstalledappsmodel.cpp 1970-01-01 00:00:00 +0000 | |||
1381 | @@ -1,134 +0,0 @@ | |||
1382 | 1 | /* | ||
1383 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
1384 | 3 | |||
1385 | 4 | This library is free software; you can redistribute it and/or | ||
1386 | 5 | modify it under the terms of the GNU Lesser General Public | ||
1387 | 6 | License as published by the Free Software Foundation; either | ||
1388 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
1389 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
1390 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
1391 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
1392 | 11 | |||
1393 | 12 | This library is distributed in the hope that it will be useful, | ||
1394 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1395 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1396 | 15 | Lesser General Public License for more details. | ||
1397 | 16 | |||
1398 | 17 | You should have received a copy of the GNU Lesser General Public | ||
1399 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
1400 | 19 | */ | ||
1401 | 20 | // Self | ||
1402 | 21 | #include <groupedinstalledappsmodel.h> | ||
1403 | 22 | |||
1404 | 23 | // Local | ||
1405 | 24 | #include <abstractsourceregistry.h> | ||
1406 | 25 | #include <installedappsmodel.h> | ||
1407 | 26 | |||
1408 | 27 | // KDE | ||
1409 | 28 | #include <KConfigGroup> | ||
1410 | 29 | #include <KDebug> | ||
1411 | 30 | |||
1412 | 31 | // Qt | ||
1413 | 32 | |||
1414 | 33 | namespace Homerun { | ||
1415 | 34 | |||
1416 | 35 | GroupedInstalledAppsModel::GroupedInstalledAppsModel(const QString &installer, QObject *parent) | ||
1417 | 36 | : QAbstractListModel(parent) | ||
1418 | 37 | , m_installer(installer) | ||
1419 | 38 | { | ||
1420 | 39 | loadRootEntries(); | ||
1421 | 40 | } | ||
1422 | 41 | |||
1423 | 42 | GroupedInstalledAppsModel::~GroupedInstalledAppsModel() | ||
1424 | 43 | { | ||
1425 | 44 | } | ||
1426 | 45 | |||
1427 | 46 | QObject *GroupedInstalledAppsModel::modelForRow(int row) const | ||
1428 | 47 | { | ||
1429 | 48 | if (row < 0 || row >= m_models.count()) { | ||
1430 | 49 | kWarning() << "No model for row" << row << "!"; | ||
1431 | 50 | return 0; | ||
1432 | 51 | } | ||
1433 | 52 | return m_models.value(row); | ||
1434 | 53 | } | ||
1435 | 54 | |||
1436 | 55 | void GroupedInstalledAppsModel::loadRootEntries() | ||
1437 | 56 | { | ||
1438 | 57 | KServiceGroup::Ptr group = KServiceGroup::root(); | ||
1439 | 58 | KServiceGroup::List list = group->entries(false /* sorted: set to false as it does not seem to work */); | ||
1440 | 59 | |||
1441 | 60 | QMap<QString, KServiceGroup::Ptr> groupMap; | ||
1442 | 61 | for( KServiceGroup::List::ConstIterator it = list.constBegin(); it != list.constEnd(); it++) { | ||
1443 | 62 | const KSycocaEntry::Ptr p = (*it); | ||
1444 | 63 | |||
1445 | 64 | if (p->isType(KST_KServiceGroup)) { | ||
1446 | 65 | KServiceGroup::Ptr subGroup = KServiceGroup::Ptr::staticCast(p); | ||
1447 | 66 | |||
1448 | 67 | if (!subGroup->noDisplay() && subGroup->childCount() > 0) { | ||
1449 | 68 | groupMap.insert(subGroup->caption().toLower(), subGroup); | ||
1450 | 69 | } | ||
1451 | 70 | } | ||
1452 | 71 | } | ||
1453 | 72 | m_pendingGroupList = groupMap.values(); | ||
1454 | 73 | QMetaObject::invokeMethod(this, "loadNextGroup", Qt::QueuedConnection); | ||
1455 | 74 | } | ||
1456 | 75 | |||
1457 | 76 | void GroupedInstalledAppsModel::loadNextGroup() | ||
1458 | 77 | { | ||
1459 | 78 | if (m_pendingGroupList.isEmpty()) { | ||
1460 | 79 | return; | ||
1461 | 80 | } | ||
1462 | 81 | KServiceGroup::Ptr group = m_pendingGroupList.takeFirst(); | ||
1463 | 82 | InstalledAppsModel *model = createInstalledAppsModel(group); | ||
1464 | 83 | beginInsertRows(QModelIndex(), m_models.count(), m_models.count()); | ||
1465 | 84 | m_models << model; | ||
1466 | 85 | endInsertRows(); | ||
1467 | 86 | QMetaObject::invokeMethod(this, "loadNextGroup", Qt::QueuedConnection); | ||
1468 | 87 | } | ||
1469 | 88 | |||
1470 | 89 | int GroupedInstalledAppsModel::rowCount(const QModelIndex &parent) const | ||
1471 | 90 | { | ||
1472 | 91 | if (parent.isValid()) { | ||
1473 | 92 | return 0; | ||
1474 | 93 | } | ||
1475 | 94 | return m_models.count(); | ||
1476 | 95 | } | ||
1477 | 96 | |||
1478 | 97 | QVariant GroupedInstalledAppsModel::data(const QModelIndex &index, int role) const | ||
1479 | 98 | { | ||
1480 | 99 | if (index.parent().isValid()) { | ||
1481 | 100 | return QVariant(); | ||
1482 | 101 | } | ||
1483 | 102 | |||
1484 | 103 | InstalledAppsModel *model = m_models.value(index.row()); | ||
1485 | 104 | if (!model) { | ||
1486 | 105 | return QVariant(); | ||
1487 | 106 | } | ||
1488 | 107 | |||
1489 | 108 | if (role == Qt::DisplayRole) { | ||
1490 | 109 | return model->name(); | ||
1491 | 110 | } else { | ||
1492 | 111 | return QVariant(); | ||
1493 | 112 | } | ||
1494 | 113 | } | ||
1495 | 114 | |||
1496 | 115 | InstalledAppsModel *GroupedInstalledAppsModel::createInstalledAppsModel(KServiceGroup::Ptr group) | ||
1497 | 116 | { | ||
1498 | 117 | return new InstalledAppsModel(group->entryPath(), m_installer, this); | ||
1499 | 118 | } | ||
1500 | 119 | |||
1501 | 120 | //- GroupedInstalledAppsSource -------------------------------------- | ||
1502 | 121 | GroupedInstalledAppsSource::GroupedInstalledAppsSource(QObject *parent) | ||
1503 | 122 | : AbstractSource(parent) | ||
1504 | 123 | {} | ||
1505 | 124 | |||
1506 | 125 | QAbstractItemModel *GroupedInstalledAppsSource::createModelFromConfigGroup(const KConfigGroup &) | ||
1507 | 126 | { | ||
1508 | 127 | KConfigGroup group(config(), "PackageManagement"); | ||
1509 | 128 | QString installer = group.readEntry("categoryInstaller"); | ||
1510 | 129 | return new GroupedInstalledAppsModel(installer); | ||
1511 | 130 | } | ||
1512 | 131 | |||
1513 | 132 | } // namespace Homerun | ||
1514 | 133 | |||
1515 | 134 | #include <groupedinstalledappsmodel.moc> | ||
1516 | 135 | 0 | ||
1517 | === removed file 'components/groupedinstalledappsmodel.h' | |||
1518 | --- components/groupedinstalledappsmodel.h 2012-11-14 21:30:06 +0000 | |||
1519 | +++ components/groupedinstalledappsmodel.h 1970-01-01 00:00:00 +0000 | |||
1520 | @@ -1,75 +0,0 @@ | |||
1521 | 1 | /* | ||
1522 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
1523 | 3 | |||
1524 | 4 | This library is free software; you can redistribute it and/or | ||
1525 | 5 | modify it under the terms of the GNU Lesser General Public | ||
1526 | 6 | License as published by the Free Software Foundation; either | ||
1527 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
1528 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
1529 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
1530 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
1531 | 11 | |||
1532 | 12 | This library is distributed in the hope that it will be useful, | ||
1533 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1534 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1535 | 15 | Lesser General Public License for more details. | ||
1536 | 16 | |||
1537 | 17 | You should have received a copy of the GNU Lesser General Public | ||
1538 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
1539 | 19 | */ | ||
1540 | 20 | #ifndef GROUPEDINSTALLEDAPPSMODEL_H | ||
1541 | 21 | #define GROUPEDINSTALLEDAPPSMODEL_H | ||
1542 | 22 | |||
1543 | 23 | // Local | ||
1544 | 24 | #include <abstractsource.h> | ||
1545 | 25 | |||
1546 | 26 | // Qt | ||
1547 | 27 | #include <QAbstractListModel> | ||
1548 | 28 | |||
1549 | 29 | // KDE | ||
1550 | 30 | #include <KServiceGroup> | ||
1551 | 31 | |||
1552 | 32 | namespace Homerun { | ||
1553 | 33 | |||
1554 | 34 | class InstalledAppsModel; | ||
1555 | 35 | |||
1556 | 36 | /** | ||
1557 | 37 | * A model which returns all services in grouped sub-models | ||
1558 | 38 | */ | ||
1559 | 39 | class GroupedInstalledAppsModel : public QAbstractListModel | ||
1560 | 40 | { | ||
1561 | 41 | Q_OBJECT | ||
1562 | 42 | public: | ||
1563 | 43 | explicit GroupedInstalledAppsModel(const QString &installer, QObject *parent = 0); | ||
1564 | 44 | ~GroupedInstalledAppsModel(); | ||
1565 | 45 | |||
1566 | 46 | int rowCount(const QModelIndex &parent = QModelIndex()) const; // reimp | ||
1567 | 47 | QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const; // reimp | ||
1568 | 48 | |||
1569 | 49 | Q_INVOKABLE QObject *modelForRow(int row) const; | ||
1570 | 50 | |||
1571 | 51 | Q_SIGNALS: | ||
1572 | 52 | void installerChanged(const QString &); | ||
1573 | 53 | |||
1574 | 54 | private Q_SLOTS: | ||
1575 | 55 | void loadRootEntries(); | ||
1576 | 56 | void loadNextGroup(); | ||
1577 | 57 | |||
1578 | 58 | private: | ||
1579 | 59 | QString m_installer; | ||
1580 | 60 | QList<KServiceGroup::Ptr> m_pendingGroupList; | ||
1581 | 61 | QList<InstalledAppsModel *> m_models; | ||
1582 | 62 | |||
1583 | 63 | InstalledAppsModel *createInstalledAppsModel(KServiceGroup::Ptr group); | ||
1584 | 64 | }; | ||
1585 | 65 | |||
1586 | 66 | class GroupedInstalledAppsSource : public AbstractSource | ||
1587 | 67 | { | ||
1588 | 68 | public: | ||
1589 | 69 | GroupedInstalledAppsSource(QObject *parent); | ||
1590 | 70 | QAbstractItemModel *createModelFromConfigGroup(const KConfigGroup &); | ||
1591 | 71 | }; | ||
1592 | 72 | |||
1593 | 73 | } // namespace Homerun | ||
1594 | 74 | |||
1595 | 75 | #endif /* GROUPEDINSTALLEDAPPSMODEL_H */ | ||
1596 | 76 | 0 | ||
1597 | === removed file 'components/installedappsconfigurationwidget.cpp' | |||
1598 | --- components/installedappsconfigurationwidget.cpp 2012-11-14 21:30:06 +0000 | |||
1599 | +++ components/installedappsconfigurationwidget.cpp 1970-01-01 00:00:00 +0000 | |||
1600 | @@ -1,145 +0,0 @@ | |||
1601 | 1 | /* | ||
1602 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
1603 | 3 | |||
1604 | 4 | This library is free software; you can redistribute it and/or | ||
1605 | 5 | modify it under the terms of the GNU Lesser General Public | ||
1606 | 6 | License as published by the Free Software Foundation; either | ||
1607 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
1608 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
1609 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
1610 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
1611 | 11 | |||
1612 | 12 | This library is distributed in the hope that it will be useful, | ||
1613 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1614 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1615 | 15 | Lesser General Public License for more details. | ||
1616 | 16 | |||
1617 | 17 | You should have received a copy of the GNU Lesser General Public | ||
1618 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
1619 | 19 | */ | ||
1620 | 20 | // Self | ||
1621 | 21 | #include <installedappsconfigurationwidget.h> | ||
1622 | 22 | |||
1623 | 23 | // Local | ||
1624 | 24 | #include <ui_installedappsconfigurationwidget.h> | ||
1625 | 25 | |||
1626 | 26 | // KDE | ||
1627 | 27 | #include <KDebug> | ||
1628 | 28 | #include <KIcon> | ||
1629 | 29 | #include <KServiceGroup> | ||
1630 | 30 | #include <KSycocaEntry> | ||
1631 | 31 | |||
1632 | 32 | // Qt | ||
1633 | 33 | #include <QStandardItem> | ||
1634 | 34 | #include <QStandardItemModel> | ||
1635 | 35 | |||
1636 | 36 | enum { | ||
1637 | 37 | EntryPathRole = Qt::UserRole + 1, | ||
1638 | 38 | SortRole, | ||
1639 | 39 | }; | ||
1640 | 40 | |||
1641 | 41 | namespace Homerun | ||
1642 | 42 | { | ||
1643 | 43 | |||
1644 | 44 | InstalledAppsConfigurationWidget::InstalledAppsConfigurationWidget(const KConfigGroup &group) | ||
1645 | 45 | : SourceConfigurationWidget(group) | ||
1646 | 46 | , m_ui(new Ui_InstalledAppsConfigurationWidget) | ||
1647 | 47 | , m_model(new QStandardItemModel(this)) | ||
1648 | 48 | { | ||
1649 | 49 | // Init model | ||
1650 | 50 | QStandardItem *defaultItem = fillModel(group.readEntry("entryPath")); | ||
1651 | 51 | m_model->setSortRole(SortRole); | ||
1652 | 52 | m_model->sort(0); | ||
1653 | 53 | |||
1654 | 54 | m_ui->setupUi(this); | ||
1655 | 55 | m_ui->treeView->setModel(m_model); | ||
1656 | 56 | |||
1657 | 57 | // Select currently configured item | ||
1658 | 58 | Q_ASSERT(defaultItem); | ||
1659 | 59 | QModelIndex index = defaultItem->index(); | ||
1660 | 60 | m_ui->treeView->selectionModel()->select(index, QItemSelectionModel::Select); | ||
1661 | 61 | |||
1662 | 62 | // Expand up to the configured item | ||
1663 | 63 | index = index.parent(); | ||
1664 | 64 | for (; index.isValid(); index = index.parent()) { | ||
1665 | 65 | m_ui->treeView->setExpanded(index, true); | ||
1666 | 66 | } | ||
1667 | 67 | |||
1668 | 68 | // Always expand top level | ||
1669 | 69 | m_ui->treeView->setExpanded(m_model->index(0, 0), true); | ||
1670 | 70 | } | ||
1671 | 71 | |||
1672 | 72 | InstalledAppsConfigurationWidget::~InstalledAppsConfigurationWidget() | ||
1673 | 73 | { | ||
1674 | 74 | delete m_ui; | ||
1675 | 75 | } | ||
1676 | 76 | |||
1677 | 77 | void InstalledAppsConfigurationWidget::save() | ||
1678 | 78 | { | ||
1679 | 79 | QModelIndex index = m_ui->treeView->selectionModel()->currentIndex(); | ||
1680 | 80 | if (!index.isValid()) { | ||
1681 | 81 | kWarning() << "No item selected!"; | ||
1682 | 82 | return; | ||
1683 | 83 | } | ||
1684 | 84 | QString entryPath = index.data(EntryPathRole).toString(); | ||
1685 | 85 | configGroup().writeEntry("entryPath", entryPath); | ||
1686 | 86 | } | ||
1687 | 87 | |||
1688 | 88 | |||
1689 | 89 | // Helper struct for fillModel | ||
1690 | 90 | struct ItemCreator | ||
1691 | 91 | { | ||
1692 | 92 | ItemCreator() | ||
1693 | 93 | : m_item(0) | ||
1694 | 94 | {} | ||
1695 | 95 | QString m_entryPath; | ||
1696 | 96 | QStandardItem *m_item; | ||
1697 | 97 | |||
1698 | 98 | void createItemChildren(QStandardItem *parent, KServiceGroup::Ptr parentGroup) | ||
1699 | 99 | { | ||
1700 | 100 | KServiceGroup::List list = parentGroup->entries(false /* sorted: set to false as it does not seem to work */); | ||
1701 | 101 | |||
1702 | 102 | Q_FOREACH(const KSycocaEntry::Ptr entry, list) { | ||
1703 | 103 | if (!entry->isType(KST_KServiceGroup)) { | ||
1704 | 104 | continue; | ||
1705 | 105 | } | ||
1706 | 106 | KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast(entry); | ||
1707 | 107 | |||
1708 | 108 | if (group->noDisplay() || group->childCount() == 0) { | ||
1709 | 109 | continue; | ||
1710 | 110 | } | ||
1711 | 111 | QString entryPath = group->entryPath(); | ||
1712 | 112 | |||
1713 | 113 | QStandardItem *item = new QStandardItem; | ||
1714 | 114 | item->setText(group->caption()); | ||
1715 | 115 | item->setIcon(KIcon(group->icon())); | ||
1716 | 116 | item->setData(entryPath, EntryPathRole); | ||
1717 | 117 | item->setData(group->caption().toLower(), SortRole); | ||
1718 | 118 | |||
1719 | 119 | parent->appendRow(item); | ||
1720 | 120 | createItemChildren(item, group); | ||
1721 | 121 | |||
1722 | 122 | if (m_entryPath == entryPath) { | ||
1723 | 123 | m_item = item; | ||
1724 | 124 | } | ||
1725 | 125 | } | ||
1726 | 126 | } | ||
1727 | 127 | }; | ||
1728 | 128 | |||
1729 | 129 | QStandardItem *InstalledAppsConfigurationWidget::fillModel(const QString &entryPath) | ||
1730 | 130 | { | ||
1731 | 131 | KServiceGroup::Ptr group = KServiceGroup::root(); | ||
1732 | 132 | QStandardItem *rootItem = new QStandardItem; | ||
1733 | 133 | rootItem->setText(i18n("All Applications")); | ||
1734 | 134 | rootItem->setData(QString(), EntryPathRole); | ||
1735 | 135 | m_model->appendRow(rootItem); | ||
1736 | 136 | |||
1737 | 137 | ItemCreator creator; | ||
1738 | 138 | creator.m_entryPath = entryPath; | ||
1739 | 139 | creator.createItemChildren(rootItem, group); | ||
1740 | 140 | return creator.m_item ? creator.m_item : rootItem; | ||
1741 | 141 | } | ||
1742 | 142 | |||
1743 | 143 | } // namespace Homerun | ||
1744 | 144 | |||
1745 | 145 | #include <installedappsconfigurationwidget.moc> | ||
1746 | 146 | 0 | ||
1747 | === removed file 'components/installedappsconfigurationwidget.h' | |||
1748 | --- components/installedappsconfigurationwidget.h 2012-11-14 21:30:06 +0000 | |||
1749 | +++ components/installedappsconfigurationwidget.h 1970-01-01 00:00:00 +0000 | |||
1750 | @@ -1,63 +0,0 @@ | |||
1751 | 1 | /* | ||
1752 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
1753 | 3 | |||
1754 | 4 | This library is free software; you can redistribute it and/or | ||
1755 | 5 | modify it under the terms of the GNU Lesser General Public | ||
1756 | 6 | License as published by the Free Software Foundation; either | ||
1757 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
1758 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
1759 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
1760 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
1761 | 11 | |||
1762 | 12 | This library is distributed in the hope that it will be useful, | ||
1763 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1764 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1765 | 15 | Lesser General Public License for more details. | ||
1766 | 16 | |||
1767 | 17 | You should have received a copy of the GNU Lesser General Public | ||
1768 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
1769 | 19 | */ | ||
1770 | 20 | #ifndef INSTALLEDAPPSCONFIGURATIONWIDGET_H | ||
1771 | 21 | #define INSTALLEDAPPSCONFIGURATIONWIDGET_H | ||
1772 | 22 | |||
1773 | 23 | // Local | ||
1774 | 24 | #include <sourceconfigurationwidget.h> | ||
1775 | 25 | |||
1776 | 26 | // Qt | ||
1777 | 27 | |||
1778 | 28 | // KDE | ||
1779 | 29 | #include <KServiceGroup> | ||
1780 | 30 | |||
1781 | 31 | class QStandardItem; | ||
1782 | 32 | class QStandardItemModel; | ||
1783 | 33 | |||
1784 | 34 | class Ui_InstalledAppsConfigurationWidget; | ||
1785 | 35 | |||
1786 | 36 | namespace Homerun | ||
1787 | 37 | { | ||
1788 | 38 | |||
1789 | 39 | /** | ||
1790 | 40 | * Configuration widget for the InstalledApps source | ||
1791 | 41 | */ | ||
1792 | 42 | class InstalledAppsConfigurationWidget : public SourceConfigurationWidget | ||
1793 | 43 | { | ||
1794 | 44 | Q_OBJECT | ||
1795 | 45 | public: | ||
1796 | 46 | explicit InstalledAppsConfigurationWidget(const KConfigGroup &group); | ||
1797 | 47 | ~InstalledAppsConfigurationWidget(); | ||
1798 | 48 | |||
1799 | 49 | void save(); // reimp | ||
1800 | 50 | |||
1801 | 51 | private: | ||
1802 | 52 | Ui_InstalledAppsConfigurationWidget *m_ui; | ||
1803 | 53 | QStandardItemModel *m_model; | ||
1804 | 54 | |||
1805 | 55 | /** | ||
1806 | 56 | * Fill m_model, returns the item which corresponds to defaultEntryPath | ||
1807 | 57 | */ | ||
1808 | 58 | QStandardItem *fillModel(const QString &defaultEntryPath); | ||
1809 | 59 | }; | ||
1810 | 60 | |||
1811 | 61 | } // namespace Homerun | ||
1812 | 62 | |||
1813 | 63 | #endif /* INSTALLEDAPPSCONFIGURATIONWIDGET_H */ | ||
1814 | 64 | 0 | ||
1815 | === removed file 'components/installedappsconfigurationwidget.ui' | |||
1816 | --- components/installedappsconfigurationwidget.ui 2012-11-14 21:30:06 +0000 | |||
1817 | +++ components/installedappsconfigurationwidget.ui 1970-01-01 00:00:00 +0000 | |||
1818 | @@ -1,50 +0,0 @@ | |||
1819 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
1820 | 2 | <ui version="4.0"> | ||
1821 | 3 | <class>InstalledAppsConfigurationWidget</class> | ||
1822 | 4 | <widget class="QWidget" name="InstalledAppsConfigurationWidget"> | ||
1823 | 5 | <property name="geometry"> | ||
1824 | 6 | <rect> | ||
1825 | 7 | <x>0</x> | ||
1826 | 8 | <y>0</y> | ||
1827 | 9 | <width>408</width> | ||
1828 | 10 | <height>327</height> | ||
1829 | 11 | </rect> | ||
1830 | 12 | </property> | ||
1831 | 13 | <layout class="QVBoxLayout" name="verticalLayout"> | ||
1832 | 14 | <item> | ||
1833 | 15 | <widget class="QLabel" name="label"> | ||
1834 | 16 | <property name="text"> | ||
1835 | 17 | <string>Pick the application folder to display:</string> | ||
1836 | 18 | </property> | ||
1837 | 19 | <property name="buddy"> | ||
1838 | 20 | <cstring>treeView</cstring> | ||
1839 | 21 | </property> | ||
1840 | 22 | </widget> | ||
1841 | 23 | </item> | ||
1842 | 24 | <item> | ||
1843 | 25 | <widget class="QTreeView" name="treeView"> | ||
1844 | 26 | <property name="minimumSize"> | ||
1845 | 27 | <size> | ||
1846 | 28 | <width>400</width> | ||
1847 | 29 | <height>300</height> | ||
1848 | 30 | </size> | ||
1849 | 31 | </property> | ||
1850 | 32 | <property name="editTriggers"> | ||
1851 | 33 | <set>QAbstractItemView::NoEditTriggers</set> | ||
1852 | 34 | </property> | ||
1853 | 35 | <property name="showDropIndicator" stdset="0"> | ||
1854 | 36 | <bool>false</bool> | ||
1855 | 37 | </property> | ||
1856 | 38 | <property name="rootIsDecorated"> | ||
1857 | 39 | <bool>false</bool> | ||
1858 | 40 | </property> | ||
1859 | 41 | <property name="headerHidden"> | ||
1860 | 42 | <bool>true</bool> | ||
1861 | 43 | </property> | ||
1862 | 44 | </widget> | ||
1863 | 45 | </item> | ||
1864 | 46 | </layout> | ||
1865 | 47 | </widget> | ||
1866 | 48 | <resources/> | ||
1867 | 49 | <connections/> | ||
1868 | 50 | </ui> | ||
1869 | 51 | 0 | ||
1870 | === removed file 'components/installedappsmodel.cpp' | |||
1871 | --- components/installedappsmodel.cpp 2012-11-14 21:30:06 +0000 | |||
1872 | +++ components/installedappsmodel.cpp 1970-01-01 00:00:00 +0000 | |||
1873 | @@ -1,319 +0,0 @@ | |||
1874 | 1 | /* | ||
1875 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
1876 | 3 | |||
1877 | 4 | This library is free software; you can redistribute it and/or | ||
1878 | 5 | modify it under the terms of the GNU Lesser General Public | ||
1879 | 6 | License as published by the Free Software Foundation; either | ||
1880 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
1881 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
1882 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
1883 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
1884 | 11 | |||
1885 | 12 | This library is distributed in the hope that it will be useful, | ||
1886 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1887 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1888 | 15 | Lesser General Public License for more details. | ||
1889 | 16 | |||
1890 | 17 | You should have received a copy of the GNU Lesser General Public | ||
1891 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
1892 | 19 | */ | ||
1893 | 20 | // Local | ||
1894 | 21 | #include <pathmodel.h> | ||
1895 | 22 | #include <installedappsmodel.h> | ||
1896 | 23 | #include <installedappsconfigurationwidget.h> | ||
1897 | 24 | #include <sourceregistry.h> | ||
1898 | 25 | |||
1899 | 26 | // Qt | ||
1900 | 27 | #include <QIcon> | ||
1901 | 28 | #include <QAction> | ||
1902 | 29 | #include <QTimer> | ||
1903 | 30 | |||
1904 | 31 | // KDE | ||
1905 | 32 | #include <KDebug> | ||
1906 | 33 | #include <KLocale> | ||
1907 | 34 | #include <kmacroexpander.h> | ||
1908 | 35 | #include <KRun> | ||
1909 | 36 | #include <KService> | ||
1910 | 37 | #include <KServiceTypeTrader> | ||
1911 | 38 | #include <KSycocaEntry> | ||
1912 | 39 | |||
1913 | 40 | #include <Plasma/RunnerManager> | ||
1914 | 41 | |||
1915 | 42 | namespace Homerun { | ||
1916 | 43 | |||
1917 | 44 | static const char *SOURCE_ID = "InstalledApps"; | ||
1918 | 45 | |||
1919 | 46 | //- AbstractNode --------------------------------------------------------------- | ||
1920 | 47 | AbstractNode::~AbstractNode() | ||
1921 | 48 | { | ||
1922 | 49 | } | ||
1923 | 50 | |||
1924 | 51 | bool AbstractNode::lessThan(AbstractNode *n1, AbstractNode *n2) | ||
1925 | 52 | { | ||
1926 | 53 | Q_ASSERT(n1); | ||
1927 | 54 | Q_ASSERT(n2); | ||
1928 | 55 | return n1->m_sortKey < n2->m_sortKey; | ||
1929 | 56 | } | ||
1930 | 57 | |||
1931 | 58 | //- GroupNode ------------------------------------------------------------------ | ||
1932 | 59 | GroupNode::GroupNode(KServiceGroup::Ptr group, InstalledAppsModel *model) | ||
1933 | 60 | : m_model(model) | ||
1934 | 61 | { | ||
1935 | 62 | m_icon = group->icon(); | ||
1936 | 63 | m_name = group->caption(); | ||
1937 | 64 | m_entryPath = group->entryPath(); | ||
1938 | 65 | m_sortKey = m_name.toLower(); | ||
1939 | 66 | } | ||
1940 | 67 | |||
1941 | 68 | bool GroupNode::trigger() | ||
1942 | 69 | { | ||
1943 | 70 | QVariantMap args; | ||
1944 | 71 | args.insert("entryPath", m_entryPath); | ||
1945 | 72 | m_model->openSourceRequested(SOURCE_ID, args); | ||
1946 | 73 | return false; | ||
1947 | 74 | } | ||
1948 | 75 | |||
1949 | 76 | //- AppNode -------------------------------------------------------------------- | ||
1950 | 77 | AppNode::AppNode(KService::Ptr service) | ||
1951 | 78 | : m_service(service) | ||
1952 | 79 | { | ||
1953 | 80 | m_icon = service->icon(); | ||
1954 | 81 | m_name = service->name(); | ||
1955 | 82 | m_service = service; | ||
1956 | 83 | m_sortKey = m_name.toLower(); | ||
1957 | 84 | } | ||
1958 | 85 | |||
1959 | 86 | bool AppNode::trigger() | ||
1960 | 87 | { | ||
1961 | 88 | return KRun::run(*m_service, KUrl::List(), 0); | ||
1962 | 89 | } | ||
1963 | 90 | |||
1964 | 91 | QString AppNode::favoriteId() const | ||
1965 | 92 | { | ||
1966 | 93 | return QString("app:") + m_service->storageId(); | ||
1967 | 94 | } | ||
1968 | 95 | |||
1969 | 96 | //- InstallerNode -------------------------------------------------------------- | ||
1970 | 97 | InstallerNode::InstallerNode(KServiceGroup::Ptr group, KService::Ptr installerService) | ||
1971 | 98 | : m_group(group) | ||
1972 | 99 | , m_service(installerService) | ||
1973 | 100 | { | ||
1974 | 101 | m_icon = m_service->icon(); | ||
1975 | 102 | m_name = m_service->name(); | ||
1976 | 103 | } | ||
1977 | 104 | |||
1978 | 105 | bool InstallerNode::trigger() | ||
1979 | 106 | { | ||
1980 | 107 | QHash<QString, QString> map; | ||
1981 | 108 | QString category = m_group->entryPath(); | ||
1982 | 109 | if (category.endsWith('/')) { | ||
1983 | 110 | category.truncate(category.length() - 1); | ||
1984 | 111 | } | ||
1985 | 112 | map.insert("category", category); | ||
1986 | 113 | |||
1987 | 114 | QString command = KMacroExpander::expandMacros(m_service->exec(), map, '@'); | ||
1988 | 115 | return KRun::run(command, KUrl::List(), 0, m_service->name(), m_service->icon()); | ||
1989 | 116 | } | ||
1990 | 117 | |||
1991 | 118 | //- InstalledAppsModel ------------------------------------------------------------ | ||
1992 | 119 | InstalledAppsModel::InstalledAppsModel(const QString &entryPath, const QString &installer, QObject *parent) | ||
1993 | 120 | : QAbstractListModel(parent) | ||
1994 | 121 | , m_pathModel(new PathModel(this)) | ||
1995 | 122 | , m_installer(installer) | ||
1996 | 123 | { | ||
1997 | 124 | QHash<int, QByteArray> roles; | ||
1998 | 125 | roles.insert(Qt::DisplayRole, "display"); | ||
1999 | 126 | roles.insert(Qt::DecorationRole, "decoration"); | ||
2000 | 127 | roles.insert(FavoriteIdRole, "favoriteId"); | ||
2001 | 128 | |||
2002 | 129 | setRoleNames(roles); | ||
2003 | 130 | |||
2004 | 131 | load(entryPath); | ||
2005 | 132 | } | ||
2006 | 133 | |||
2007 | 134 | InstalledAppsModel::~InstalledAppsModel() | ||
2008 | 135 | { | ||
2009 | 136 | qDeleteAll(m_nodeList); | ||
2010 | 137 | } | ||
2011 | 138 | |||
2012 | 139 | int InstalledAppsModel::rowCount(const QModelIndex& index) const | ||
2013 | 140 | { | ||
2014 | 141 | return index.isValid() ? 0 : m_nodeList.count(); | ||
2015 | 142 | } | ||
2016 | 143 | |||
2017 | 144 | int InstalledAppsModel::count() const | ||
2018 | 145 | { | ||
2019 | 146 | return m_nodeList.count(); | ||
2020 | 147 | } | ||
2021 | 148 | |||
2022 | 149 | QVariant InstalledAppsModel::data(const QModelIndex &index, int role) const | ||
2023 | 150 | { | ||
2024 | 151 | if (!index.isValid() || index.row() >= m_nodeList.count()) { | ||
2025 | 152 | return QVariant(); | ||
2026 | 153 | } | ||
2027 | 154 | |||
2028 | 155 | const AbstractNode *node = m_nodeList.at(index.row()); | ||
2029 | 156 | if (role == Qt::DisplayRole) { | ||
2030 | 157 | return node->name(); | ||
2031 | 158 | } else if (role == Qt::DecorationRole) { | ||
2032 | 159 | // at least show the oxygen question-mark, otherwise it looks weird blank. | ||
2033 | 160 | return node->icon().isEmpty() ? QLatin1String("unknown") : node->icon(); | ||
2034 | 161 | } else if (role == FavoriteIdRole) { | ||
2035 | 162 | return node->favoriteId(); | ||
2036 | 163 | } | ||
2037 | 164 | |||
2038 | 165 | return QVariant(); | ||
2039 | 166 | } | ||
2040 | 167 | |||
2041 | 168 | bool InstalledAppsModel::trigger(int row) | ||
2042 | 169 | { | ||
2043 | 170 | return m_nodeList.at(row)->trigger(); | ||
2044 | 171 | } | ||
2045 | 172 | |||
2046 | 173 | void InstalledAppsModel::load(const QString &entryPath) | ||
2047 | 174 | { | ||
2048 | 175 | m_pathModel->clear(); | ||
2049 | 176 | beginResetModel(); | ||
2050 | 177 | qDeleteAll(m_nodeList); | ||
2051 | 178 | m_nodeList.clear(); | ||
2052 | 179 | |||
2053 | 180 | if (entryPath.isEmpty()) { | ||
2054 | 181 | loadRootEntries(); | ||
2055 | 182 | } else { | ||
2056 | 183 | KServiceGroup::Ptr group = KServiceGroup::group(entryPath); | ||
2057 | 184 | loadServiceGroup(group); | ||
2058 | 185 | QVariantMap args; | ||
2059 | 186 | args.insert("entryPath", entryPath); | ||
2060 | 187 | m_pathModel->addPath(group->caption(), SOURCE_ID, args); | ||
2061 | 188 | } | ||
2062 | 189 | |||
2063 | 190 | endResetModel(); | ||
2064 | 191 | |||
2065 | 192 | emit countChanged(); | ||
2066 | 193 | } | ||
2067 | 194 | |||
2068 | 195 | void InstalledAppsModel::loadRootEntries() | ||
2069 | 196 | { | ||
2070 | 197 | KServiceGroup::Ptr group = KServiceGroup::root(); | ||
2071 | 198 | KServiceGroup::List list = group->entries(false /* sorted: set to false as it does not seem to work */); | ||
2072 | 199 | |||
2073 | 200 | for( KServiceGroup::List::ConstIterator it = list.constBegin(); it != list.constEnd(); it++) { | ||
2074 | 201 | const KSycocaEntry::Ptr p = (*it); | ||
2075 | 202 | |||
2076 | 203 | if (p->isType(KST_KServiceGroup)) { | ||
2077 | 204 | KServiceGroup::Ptr subGroup = KServiceGroup::Ptr::staticCast(p); | ||
2078 | 205 | |||
2079 | 206 | if (!subGroup->noDisplay() && subGroup->childCount() > 0) { | ||
2080 | 207 | m_nodeList << new GroupNode(subGroup, this); | ||
2081 | 208 | } | ||
2082 | 209 | } | ||
2083 | 210 | } | ||
2084 | 211 | qSort(m_nodeList.begin(), m_nodeList.end(), AbstractNode::lessThan); | ||
2085 | 212 | } | ||
2086 | 213 | |||
2087 | 214 | void InstalledAppsModel::loadServiceGroup(KServiceGroup::Ptr group) | ||
2088 | 215 | { | ||
2089 | 216 | doLoadServiceGroup(group); | ||
2090 | 217 | |||
2091 | 218 | qSort(m_nodeList.begin(), m_nodeList.end(), AbstractNode::lessThan); | ||
2092 | 219 | |||
2093 | 220 | if (!m_installer.isEmpty()) { | ||
2094 | 221 | KService::Ptr service = KService::serviceByDesktopName(m_installer); | ||
2095 | 222 | if (service) { | ||
2096 | 223 | m_nodeList << new InstallerNode(group, service); | ||
2097 | 224 | } else { | ||
2098 | 225 | kWarning() << "Could not find service for" << m_installer; | ||
2099 | 226 | } | ||
2100 | 227 | } | ||
2101 | 228 | } | ||
2102 | 229 | |||
2103 | 230 | void InstalledAppsModel::doLoadServiceGroup(KServiceGroup::Ptr group) | ||
2104 | 231 | { | ||
2105 | 232 | /* This method is separate from loadServiceGroup so that | ||
2106 | 233 | * - only one installer node is added at the end | ||
2107 | 234 | * - sorting is done only once | ||
2108 | 235 | */ | ||
2109 | 236 | if (!group || !group->isValid()) { | ||
2110 | 237 | return; | ||
2111 | 238 | } | ||
2112 | 239 | |||
2113 | 240 | KServiceGroup::List list = group->entries(false /* see above */); | ||
2114 | 241 | |||
2115 | 242 | for( KServiceGroup::List::ConstIterator it = list.constBegin(); | ||
2116 | 243 | it != list.constEnd(); it++) { | ||
2117 | 244 | const KSycocaEntry::Ptr p = (*it); | ||
2118 | 245 | |||
2119 | 246 | if (p->isType(KST_KService)) { | ||
2120 | 247 | const KService::Ptr service = KService::Ptr::staticCast(p); | ||
2121 | 248 | |||
2122 | 249 | if (!service->noDisplay()) { | ||
2123 | 250 | QString genericName = service->genericName(); | ||
2124 | 251 | if (genericName.isNull()) { | ||
2125 | 252 | genericName = service->comment(); | ||
2126 | 253 | } | ||
2127 | 254 | m_nodeList << new AppNode(service); | ||
2128 | 255 | } | ||
2129 | 256 | |||
2130 | 257 | } else if (p->isType(KST_KServiceGroup)) { | ||
2131 | 258 | const KServiceGroup::Ptr subGroup = KServiceGroup::Ptr::staticCast(p); | ||
2132 | 259 | |||
2133 | 260 | if (!subGroup->noDisplay() && subGroup->childCount() > 0) { | ||
2134 | 261 | doLoadServiceGroup(subGroup); | ||
2135 | 262 | } | ||
2136 | 263 | } | ||
2137 | 264 | } | ||
2138 | 265 | } | ||
2139 | 266 | |||
2140 | 267 | PathModel *InstalledAppsModel::pathModel() const | ||
2141 | 268 | { | ||
2142 | 269 | return m_pathModel; | ||
2143 | 270 | } | ||
2144 | 271 | |||
2145 | 272 | QString InstalledAppsModel::name() const | ||
2146 | 273 | { | ||
2147 | 274 | if (m_pathModel->count() > 0) { | ||
2148 | 275 | QModelIndex index = m_pathModel->index(m_pathModel->count() - 1, 0); | ||
2149 | 276 | return index.data().toString(); | ||
2150 | 277 | } else { | ||
2151 | 278 | return i18n("Applications"); | ||
2152 | 279 | } | ||
2153 | 280 | } | ||
2154 | 281 | |||
2155 | 282 | //- InstalledAppsSource --------------------------------------------- | ||
2156 | 283 | InstalledAppsSource::InstalledAppsSource(QObject *parent) | ||
2157 | 284 | : AbstractSource(parent) | ||
2158 | 285 | {} | ||
2159 | 286 | |||
2160 | 287 | QAbstractItemModel *InstalledAppsSource::createModelFromConfigGroup(const KConfigGroup &group) | ||
2161 | 288 | { | ||
2162 | 289 | QString entryPath = group.readEntry("entryPath"); | ||
2163 | 290 | return createModel(entryPath); | ||
2164 | 291 | } | ||
2165 | 292 | |||
2166 | 293 | QAbstractItemModel *InstalledAppsSource::createModelFromArguments(const QVariantMap &arguments) | ||
2167 | 294 | { | ||
2168 | 295 | QString entryPath = arguments.value("entryPath").toString(); | ||
2169 | 296 | return createModel(entryPath); | ||
2170 | 297 | } | ||
2171 | 298 | |||
2172 | 299 | QAbstractItemModel *InstalledAppsSource::createModel(const QString &entryPath) | ||
2173 | 300 | { | ||
2174 | 301 | KConfigGroup group(config(), "PackageManagement"); | ||
2175 | 302 | QString installer = group.readEntry("categoryInstaller"); | ||
2176 | 303 | |||
2177 | 304 | return new InstalledAppsModel(entryPath, installer); | ||
2178 | 305 | } | ||
2179 | 306 | |||
2180 | 307 | bool InstalledAppsSource::isConfigurable() const | ||
2181 | 308 | { | ||
2182 | 309 | return true; | ||
2183 | 310 | } | ||
2184 | 311 | |||
2185 | 312 | SourceConfigurationWidget *InstalledAppsSource::createConfigurationWidget(const KConfigGroup &group) | ||
2186 | 313 | { | ||
2187 | 314 | return new InstalledAppsConfigurationWidget(group); | ||
2188 | 315 | } | ||
2189 | 316 | |||
2190 | 317 | } // namespace Homerun | ||
2191 | 318 | |||
2192 | 319 | #include "installedappsmodel.moc" | ||
2193 | 320 | 0 | ||
2194 | === removed file 'components/installedappsmodel.h' | |||
2195 | --- components/installedappsmodel.h 2012-11-14 21:30:06 +0000 | |||
2196 | +++ components/installedappsmodel.h 1970-01-01 00:00:00 +0000 | |||
2197 | @@ -1,159 +0,0 @@ | |||
2198 | 1 | /* | ||
2199 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
2200 | 3 | |||
2201 | 4 | This library is free software; you can redistribute it and/or | ||
2202 | 5 | modify it under the terms of the GNU Lesser General Public | ||
2203 | 6 | License as published by the Free Software Foundation; either | ||
2204 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
2205 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
2206 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
2207 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
2208 | 11 | |||
2209 | 12 | This library is distributed in the hope that it will be useful, | ||
2210 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2211 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2212 | 15 | Lesser General Public License for more details. | ||
2213 | 16 | |||
2214 | 17 | You should have received a copy of the GNU Lesser General Public | ||
2215 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
2216 | 19 | */ | ||
2217 | 20 | #ifndef INSTALLEDAPPSMODEL_H | ||
2218 | 21 | #define INSTALLEDAPPSMODEL_H | ||
2219 | 22 | |||
2220 | 23 | // Local | ||
2221 | 24 | #include <abstractsource.h> | ||
2222 | 25 | |||
2223 | 26 | // Qt | ||
2224 | 27 | #include <QAbstractListModel> | ||
2225 | 28 | #include <QStringList> | ||
2226 | 29 | |||
2227 | 30 | // KDE | ||
2228 | 31 | #include <KIcon> | ||
2229 | 32 | #include <KService> | ||
2230 | 33 | #include <KServiceGroup> | ||
2231 | 34 | #include <KUrl> | ||
2232 | 35 | |||
2233 | 36 | namespace Homerun { | ||
2234 | 37 | |||
2235 | 38 | class PathModel; | ||
2236 | 39 | |||
2237 | 40 | class InstalledAppsModel; | ||
2238 | 41 | class InstalledAppsSource; | ||
2239 | 42 | |||
2240 | 43 | class AbstractNode | ||
2241 | 44 | { | ||
2242 | 45 | public: | ||
2243 | 46 | virtual ~AbstractNode(); | ||
2244 | 47 | |||
2245 | 48 | virtual bool trigger() = 0; | ||
2246 | 49 | virtual QString favoriteId() const { return QString(); } | ||
2247 | 50 | |||
2248 | 51 | QString icon() const { return m_icon; } | ||
2249 | 52 | QString name() const { return m_name; } | ||
2250 | 53 | |||
2251 | 54 | static bool lessThan(AbstractNode *n1, AbstractNode *n2); | ||
2252 | 55 | |||
2253 | 56 | protected: | ||
2254 | 57 | QString m_sortKey; | ||
2255 | 58 | QString m_icon; | ||
2256 | 59 | QString m_name; | ||
2257 | 60 | }; | ||
2258 | 61 | |||
2259 | 62 | class GroupNode : public AbstractNode | ||
2260 | 63 | { | ||
2261 | 64 | public: | ||
2262 | 65 | GroupNode(KServiceGroup::Ptr group, InstalledAppsModel *model); | ||
2263 | 66 | |||
2264 | 67 | bool trigger(); // reimp | ||
2265 | 68 | |||
2266 | 69 | private: | ||
2267 | 70 | InstalledAppsModel *m_model; | ||
2268 | 71 | QString m_entryPath; | ||
2269 | 72 | }; | ||
2270 | 73 | |||
2271 | 74 | class AppNode : public AbstractNode | ||
2272 | 75 | { | ||
2273 | 76 | public: | ||
2274 | 77 | AppNode(KService::Ptr service); | ||
2275 | 78 | |||
2276 | 79 | bool trigger(); // reimp; | ||
2277 | 80 | QString favoriteId() const; // reimp | ||
2278 | 81 | |||
2279 | 82 | private: | ||
2280 | 83 | KService::Ptr m_service; | ||
2281 | 84 | }; | ||
2282 | 85 | |||
2283 | 86 | class InstallerNode : public AbstractNode | ||
2284 | 87 | { | ||
2285 | 88 | public: | ||
2286 | 89 | InstallerNode(KServiceGroup::Ptr group, KService::Ptr installerService); | ||
2287 | 90 | |||
2288 | 91 | bool trigger(); // reimp | ||
2289 | 92 | |||
2290 | 93 | private: | ||
2291 | 94 | InstalledAppsModel *m_model; | ||
2292 | 95 | KServiceGroup::Ptr m_group; | ||
2293 | 96 | KService::Ptr m_service; | ||
2294 | 97 | }; | ||
2295 | 98 | |||
2296 | 99 | class InstalledAppsModel : public QAbstractListModel | ||
2297 | 100 | { | ||
2298 | 101 | Q_OBJECT | ||
2299 | 102 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
2300 | 103 | Q_PROPERTY(QObject* pathModel READ pathModel CONSTANT) | ||
2301 | 104 | Q_PROPERTY(QString name READ name CONSTANT) | ||
2302 | 105 | |||
2303 | 106 | public: | ||
2304 | 107 | enum Roles { | ||
2305 | 108 | FavoriteIdRole = Qt::UserRole + 1, | ||
2306 | 109 | }; | ||
2307 | 110 | |||
2308 | 111 | InstalledAppsModel(const QString &entryPath, const QString &installer, QObject *parent = 0); | ||
2309 | 112 | ~InstalledAppsModel(); | ||
2310 | 113 | |||
2311 | 114 | int rowCount(const QModelIndex&) const; | ||
2312 | 115 | int count() const; | ||
2313 | 116 | QVariant data(const QModelIndex&, int) const; | ||
2314 | 117 | |||
2315 | 118 | PathModel *pathModel() const; | ||
2316 | 119 | |||
2317 | 120 | Q_INVOKABLE bool trigger(int row); | ||
2318 | 121 | |||
2319 | 122 | QString name() const; | ||
2320 | 123 | |||
2321 | 124 | Q_SIGNALS: | ||
2322 | 125 | void countChanged(); | ||
2323 | 126 | void openSourceRequested(const QString &sourceId, const QVariantMap &args); | ||
2324 | 127 | |||
2325 | 128 | private: | ||
2326 | 129 | void loadRootEntries(); | ||
2327 | 130 | void loadServiceGroup(KServiceGroup::Ptr group); | ||
2328 | 131 | void doLoadServiceGroup(KServiceGroup::Ptr group); | ||
2329 | 132 | |||
2330 | 133 | PathModel *m_pathModel; | ||
2331 | 134 | QList<AbstractNode *> m_nodeList; | ||
2332 | 135 | QString m_installer; | ||
2333 | 136 | QString m_arguments; | ||
2334 | 137 | |||
2335 | 138 | void load(const QString &entryPath); | ||
2336 | 139 | |||
2337 | 140 | friend class GroupNode; | ||
2338 | 141 | }; | ||
2339 | 142 | |||
2340 | 143 | class InstalledAppsSource : public AbstractSource | ||
2341 | 144 | { | ||
2342 | 145 | public: | ||
2343 | 146 | InstalledAppsSource(QObject *parent); | ||
2344 | 147 | QAbstractItemModel *createModelFromConfigGroup(const KConfigGroup &group); // reimp | ||
2345 | 148 | QAbstractItemModel *createModelFromArguments(const QVariantMap &arguments); // reimp | ||
2346 | 149 | |||
2347 | 150 | bool isConfigurable() const; // reimp | ||
2348 | 151 | SourceConfigurationWidget *createConfigurationWidget(const KConfigGroup &group); // reimp | ||
2349 | 152 | |||
2350 | 153 | private: | ||
2351 | 154 | QAbstractItemModel *createModel(const QString &entryPath); | ||
2352 | 155 | }; | ||
2353 | 156 | |||
2354 | 157 | } // namespace Homerun | ||
2355 | 158 | |||
2356 | 159 | #endif | ||
2357 | 160 | 0 | ||
2358 | === added file 'components/messagebox.cpp' | |||
2359 | --- components/messagebox.cpp 1970-01-01 00:00:00 +0000 | |||
2360 | +++ components/messagebox.cpp 2013-03-01 15:15:27 +0000 | |||
2361 | @@ -0,0 +1,45 @@ | |||
2362 | 1 | /* | ||
2363 | 2 | Copyright 2013 Aurélien Gâteau <agateau@kde.org> | ||
2364 | 3 | |||
2365 | 4 | This program is free software; you can redistribute it and/or | ||
2366 | 5 | modify it under the terms of the GNU General Public License as | ||
2367 | 6 | published by the Free Software Foundation; either version 2 of | ||
2368 | 7 | the License or (at your option) version 3 or any later version | ||
2369 | 8 | accepted by the membership of KDE e.V. (or its successor approved | ||
2370 | 9 | by the membership of KDE e.V.), which shall act as a proxy | ||
2371 | 10 | defined in Section 14 of version 3 of the license. | ||
2372 | 11 | |||
2373 | 12 | This program is distributed in the hope that it will be useful, | ||
2374 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2375 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2376 | 15 | GNU General Public License for more details. | ||
2377 | 16 | |||
2378 | 17 | You should have received a copy of the GNU General Public License | ||
2379 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2380 | 19 | */ | ||
2381 | 20 | // Self | ||
2382 | 21 | #include <messagebox.h> | ||
2383 | 22 | |||
2384 | 23 | // Local | ||
2385 | 24 | |||
2386 | 25 | // KDE | ||
2387 | 26 | |||
2388 | 27 | // Qt | ||
2389 | 28 | #include <QApplication> | ||
2390 | 29 | |||
2391 | 30 | MessageBox::MessageBox(QObject *parent) | ||
2392 | 31 | : QObject(parent) | ||
2393 | 32 | { | ||
2394 | 33 | } | ||
2395 | 34 | |||
2396 | 35 | int MessageBox::warningContinueCancel(const QString& text, const QString& caption, const QString& continueText, const QString& cancelText) | ||
2397 | 36 | { | ||
2398 | 37 | KGuiItem cont = continueText.isEmpty() ? KStandardGuiItem::cont() : KGuiItem(continueText); | ||
2399 | 38 | KGuiItem cancel = cancelText.isEmpty() ? KStandardGuiItem::cancel() : KGuiItem(cancelText); | ||
2400 | 39 | int ret = KMessageBox::warningContinueCancel(QApplication::activeWindow(), | ||
2401 | 40 | text, caption, cont, cancel); | ||
2402 | 41 | |||
2403 | 42 | return ret; | ||
2404 | 43 | } | ||
2405 | 44 | |||
2406 | 45 | #include <messagebox.moc> | ||
2407 | 0 | 46 | ||
2408 | === added file 'components/messagebox.h' | |||
2409 | --- components/messagebox.h 1970-01-01 00:00:00 +0000 | |||
2410 | +++ components/messagebox.h 2013-03-01 15:15:27 +0000 | |||
2411 | @@ -0,0 +1,60 @@ | |||
2412 | 1 | /* | ||
2413 | 2 | Copyright 2013 Aurélien Gâteau <agateau@kde.org> | ||
2414 | 3 | |||
2415 | 4 | This program is free software; you can redistribute it and/or | ||
2416 | 5 | modify it under the terms of the GNU General Public License as | ||
2417 | 6 | published by the Free Software Foundation; either version 2 of | ||
2418 | 7 | the License or (at your option) version 3 or any later version | ||
2419 | 8 | accepted by the membership of KDE e.V. (or its successor approved | ||
2420 | 9 | by the membership of KDE e.V.), which shall act as a proxy | ||
2421 | 10 | defined in Section 14 of version 3 of the license. | ||
2422 | 11 | |||
2423 | 12 | This program is distributed in the hope that it will be useful, | ||
2424 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2425 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2426 | 15 | GNU General Public License for more details. | ||
2427 | 16 | |||
2428 | 17 | You should have received a copy of the GNU General Public License | ||
2429 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2430 | 19 | */ | ||
2431 | 20 | #ifndef MESSAGEBOX_H | ||
2432 | 21 | #define MESSAGEBOX_H | ||
2433 | 22 | |||
2434 | 23 | // Local | ||
2435 | 24 | |||
2436 | 25 | // Qt | ||
2437 | 26 | #include <QObject> | ||
2438 | 27 | |||
2439 | 28 | // KDE | ||
2440 | 29 | #include <KMessageBox> | ||
2441 | 30 | |||
2442 | 31 | /** | ||
2443 | 32 | * Wrapper around KMessageBox | ||
2444 | 33 | */ | ||
2445 | 34 | class MessageBox : public QObject | ||
2446 | 35 | { | ||
2447 | 36 | Q_OBJECT | ||
2448 | 37 | Q_ENUMS(ButtonCode) | ||
2449 | 38 | public: | ||
2450 | 39 | explicit MessageBox(QObject *parent = 0); | ||
2451 | 40 | |||
2452 | 41 | enum ButtonCode { | ||
2453 | 42 | Ok = KMessageBox::Ok, | ||
2454 | 43 | Cancel = KMessageBox::Cancel, | ||
2455 | 44 | Yes = KMessageBox::Yes, | ||
2456 | 45 | No = KMessageBox::No, | ||
2457 | 46 | Continue = KMessageBox::Continue, | ||
2458 | 47 | }; | ||
2459 | 48 | |||
2460 | 49 | /** | ||
2461 | 50 | * Return value is a MessageBox::ButtonCode | ||
2462 | 51 | */ | ||
2463 | 52 | Q_INVOKABLE int warningContinueCancel( | ||
2464 | 53 | const QString &text, | ||
2465 | 54 | const QString &caption = QString(), | ||
2466 | 55 | const QString &continueText = QString(), | ||
2467 | 56 | const QString &cancelText = QString() | ||
2468 | 57 | ); | ||
2469 | 58 | }; | ||
2470 | 59 | |||
2471 | 60 | #endif /* MESSAGEBOX_H */ | ||
2472 | 0 | 61 | ||
2473 | === removed file 'components/powermodel.cpp' | |||
2474 | --- components/powermodel.cpp 2012-12-18 19:55:12 +0000 | |||
2475 | +++ components/powermodel.cpp 1970-01-01 00:00:00 +0000 | |||
2476 | @@ -1,143 +0,0 @@ | |||
2477 | 1 | /* | ||
2478 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
2479 | 3 | Copyright (C) 2012 Shaun Reich <shaun.reich@blue-systems.com> | ||
2480 | 4 | |||
2481 | 5 | This library is free software; you can redistribute it and/or | ||
2482 | 6 | modify it under the terms of the GNU Library General Public | ||
2483 | 7 | License as published by the Free Software Foundation; either | ||
2484 | 8 | version 2 of the License, or (at your option) any later version. | ||
2485 | 9 | |||
2486 | 10 | This library is distributed in the hope that it will be useful, | ||
2487 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2488 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2489 | 13 | Library General Public License for more details. | ||
2490 | 14 | |||
2491 | 15 | You should have received a copy of the GNU Library General Public License | ||
2492 | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
2493 | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
2494 | 18 | Boston, MA 02110-1301, USA. | ||
2495 | 19 | */ | ||
2496 | 20 | |||
2497 | 21 | // Own | ||
2498 | 22 | #include "powermodel.h" | ||
2499 | 23 | |||
2500 | 24 | //Qt | ||
2501 | 25 | #include <QDBusMessage> | ||
2502 | 26 | #include <QDBusConnection> | ||
2503 | 27 | #include <QDBusPendingCall> | ||
2504 | 28 | |||
2505 | 29 | // KDE | ||
2506 | 30 | #include <KDebug> | ||
2507 | 31 | #include <KIcon> | ||
2508 | 32 | #include <KLocale> | ||
2509 | 33 | #include <KRun> | ||
2510 | 34 | #include <KService> | ||
2511 | 35 | #include <kworkspace/kworkspace.h> | ||
2512 | 36 | |||
2513 | 37 | //Plasma | ||
2514 | 38 | #include <Plasma/AbstractRunner> | ||
2515 | 39 | #include <Plasma/RunnerManager> | ||
2516 | 40 | |||
2517 | 41 | namespace Homerun { | ||
2518 | 42 | |||
2519 | 43 | PowerModel::PowerModel(QObject *parent) | ||
2520 | 44 | : QAbstractListModel(parent) | ||
2521 | 45 | { | ||
2522 | 46 | PowerAction suspend; | ||
2523 | 47 | suspend.name = i18nc("an action", "Suspend"); | ||
2524 | 48 | suspend.type = Suspend; | ||
2525 | 49 | suspend.iconName = "system-suspend"; | ||
2526 | 50 | m_powerList.append(suspend); | ||
2527 | 51 | |||
2528 | 52 | PowerAction hibernate; | ||
2529 | 53 | hibernate.name = i18nc("an action", "Hibernate"); | ||
2530 | 54 | hibernate.type = Hibernate; | ||
2531 | 55 | hibernate.iconName = "system-suspend-hibernate"; | ||
2532 | 56 | m_powerList.append(hibernate); | ||
2533 | 57 | |||
2534 | 58 | PowerAction restart; | ||
2535 | 59 | restart.name = i18nc("an action", "Restart"); | ||
2536 | 60 | restart.type = Restart; | ||
2537 | 61 | restart.iconName = "system-reboot"; | ||
2538 | 62 | m_powerList.append(restart); | ||
2539 | 63 | |||
2540 | 64 | PowerAction shutdown; | ||
2541 | 65 | shutdown.name = i18nc("an action", "Shutdown"); | ||
2542 | 66 | shutdown.type = Shutdown; | ||
2543 | 67 | shutdown.iconName = "system-shutdown"; | ||
2544 | 68 | m_powerList.append(shutdown); | ||
2545 | 69 | } | ||
2546 | 70 | |||
2547 | 71 | PowerModel::~PowerModel() | ||
2548 | 72 | { | ||
2549 | 73 | } | ||
2550 | 74 | |||
2551 | 75 | int PowerModel::count() const | ||
2552 | 76 | { | ||
2553 | 77 | return m_powerList.count(); | ||
2554 | 78 | } | ||
2555 | 79 | |||
2556 | 80 | QString PowerModel::name() const | ||
2557 | 81 | { | ||
2558 | 82 | return i18n("Power"); | ||
2559 | 83 | } | ||
2560 | 84 | |||
2561 | 85 | int PowerModel::rowCount(const QModelIndex &index) const | ||
2562 | 86 | { | ||
2563 | 87 | if (index.isValid()) { | ||
2564 | 88 | return 0; | ||
2565 | 89 | } | ||
2566 | 90 | return m_powerList.count(); | ||
2567 | 91 | } | ||
2568 | 92 | |||
2569 | 93 | QVariant PowerModel::data(const QModelIndex &index, int role) const | ||
2570 | 94 | { | ||
2571 | 95 | PowerAction action = m_powerList.value(index.row()); | ||
2572 | 96 | |||
2573 | 97 | if (role == Qt::DisplayRole) { | ||
2574 | 98 | return action.name; | ||
2575 | 99 | } else if (role == Qt::DecorationRole) { | ||
2576 | 100 | return KIcon(action.iconName); | ||
2577 | 101 | } else { | ||
2578 | 102 | kWarning() << "Unhandled role" << role; | ||
2579 | 103 | return QVariant(); | ||
2580 | 104 | } | ||
2581 | 105 | } | ||
2582 | 106 | |||
2583 | 107 | bool PowerModel::trigger(int row) | ||
2584 | 108 | { | ||
2585 | 109 | PowerAction action = m_powerList.value(row); | ||
2586 | 110 | |||
2587 | 111 | switch (action.type) { | ||
2588 | 112 | case Shutdown: | ||
2589 | 113 | KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeHalt); | ||
2590 | 114 | break; | ||
2591 | 115 | |||
2592 | 116 | case Restart: | ||
2593 | 117 | KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeReboot); | ||
2594 | 118 | break; | ||
2595 | 119 | |||
2596 | 120 | case Suspend: | ||
2597 | 121 | suspend("suspendToRam"); | ||
2598 | 122 | break; | ||
2599 | 123 | |||
2600 | 124 | case Hibernate: | ||
2601 | 125 | suspend("suspendToDisk"); | ||
2602 | 126 | break; | ||
2603 | 127 | } | ||
2604 | 128 | |||
2605 | 129 | return true; | ||
2606 | 130 | } | ||
2607 | 131 | |||
2608 | 132 | void PowerModel::suspend(const QString& type) | ||
2609 | 133 | { | ||
2610 | 134 | QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement", | ||
2611 | 135 | "/org/kde/Solid/PowerManagement", | ||
2612 | 136 | "org.kde.Solid.PowerManagement", | ||
2613 | 137 | type); | ||
2614 | 138 | QDBusConnection::sessionBus().asyncCall(msg); | ||
2615 | 139 | } | ||
2616 | 140 | |||
2617 | 141 | } // namespace Homerun | ||
2618 | 142 | |||
2619 | 143 | #include "powermodel.moc" | ||
2620 | 144 | 0 | ||
2621 | === removed file 'components/powermodel.h' | |||
2622 | --- components/powermodel.h 2012-11-14 21:30:06 +0000 | |||
2623 | +++ components/powermodel.h 1970-01-01 00:00:00 +0000 | |||
2624 | @@ -1,75 +0,0 @@ | |||
2625 | 1 | /* | ||
2626 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
2627 | 3 | Copyright 2012 (C) Shaun Reich <shaun.reich@blue-systems.com> | ||
2628 | 4 | |||
2629 | 5 | This library is free software; you can redistribute it and/or | ||
2630 | 6 | modify it under the terms of the GNU Library General Public | ||
2631 | 7 | License as published by the Free Software Foundation; either | ||
2632 | 8 | version 2 of the License, or (at your option) any later version. | ||
2633 | 9 | |||
2634 | 10 | This library is distributed in the hope that it will be useful, | ||
2635 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2636 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2637 | 13 | Library General Public License for more details. | ||
2638 | 14 | |||
2639 | 15 | You should have received a copy of the GNU Library General Public License | ||
2640 | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
2641 | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
2642 | 18 | Boston, MA 02110-1301, USA. | ||
2643 | 19 | */ | ||
2644 | 20 | |||
2645 | 21 | #ifndef POWERMODEL_H | ||
2646 | 22 | #define POWERMODEL_H | ||
2647 | 23 | |||
2648 | 24 | #include <QAbstractListModel> | ||
2649 | 25 | |||
2650 | 26 | #include <KService> | ||
2651 | 27 | |||
2652 | 28 | class QString; | ||
2653 | 29 | |||
2654 | 30 | namespace Homerun { | ||
2655 | 31 | |||
2656 | 32 | enum PowerType { | ||
2657 | 33 | Shutdown, | ||
2658 | 34 | Restart, | ||
2659 | 35 | Hibernate, | ||
2660 | 36 | Suspend | ||
2661 | 37 | }; | ||
2662 | 38 | |||
2663 | 39 | struct PowerAction | ||
2664 | 40 | { | ||
2665 | 41 | QString name; | ||
2666 | 42 | QString iconName; | ||
2667 | 43 | PowerType type; | ||
2668 | 44 | }; | ||
2669 | 45 | |||
2670 | 46 | class PowerModel : public QAbstractListModel | ||
2671 | 47 | { | ||
2672 | 48 | Q_OBJECT | ||
2673 | 49 | Q_PROPERTY(QString name READ name CONSTANT) | ||
2674 | 50 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
2675 | 51 | |||
2676 | 52 | public: | ||
2677 | 53 | PowerModel(QObject *parent = 0); | ||
2678 | 54 | ~PowerModel(); | ||
2679 | 55 | |||
2680 | 56 | int count() const; | ||
2681 | 57 | QString name() const; | ||
2682 | 58 | |||
2683 | 59 | int rowCount(const QModelIndex & = QModelIndex()) const; | ||
2684 | 60 | QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const; | ||
2685 | 61 | |||
2686 | 62 | Q_INVOKABLE bool trigger(int row); | ||
2687 | 63 | |||
2688 | 64 | void suspend(const QString& type); | ||
2689 | 65 | |||
2690 | 66 | Q_SIGNALS: | ||
2691 | 67 | void countChanged(); | ||
2692 | 68 | |||
2693 | 69 | private: | ||
2694 | 70 | QList<PowerAction> m_powerList; | ||
2695 | 71 | }; | ||
2696 | 72 | |||
2697 | 73 | } // namespace Homerun | ||
2698 | 74 | |||
2699 | 75 | #endif | ||
2700 | 76 | 0 | ||
2701 | === added file 'components/qml/Label.qml' | |||
2702 | --- components/qml/Label.qml 1970-01-01 00:00:00 +0000 | |||
2703 | +++ components/qml/Label.qml 2013-03-01 15:15:27 +0000 | |||
2704 | @@ -0,0 +1,68 @@ | |||
2705 | 1 | /* | ||
2706 | 2 | Copyright 2013 Aurélien Gâteau <agateau@kde.org> | ||
2707 | 3 | |||
2708 | 4 | This program is free software; you can redistribute it and/or | ||
2709 | 5 | modify it under the terms of the GNU General Public License as | ||
2710 | 6 | published by the Free Software Foundation; either version 2 of | ||
2711 | 7 | the License or (at your option) version 3 or any later version | ||
2712 | 8 | accepted by the membership of KDE e.V. (or its successor approved | ||
2713 | 9 | by the membership of KDE e.V.), which shall act as a proxy | ||
2714 | 10 | defined in Section 14 of version 3 of the license. | ||
2715 | 11 | |||
2716 | 12 | This program is distributed in the hope that it will be useful, | ||
2717 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2718 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2719 | 15 | GNU General Public License for more details. | ||
2720 | 16 | |||
2721 | 17 | You should have received a copy of the GNU General Public License | ||
2722 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2723 | 19 | */ | ||
2724 | 20 | import QtQuick 1.1 | ||
2725 | 21 | import org.kde.homerun.components 0.1 as HomerunComponents | ||
2726 | 22 | import org.kde.plasma.components 0.1 as PlasmaComponents | ||
2727 | 23 | |||
2728 | 24 | /** | ||
2729 | 25 | * A label which uses Plasma colors by default, but appears differently when | ||
2730 | 26 | * run as a containment: it shows a shadow behind itself and both shadow and | ||
2731 | 27 | * text colors can be customized. | ||
2732 | 28 | */ | ||
2733 | 29 | PlasmaComponents.Label { | ||
2734 | 30 | id: main | ||
2735 | 31 | |||
2736 | 32 | Component { | ||
2737 | 33 | id: shadowComponent | ||
2738 | 34 | HomerunComponents.ShadowEffect { | ||
2739 | 35 | xOffset: 0 | ||
2740 | 36 | yOffset: 1 | ||
2741 | 37 | blurRadius: 2 | ||
2742 | 38 | } | ||
2743 | 39 | } | ||
2744 | 40 | |||
2745 | 41 | Component.onCompleted: { | ||
2746 | 42 | var isContainment = "plasmoid" in this; | ||
2747 | 43 | if (isContainment) { | ||
2748 | 44 | readConfig(); | ||
2749 | 45 | plasmoid.addEventListener("ConfigChanged", readConfig); | ||
2750 | 46 | } else { | ||
2751 | 47 | main.color = theme.textColor; | ||
2752 | 48 | } | ||
2753 | 49 | } | ||
2754 | 50 | |||
2755 | 51 | function readConfig() { | ||
2756 | 52 | main.color = plasmoid.readConfig("textColor"); | ||
2757 | 53 | if (plasmoid.readConfig("shadowModeNone") == true) { | ||
2758 | 54 | if (main.effect) { | ||
2759 | 55 | main.effect.destroy(); | ||
2760 | 56 | } | ||
2761 | 57 | return; | ||
2762 | 58 | } | ||
2763 | 59 | if (!main.effect) { | ||
2764 | 60 | main.effect = shadowComponent.createObject(main); | ||
2765 | 61 | } | ||
2766 | 62 | if (plasmoid.readConfig("shadowModeCustom") == true) { | ||
2767 | 63 | main.effect.color = plasmoid.readConfig("shadowColor"); | ||
2768 | 64 | } else { | ||
2769 | 65 | main.effect.resetColor(); | ||
2770 | 66 | } | ||
2771 | 67 | } | ||
2772 | 68 | } | ||
2773 | 0 | 69 | ||
2774 | === modified file 'components/qml/TabButton.qml' | |||
2775 | --- components/qml/TabButton.qml 2012-11-14 21:30:06 +0000 | |||
2776 | +++ components/qml/TabButton.qml 2013-03-01 15:15:27 +0000 | |||
2777 | @@ -81,7 +81,7 @@ | |||
2778 | 81 | **/ | 81 | **/ |
2779 | 82 | 82 | ||
2780 | 83 | import QtQuick 1.1 | 83 | import QtQuick 1.1 |
2782 | 84 | import org.kde.plasma.components 0.1 | 84 | import org.kde.plasma.components 0.1 as PlasmaComponents |
2783 | 85 | import "private" as Private | 85 | import "private" as Private |
2784 | 86 | 86 | ||
2785 | 87 | Item { | 87 | Item { |
2786 | @@ -127,6 +127,15 @@ | |||
2787 | 127 | } | 127 | } |
2788 | 128 | } | 128 | } |
2789 | 129 | 129 | ||
2790 | 130 | /* | ||
2791 | 131 | HACK: We use a HomerunComponents.Label for the normal text and | ||
2792 | 132 | a PlasmaComponents.Label for the current text. | ||
2793 | 133 | |||
2794 | 134 | This is necessary for containment mode: | ||
2795 | 135 | It makes it possible to have custom color + shadow for normal text (to | ||
2796 | 136 | ensure it remains readable) and buttonTextColor + no-shadow for button text | ||
2797 | 137 | (because it is drawn on top of a button frame) | ||
2798 | 138 | */ | ||
2799 | 130 | Label { | 139 | Label { |
2800 | 131 | id: label | 140 | id: label |
2801 | 132 | 141 | ||
2802 | @@ -144,7 +153,24 @@ | |||
2803 | 144 | horizontalAlignment: Text.AlignLeft | 153 | horizontalAlignment: Text.AlignLeft |
2804 | 145 | verticalAlignment: Text.AlignVCenter | 154 | verticalAlignment: Text.AlignVCenter |
2805 | 146 | 155 | ||
2807 | 147 | color: root.ListView.isCurrentItem ? theme.buttonTextColor : theme.textColor | 156 | color: theme.textColor |
2808 | 157 | opacity: root.ListView.isCurrentItem ? 0 : 1 | ||
2809 | 158 | Behavior on opacity { NumberAnimation { duration: 250 }} | ||
2810 | 159 | } | ||
2811 | 160 | |||
2812 | 161 | PlasmaComponents.Label { | ||
2813 | 162 | id: currentLabel | ||
2814 | 163 | text: label.text | ||
2815 | 164 | |||
2816 | 165 | anchors.fill: label | ||
2817 | 166 | |||
2818 | 167 | elide: label.elide | ||
2819 | 168 | horizontalAlignment: label.horizontalAlignment | ||
2820 | 169 | verticalAlignment: label.verticalAlignment | ||
2821 | 170 | |||
2822 | 171 | color: theme.buttonTextColor | ||
2823 | 172 | opacity: root.ListView.isCurrentItem ? 1 : 0 | ||
2824 | 173 | Behavior on opacity { NumberAnimation { duration: 250 }} | ||
2825 | 148 | } | 174 | } |
2826 | 149 | 175 | ||
2827 | 150 | MouseArea { | 176 | MouseArea { |
2828 | 151 | 177 | ||
2829 | === modified file 'components/qml/qmldir' | |||
2830 | --- components/qml/qmldir 2012-11-14 21:30:06 +0000 | |||
2831 | +++ components/qml/qmldir 2013-03-01 15:15:27 +0000 | |||
2832 | @@ -3,3 +3,4 @@ | |||
2833 | 3 | TabBar 0.1 TabBar.qml | 3 | TabBar 0.1 TabBar.qml |
2834 | 4 | TabButton 0.1 TabButton.qml | 4 | TabButton 0.1 TabButton.qml |
2835 | 5 | TabGroup 0.1 TabGroup.qml | 5 | TabGroup 0.1 TabGroup.qml |
2836 | 6 | Label 0.1 Label.qml | ||
2837 | 6 | 7 | ||
2838 | === removed file 'components/runnerconfigurationwidget.cpp' | |||
2839 | --- components/runnerconfigurationwidget.cpp 2012-11-14 21:30:06 +0000 | |||
2840 | +++ components/runnerconfigurationwidget.cpp 1970-01-01 00:00:00 +0000 | |||
2841 | @@ -1,105 +0,0 @@ | |||
2842 | 1 | /* | ||
2843 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
2844 | 3 | |||
2845 | 4 | This library is free software; you can redistribute it and/or | ||
2846 | 5 | modify it under the terms of the GNU Lesser General Public | ||
2847 | 6 | License as published by the Free Software Foundation; either | ||
2848 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
2849 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
2850 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
2851 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
2852 | 11 | |||
2853 | 12 | This library is distributed in the hope that it will be useful, | ||
2854 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2855 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2856 | 15 | Lesser General Public License for more details. | ||
2857 | 16 | |||
2858 | 17 | You should have received a copy of the GNU Lesser General Public | ||
2859 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
2860 | 19 | */ | ||
2861 | 20 | // Self | ||
2862 | 21 | #include <runnerconfigurationwidget.h> | ||
2863 | 22 | |||
2864 | 23 | // Local | ||
2865 | 24 | |||
2866 | 25 | // KDE | ||
2867 | 26 | #include <KDebug> | ||
2868 | 27 | #include <KPluginInfo> | ||
2869 | 28 | #include <Plasma/RunnerManager> | ||
2870 | 29 | |||
2871 | 30 | // Qt | ||
2872 | 31 | #include <QListWidgetItem> | ||
2873 | 32 | |||
2874 | 33 | Q_DECLARE_METATYPE(KPluginInfo) | ||
2875 | 34 | |||
2876 | 35 | static const char *WHITELIST_KEY = "whitelist"; | ||
2877 | 36 | |||
2878 | 37 | namespace Homerun | ||
2879 | 38 | { | ||
2880 | 39 | |||
2881 | 40 | static QListWidgetItem *createWidgetItem(const KPluginInfo &info) | ||
2882 | 41 | { | ||
2883 | 42 | QListWidgetItem *item = new QListWidgetItem(info.name()); | ||
2884 | 43 | item->setIcon(KIcon(info.icon())); | ||
2885 | 44 | item->setFlags(item->flags() | Qt::ItemIsUserCheckable); | ||
2886 | 45 | item->setData(Qt::UserRole, QVariant::fromValue(info)); | ||
2887 | 46 | return item; | ||
2888 | 47 | } | ||
2889 | 48 | |||
2890 | 49 | RunnerConfigurationWidget::RunnerConfigurationWidget(const KConfigGroup &group) | ||
2891 | 50 | : SourceConfigurationWidget(group) | ||
2892 | 51 | { | ||
2893 | 52 | setupUi(this); | ||
2894 | 53 | m_searchLine->setListWidget(m_listWidget); | ||
2895 | 54 | |||
2896 | 55 | // A runner is enabled if there is either a whitelist and it is part of it | ||
2897 | 56 | // or if there is no whitelist and its EnabledByDefault key is true | ||
2898 | 57 | |||
2899 | 58 | QStringList whiteList = group.readEntry(WHITELIST_KEY, QStringList()); | ||
2900 | 59 | bool hasWhiteList = !whiteList.isEmpty(); | ||
2901 | 60 | |||
2902 | 61 | KPluginInfo::List list = Plasma::RunnerManager::listRunnerInfo(); | ||
2903 | 62 | Q_FOREACH(const KPluginInfo &info, list) { | ||
2904 | 63 | QListWidgetItem *item = createWidgetItem(info); | ||
2905 | 64 | bool selected; | ||
2906 | 65 | if (hasWhiteList) { | ||
2907 | 66 | selected = whiteList.contains(info.pluginName()); | ||
2908 | 67 | } else { | ||
2909 | 68 | selected = info.isPluginEnabledByDefault(); | ||
2910 | 69 | } | ||
2911 | 70 | item->setCheckState(selected ? Qt::Checked : Qt::Unchecked); | ||
2912 | 71 | m_listWidget->addItem(item); | ||
2913 | 72 | } | ||
2914 | 73 | m_listWidget->sortItems(); | ||
2915 | 74 | } | ||
2916 | 75 | |||
2917 | 76 | void RunnerConfigurationWidget::save() | ||
2918 | 77 | { | ||
2919 | 78 | QStringList whiteList; | ||
2920 | 79 | bool hasChanges = false; | ||
2921 | 80 | |||
2922 | 81 | // Only write a whiteList if the selected runner list is not the same as | ||
2923 | 82 | // the list of all EnabledByDefault runners | ||
2924 | 83 | |||
2925 | 84 | for (int idx = 0; idx < m_listWidget->count(); ++idx) { | ||
2926 | 85 | QListWidgetItem *item = m_listWidget->item(idx); | ||
2927 | 86 | KPluginInfo info = item->data(Qt::UserRole).value<KPluginInfo>(); | ||
2928 | 87 | |||
2929 | 88 | bool selected = item->checkState() == Qt::Checked; | ||
2930 | 89 | if (selected != info.isPluginEnabledByDefault()) { | ||
2931 | 90 | hasChanges = true; | ||
2932 | 91 | } | ||
2933 | 92 | if (selected) { | ||
2934 | 93 | whiteList << info.pluginName(); | ||
2935 | 94 | } | ||
2936 | 95 | } | ||
2937 | 96 | if (hasChanges) { | ||
2938 | 97 | configGroup().writeEntry(WHITELIST_KEY, whiteList); | ||
2939 | 98 | } else { | ||
2940 | 99 | configGroup().deleteEntry(WHITELIST_KEY); | ||
2941 | 100 | } | ||
2942 | 101 | } | ||
2943 | 102 | |||
2944 | 103 | } // namespace Homerun | ||
2945 | 104 | |||
2946 | 105 | #include <runnerconfigurationwidget.moc> | ||
2947 | 106 | 0 | ||
2948 | === removed file 'components/runnerconfigurationwidget.h' | |||
2949 | --- components/runnerconfigurationwidget.h 2012-11-14 21:30:06 +0000 | |||
2950 | +++ components/runnerconfigurationwidget.h 1970-01-01 00:00:00 +0000 | |||
2951 | @@ -1,48 +0,0 @@ | |||
2952 | 1 | /* | ||
2953 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
2954 | 3 | |||
2955 | 4 | This library is free software; you can redistribute it and/or | ||
2956 | 5 | modify it under the terms of the GNU Lesser General Public | ||
2957 | 6 | License as published by the Free Software Foundation; either | ||
2958 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
2959 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
2960 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
2961 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
2962 | 11 | |||
2963 | 12 | This library is distributed in the hope that it will be useful, | ||
2964 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2965 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2966 | 15 | Lesser General Public License for more details. | ||
2967 | 16 | |||
2968 | 17 | You should have received a copy of the GNU Lesser General Public | ||
2969 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
2970 | 19 | */ | ||
2971 | 20 | #ifndef RUNNERCONFIGURATIONWIDGET_H | ||
2972 | 21 | #define RUNNERCONFIGURATIONWIDGET_H | ||
2973 | 22 | |||
2974 | 23 | // Local | ||
2975 | 24 | #include <sourceconfigurationwidget.h> | ||
2976 | 25 | #include <ui_runnerconfigurationwidget.h> | ||
2977 | 26 | |||
2978 | 27 | // Qt | ||
2979 | 28 | |||
2980 | 29 | // KDE | ||
2981 | 30 | |||
2982 | 31 | namespace Homerun | ||
2983 | 32 | { | ||
2984 | 33 | |||
2985 | 34 | /** | ||
2986 | 35 | * A configuration widget for the Runner source | ||
2987 | 36 | */ | ||
2988 | 37 | class RunnerConfigurationWidget : public SourceConfigurationWidget, private Ui_RunnerConfigurationWidget | ||
2989 | 38 | { | ||
2990 | 39 | Q_OBJECT | ||
2991 | 40 | public: | ||
2992 | 41 | explicit RunnerConfigurationWidget(const KConfigGroup &); | ||
2993 | 42 | |||
2994 | 43 | void save(); // reimp | ||
2995 | 44 | }; | ||
2996 | 45 | |||
2997 | 46 | } // namespace | ||
2998 | 47 | |||
2999 | 48 | #endif /* RUNNERCONFIGURATIONWIDGET_H */ | ||
3000 | 49 | 0 | ||
3001 | === removed file 'components/runnerconfigurationwidget.ui' | |||
3002 | --- components/runnerconfigurationwidget.ui 2012-11-14 21:30:06 +0000 | |||
3003 | +++ components/runnerconfigurationwidget.ui 1970-01-01 00:00:00 +0000 | |||
3004 | @@ -1,48 +0,0 @@ | |||
3005 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
3006 | 2 | <ui version="4.0"> | ||
3007 | 3 | <class>RunnerConfigurationWidget</class> | ||
3008 | 4 | <widget class="QWidget" name="RunnerConfigurationWidget"> | ||
3009 | 5 | <property name="geometry"> | ||
3010 | 6 | <rect> | ||
3011 | 7 | <x>0</x> | ||
3012 | 8 | <y>0</y> | ||
3013 | 9 | <width>400</width> | ||
3014 | 10 | <height>300</height> | ||
3015 | 11 | </rect> | ||
3016 | 12 | </property> | ||
3017 | 13 | <layout class="QVBoxLayout" name="verticalLayout"> | ||
3018 | 14 | <item> | ||
3019 | 15 | <widget class="QLabel" name="label"> | ||
3020 | 16 | <property name="text"> | ||
3021 | 17 | <string>Pick the runners you would like to use in this source:</string> | ||
3022 | 18 | </property> | ||
3023 | 19 | </widget> | ||
3024 | 20 | </item> | ||
3025 | 21 | <item> | ||
3026 | 22 | <widget class="KListWidgetSearchLine" name="m_searchLine"/> | ||
3027 | 23 | </item> | ||
3028 | 24 | <item> | ||
3029 | 25 | <widget class="KListWidget" name="m_listWidget"/> | ||
3030 | 26 | </item> | ||
3031 | 27 | </layout> | ||
3032 | 28 | </widget> | ||
3033 | 29 | <customwidgets> | ||
3034 | 30 | <customwidget> | ||
3035 | 31 | <class>KListWidgetSearchLine</class> | ||
3036 | 32 | <extends>KLineEdit</extends> | ||
3037 | 33 | <header>klistwidgetsearchline.h</header> | ||
3038 | 34 | </customwidget> | ||
3039 | 35 | <customwidget> | ||
3040 | 36 | <class>KLineEdit</class> | ||
3041 | 37 | <extends>QLineEdit</extends> | ||
3042 | 38 | <header>klineedit.h</header> | ||
3043 | 39 | </customwidget> | ||
3044 | 40 | <customwidget> | ||
3045 | 41 | <class>KListWidget</class> | ||
3046 | 42 | <extends>QListWidget</extends> | ||
3047 | 43 | <header>klistwidget.h</header> | ||
3048 | 44 | </customwidget> | ||
3049 | 45 | </customwidgets> | ||
3050 | 46 | <resources/> | ||
3051 | 47 | <connections/> | ||
3052 | 48 | </ui> | ||
3053 | 49 | 0 | ||
3054 | === removed file 'components/runnermodel.cpp' | |||
3055 | --- components/runnermodel.cpp 2012-11-14 21:30:06 +0000 | |||
3056 | +++ components/runnermodel.cpp 1970-01-01 00:00:00 +0000 | |||
3057 | @@ -1,408 +0,0 @@ | |||
3058 | 1 | /* | ||
3059 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
3060 | 3 | |||
3061 | 4 | Based on RunnerModel class. RunnerModel class copyright: | ||
3062 | 5 | |||
3063 | 6 | Copyright 2011 Aaron Seigo <aseigo@kde.org> | ||
3064 | 7 | |||
3065 | 8 | This library is free software; you can redistribute it and/or | ||
3066 | 9 | modify it under the terms of the GNU Library General Public | ||
3067 | 10 | License as published by the Free Software Foundation; either | ||
3068 | 11 | version 2 of the License, or (at your option) any later version. | ||
3069 | 12 | |||
3070 | 13 | This library is distributed in the hope that it will be useful, | ||
3071 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3072 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3073 | 16 | Library General Public License for more details. | ||
3074 | 17 | |||
3075 | 18 | You should have received a copy of the GNU Library General Public License | ||
3076 | 19 | along with this library; see the file COPYING.LIB. If not, write to | ||
3077 | 20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
3078 | 21 | Boston, MA 02110-1301, USA. | ||
3079 | 22 | */ | ||
3080 | 23 | // Self | ||
3081 | 24 | #include <runnermodel.h> | ||
3082 | 25 | |||
3083 | 26 | // Local | ||
3084 | 27 | #include <runnerconfigurationwidget.h> | ||
3085 | 28 | |||
3086 | 29 | // KDE | ||
3087 | 30 | #include <KDebug> | ||
3088 | 31 | #include <KPluginInfo> | ||
3089 | 32 | #include <Plasma/AbstractRunner> | ||
3090 | 33 | #include <Plasma/RunnerManager> | ||
3091 | 34 | |||
3092 | 35 | // Qt | ||
3093 | 36 | #include <QStandardItemModel> | ||
3094 | 37 | #include <QTimer> | ||
3095 | 38 | |||
3096 | 39 | static const char *WHITELIST_KEY = "whitelist"; | ||
3097 | 40 | |||
3098 | 41 | namespace Homerun { | ||
3099 | 42 | |||
3100 | 43 | RunnerSubModel::RunnerSubModel(const QString &runnerId, const QString &name, QObject *parent) | ||
3101 | 44 | : QAbstractListModel(parent) | ||
3102 | 45 | , m_runnerId(runnerId) | ||
3103 | 46 | , m_name(name) | ||
3104 | 47 | { | ||
3105 | 48 | QHash<int, QByteArray> roles; | ||
3106 | 49 | roles.insert(Qt::DisplayRole, "display"); | ||
3107 | 50 | roles.insert(Qt::DecorationRole, "decoration"); | ||
3108 | 51 | roles.insert(FavoriteIdRole, "favoriteId"); | ||
3109 | 52 | /* | ||
3110 | 53 | roles.insert(Type, "type"); | ||
3111 | 54 | roles.insert(Relevance, "relevance"); | ||
3112 | 55 | roles.insert(Data, "data"); | ||
3113 | 56 | roles.insert(Id, "id"); | ||
3114 | 57 | roles.insert(SubText, "description"); | ||
3115 | 58 | roles.insert(Enabled, "enabled"); | ||
3116 | 59 | roles.insert(RunnerId, "runnerid"); | ||
3117 | 60 | roles.insert(RunnerName, "runnerName"); | ||
3118 | 61 | roles.insert(Actions, "actions"); | ||
3119 | 62 | */ | ||
3120 | 63 | setRoleNames(roles); | ||
3121 | 64 | } | ||
3122 | 65 | |||
3123 | 66 | int RunnerSubModel::count() const | ||
3124 | 67 | { | ||
3125 | 68 | return m_matches.count(); | ||
3126 | 69 | } | ||
3127 | 70 | |||
3128 | 71 | int RunnerSubModel::rowCount(const QModelIndex& parent) const | ||
3129 | 72 | { | ||
3130 | 73 | return parent.isValid() ? 0 : m_matches.count(); | ||
3131 | 74 | } | ||
3132 | 75 | |||
3133 | 76 | QVariant RunnerSubModel::data(const QModelIndex &index, int role) const | ||
3134 | 77 | { | ||
3135 | 78 | if (!index.isValid() || index.parent().isValid() || | ||
3136 | 79 | index.column() > 0 || index.row() < 0 || index.row() >= m_matches.count()) { | ||
3137 | 80 | // index requested must be valid, but we have no child items! | ||
3138 | 81 | //kDebug() << "invalid index requested"; | ||
3139 | 82 | return QVariant(); | ||
3140 | 83 | } | ||
3141 | 84 | |||
3142 | 85 | const Plasma::QueryMatch &match = m_matches.at(index.row()); | ||
3143 | 86 | if (role == Qt::DisplayRole) { | ||
3144 | 87 | return match.text(); | ||
3145 | 88 | } else if (role == Qt::DecorationRole) { | ||
3146 | 89 | return match.icon(); | ||
3147 | 90 | } else if (role == FavoriteIdRole) { | ||
3148 | 91 | QString runnerId = match.runner()->id(); | ||
3149 | 92 | if (runnerId == "services") { | ||
3150 | 93 | return QVariant("app:" + match.data().toString()); | ||
3151 | 94 | } else if (runnerId == "locations") { | ||
3152 | 95 | KUrl url(match.data().toString()); | ||
3153 | 96 | return QVariant("place:" + url.url()); | ||
3154 | 97 | } else { | ||
3155 | 98 | return QString(); | ||
3156 | 99 | } | ||
3157 | 100 | } /*else if (role == Type) { | ||
3158 | 101 | return m_matches.at(index.row()).type(); | ||
3159 | 102 | } else if (role == Relevance) { | ||
3160 | 103 | return m_matches.at(index.row()).relevance(); | ||
3161 | 104 | } else if (role == Data) { | ||
3162 | 105 | return m_matches.at(index.row()).data(); | ||
3163 | 106 | } else if (role == Id) { | ||
3164 | 107 | return m_matches.at(index.row()).id(); | ||
3165 | 108 | } else if (role == SubText) { | ||
3166 | 109 | return m_matches.at(index.row()).subtext(); | ||
3167 | 110 | } else if (role == Enabled) { | ||
3168 | 111 | return m_matches.at(index.row()).isEnabled(); | ||
3169 | 112 | } else if (role == RunnerId) { | ||
3170 | 113 | return m_matches.at(index.row()).runner()->id(); | ||
3171 | 114 | } else if (role == RunnerName) { | ||
3172 | 115 | return m_matches.at(index.row()).runner()->name(); | ||
3173 | 116 | } else if (role == Actions) { | ||
3174 | 117 | QVariantList actions; | ||
3175 | 118 | Plasma::QueryMatch amatch = m_matches.at(index.row()); | ||
3176 | 119 | QList<QAction*> theactions = m_manager->actionsForMatch(amatch); | ||
3177 | 120 | foreach(QAction* action, theactions) { | ||
3178 | 121 | actions += qVariantFromValue<QObject*>(action); | ||
3179 | 122 | } | ||
3180 | 123 | return actions; | ||
3181 | 124 | }*/ | ||
3182 | 125 | |||
3183 | 126 | return QVariant(); | ||
3184 | 127 | } | ||
3185 | 128 | |||
3186 | 129 | void RunnerSubModel::setMatches(const QList<Plasma::QueryMatch> &matches) | ||
3187 | 130 | { | ||
3188 | 131 | bool fullReset = false; | ||
3189 | 132 | int oldCount = m_matches.count(); | ||
3190 | 133 | int newCount = matches.count(); | ||
3191 | 134 | if (newCount > oldCount) { | ||
3192 | 135 | // We received more matches than we had. If all common matches are the | ||
3193 | 136 | // same, we can just append new matches instead of resetting the whole | ||
3194 | 137 | // model | ||
3195 | 138 | for (int row = 0; row < oldCount; ++row) { | ||
3196 | 139 | if (!(m_matches.at(row) == matches.at(row))) { | ||
3197 | 140 | fullReset = true; | ||
3198 | 141 | break; | ||
3199 | 142 | } | ||
3200 | 143 | } | ||
3201 | 144 | if (!fullReset) { | ||
3202 | 145 | // Not a full reset, inserting rows | ||
3203 | 146 | beginInsertRows(QModelIndex(), oldCount, newCount); | ||
3204 | 147 | m_matches = matches; | ||
3205 | 148 | endInsertRows(); | ||
3206 | 149 | emit countChanged(); | ||
3207 | 150 | } | ||
3208 | 151 | } else { | ||
3209 | 152 | fullReset = true; | ||
3210 | 153 | } | ||
3211 | 154 | |||
3212 | 155 | if (fullReset) { | ||
3213 | 156 | beginResetModel(); | ||
3214 | 157 | m_matches = matches; | ||
3215 | 158 | endResetModel(); | ||
3216 | 159 | emit countChanged(); | ||
3217 | 160 | } | ||
3218 | 161 | } | ||
3219 | 162 | |||
3220 | 163 | bool RunnerSubModel::trigger(int row) | ||
3221 | 164 | { | ||
3222 | 165 | if (row >= 0 && row < m_matches.count()) { | ||
3223 | 166 | triggerRequested(m_matches.at(row)); | ||
3224 | 167 | } | ||
3225 | 168 | return true; | ||
3226 | 169 | } | ||
3227 | 170 | |||
3228 | 171 | //-------------------------------------------------------------------- | ||
3229 | 172 | |||
3230 | 173 | RunnerModel::RunnerModel(QObject *parent) | ||
3231 | 174 | : QAbstractListModel(parent) | ||
3232 | 175 | , m_manager(0) | ||
3233 | 176 | , m_startQueryTimer(new QTimer(this)) | ||
3234 | 177 | , m_runningChangedTimeout(new QTimer(this)) | ||
3235 | 178 | , m_running(false) | ||
3236 | 179 | { | ||
3237 | 180 | m_startQueryTimer->setSingleShot(true); | ||
3238 | 181 | m_startQueryTimer->setInterval(10); | ||
3239 | 182 | connect(m_startQueryTimer, SIGNAL(timeout()), this, SLOT(startQuery())); | ||
3240 | 183 | |||
3241 | 184 | //FIXME: HACK: some runners stay in a running but finished state, not possible to say if it's actually over | ||
3242 | 185 | m_runningChangedTimeout->setSingleShot(true); | ||
3243 | 186 | connect(m_runningChangedTimeout, SIGNAL(timeout()), this, SLOT(queryHasFinished())); | ||
3244 | 187 | } | ||
3245 | 188 | |||
3246 | 189 | RunnerModel::~RunnerModel() | ||
3247 | 190 | { | ||
3248 | 191 | } | ||
3249 | 192 | |||
3250 | 193 | int RunnerModel::rowCount(const QModelIndex &parent) const | ||
3251 | 194 | { | ||
3252 | 195 | if (parent.isValid()) { | ||
3253 | 196 | return 0; | ||
3254 | 197 | } | ||
3255 | 198 | return m_models.count(); | ||
3256 | 199 | } | ||
3257 | 200 | |||
3258 | 201 | QVariant RunnerModel::data(const QModelIndex &index, int role) const | ||
3259 | 202 | { | ||
3260 | 203 | if (index.parent().isValid()) { | ||
3261 | 204 | return QVariant(); | ||
3262 | 205 | } | ||
3263 | 206 | |||
3264 | 207 | RunnerSubModel *model = m_models.value(index.row()); | ||
3265 | 208 | if (!model) { | ||
3266 | 209 | return QVariant(); | ||
3267 | 210 | } | ||
3268 | 211 | |||
3269 | 212 | if (role == Qt::DisplayRole) { | ||
3270 | 213 | return model->name(); | ||
3271 | 214 | } else { | ||
3272 | 215 | return QVariant(); | ||
3273 | 216 | } | ||
3274 | 217 | } | ||
3275 | 218 | |||
3276 | 219 | bool RunnerModel::running() const | ||
3277 | 220 | { | ||
3278 | 221 | return m_running; | ||
3279 | 222 | } | ||
3280 | 223 | |||
3281 | 224 | QObject *RunnerModel::modelForRow(int row) const | ||
3282 | 225 | { | ||
3283 | 226 | if (row < 0 || row >= m_models.count()) { | ||
3284 | 227 | kWarning() << "No model for row" << row << "!"; | ||
3285 | 228 | return 0; | ||
3286 | 229 | } | ||
3287 | 230 | return m_models.value(row); | ||
3288 | 231 | } | ||
3289 | 232 | |||
3290 | 233 | void RunnerModel::setAllowedRunners(const QStringList &list) | ||
3291 | 234 | { | ||
3292 | 235 | QStringList existingList = m_manager ? m_manager->allowedRunners() : m_pendingRunnersList; | ||
3293 | 236 | |||
3294 | 237 | if (existingList.toSet() == list.toSet()) { | ||
3295 | 238 | return; | ||
3296 | 239 | } | ||
3297 | 240 | m_pendingRunnersList = list; | ||
3298 | 241 | if (m_manager) { | ||
3299 | 242 | loadRunners(); | ||
3300 | 243 | } | ||
3301 | 244 | } | ||
3302 | 245 | |||
3303 | 246 | QString RunnerModel::currentQuery() const | ||
3304 | 247 | { | ||
3305 | 248 | return m_manager ? m_manager->query() : QString(); | ||
3306 | 249 | } | ||
3307 | 250 | |||
3308 | 251 | void RunnerModel::scheduleQuery(const QString &query) | ||
3309 | 252 | { | ||
3310 | 253 | m_pendingQuery = query; | ||
3311 | 254 | m_startQueryTimer->start(); | ||
3312 | 255 | } | ||
3313 | 256 | |||
3314 | 257 | void RunnerModel::startQuery() | ||
3315 | 258 | { | ||
3316 | 259 | if (m_pendingQuery.isEmpty()) { | ||
3317 | 260 | clear(); | ||
3318 | 261 | } | ||
3319 | 262 | |||
3320 | 263 | if (!m_manager && m_pendingQuery.isEmpty()) { | ||
3321 | 264 | // avoid creating a manager just so we can run nothing | ||
3322 | 265 | return; | ||
3323 | 266 | } | ||
3324 | 267 | |||
3325 | 268 | createManager(); | ||
3326 | 269 | /* DEBUG | ||
3327 | 270 | kWarning() << "Start query" << m_pendingQuery << "on runners:"; | ||
3328 | 271 | Q_FOREACH(Plasma::AbstractRunner *runner, m_manager->runners()) { | ||
3329 | 272 | kWarning() << "-" << runner->name(); | ||
3330 | 273 | } | ||
3331 | 274 | */ | ||
3332 | 275 | m_manager->launchQuery(m_pendingQuery); | ||
3333 | 276 | emit queryChanged(); | ||
3334 | 277 | m_running = true; | ||
3335 | 278 | emit runningChanged(true); | ||
3336 | 279 | } | ||
3337 | 280 | |||
3338 | 281 | void RunnerModel::createManager() | ||
3339 | 282 | { | ||
3340 | 283 | if (!m_manager) { | ||
3341 | 284 | m_manager = new Plasma::RunnerManager(this); | ||
3342 | 285 | connect(m_manager, SIGNAL(matchesChanged(QList<Plasma::QueryMatch>)), | ||
3343 | 286 | this, SLOT(matchesChanged(QList<Plasma::QueryMatch>))); | ||
3344 | 287 | connect(m_manager, SIGNAL(queryFinished()), | ||
3345 | 288 | this, SLOT(queryHasFinished())); | ||
3346 | 289 | |||
3347 | 290 | if (!m_pendingRunnersList.isEmpty()) { | ||
3348 | 291 | loadRunners(); | ||
3349 | 292 | } | ||
3350 | 293 | //connect(m_manager, SIGNAL(queryFinished()), this, SLOT(queryFinished())); | ||
3351 | 294 | } | ||
3352 | 295 | } | ||
3353 | 296 | |||
3354 | 297 | void RunnerModel::matchesChanged(const QList<Plasma::QueryMatch> &matches) | ||
3355 | 298 | { | ||
3356 | 299 | // Group matches by runner | ||
3357 | 300 | // We do not use a QMultiHash here because it keeps values in LIFO order, while we want FIFO. | ||
3358 | 301 | QHash<QString, QList<Plasma::QueryMatch> > matchesForRunner; | ||
3359 | 302 | Q_FOREACH(const Plasma::QueryMatch &match, matches) { | ||
3360 | 303 | QString runnerId = match.runner()->id(); | ||
3361 | 304 | auto it = matchesForRunner.find(runnerId); | ||
3362 | 305 | if (it == matchesForRunner.end()) { | ||
3363 | 306 | it = matchesForRunner.insert(runnerId, QList<Plasma::QueryMatch>()); | ||
3364 | 307 | } | ||
3365 | 308 | it.value().append(match); | ||
3366 | 309 | } | ||
3367 | 310 | |||
3368 | 311 | // Assign matches to existing models. If there is no match for a model, delete it. | ||
3369 | 312 | for (int row = m_models.count() - 1; row >= 0; --row) { | ||
3370 | 313 | RunnerSubModel *subModel = m_models.at(row); | ||
3371 | 314 | QList<Plasma::QueryMatch> matches = matchesForRunner.take(subModel->runnerId()); | ||
3372 | 315 | if (matches.isEmpty()) { | ||
3373 | 316 | beginRemoveRows(QModelIndex(), row, row); | ||
3374 | 317 | m_models.removeAt(row); | ||
3375 | 318 | delete subModel; | ||
3376 | 319 | endRemoveRows(); | ||
3377 | 320 | } else { | ||
3378 | 321 | subModel->setMatches(matches); | ||
3379 | 322 | } | ||
3380 | 323 | } | ||
3381 | 324 | |||
3382 | 325 | // At this point, matchesForRunner contains only matches for runners which | ||
3383 | 326 | // do not have a model yet. Create new models for them. | ||
3384 | 327 | if (!matchesForRunner.isEmpty()) { | ||
3385 | 328 | beginInsertRows(QModelIndex(), rowCount(), rowCount() + matchesForRunner.size() - 1); | ||
3386 | 329 | auto it = matchesForRunner.constBegin(); | ||
3387 | 330 | auto end = matchesForRunner.constEnd(); | ||
3388 | 331 | for (; it != end; ++it) { | ||
3389 | 332 | QList<Plasma::QueryMatch> matches = it.value(); | ||
3390 | 333 | Q_ASSERT(!matches.isEmpty()); | ||
3391 | 334 | QString name = matches.first().runner()->name(); | ||
3392 | 335 | RunnerSubModel *subModel = new RunnerSubModel(it.key(), name, this); | ||
3393 | 336 | connect(subModel, SIGNAL(triggerRequested(Plasma::QueryMatch)), SLOT(trigger(Plasma::QueryMatch))); | ||
3394 | 337 | subModel->setMatches(matches); | ||
3395 | 338 | m_models.append(subModel); | ||
3396 | 339 | } | ||
3397 | 340 | endInsertRows(); | ||
3398 | 341 | } | ||
3399 | 342 | |||
3400 | 343 | m_runningChangedTimeout->start(3000); | ||
3401 | 344 | } | ||
3402 | 345 | |||
3403 | 346 | void RunnerModel::queryHasFinished() | ||
3404 | 347 | { | ||
3405 | 348 | m_running = false; | ||
3406 | 349 | emit runningChanged(false); | ||
3407 | 350 | } | ||
3408 | 351 | |||
3409 | 352 | void RunnerModel::clear() | ||
3410 | 353 | { | ||
3411 | 354 | if (m_models.isEmpty()) { | ||
3412 | 355 | return; | ||
3413 | 356 | } | ||
3414 | 357 | beginResetModel(); | ||
3415 | 358 | qDeleteAll(m_models); | ||
3416 | 359 | m_models.clear(); | ||
3417 | 360 | endResetModel(); | ||
3418 | 361 | } | ||
3419 | 362 | |||
3420 | 363 | void RunnerModel::trigger(const Plasma::QueryMatch& match) | ||
3421 | 364 | { | ||
3422 | 365 | m_manager->run(match); | ||
3423 | 366 | } | ||
3424 | 367 | |||
3425 | 368 | void RunnerModel::loadRunners() | ||
3426 | 369 | { | ||
3427 | 370 | Q_ASSERT(m_manager); | ||
3428 | 371 | if (m_pendingRunnersList.count() > 0) { | ||
3429 | 372 | KPluginInfo::List list = Plasma::RunnerManager::listRunnerInfo(); | ||
3430 | 373 | Q_FOREACH(const KPluginInfo &info, list) { | ||
3431 | 374 | if (m_pendingRunnersList.contains(info.pluginName())) { | ||
3432 | 375 | m_manager->loadRunner(info.service()); | ||
3433 | 376 | } | ||
3434 | 377 | } | ||
3435 | 378 | } | ||
3436 | 379 | m_manager->setSingleMode(m_pendingRunnersList.count() == 1); | ||
3437 | 380 | m_pendingRunnersList.clear(); | ||
3438 | 381 | } | ||
3439 | 382 | |||
3440 | 383 | //- RunnerSource ------------------------------ | ||
3441 | 384 | RunnerSource::RunnerSource(QObject *parent) | ||
3442 | 385 | : AbstractSource(parent) | ||
3443 | 386 | {} | ||
3444 | 387 | |||
3445 | 388 | QAbstractItemModel *RunnerSource::createModelFromConfigGroup(const KConfigGroup &group) | ||
3446 | 389 | { | ||
3447 | 390 | RunnerModel *model = new RunnerModel; | ||
3448 | 391 | QStringList lst = group.readEntry(WHITELIST_KEY, QStringList()); | ||
3449 | 392 | model->setAllowedRunners(lst); | ||
3450 | 393 | return model; | ||
3451 | 394 | }; | ||
3452 | 395 | |||
3453 | 396 | bool RunnerSource::isConfigurable() const | ||
3454 | 397 | { | ||
3455 | 398 | return true; | ||
3456 | 399 | } | ||
3457 | 400 | |||
3458 | 401 | SourceConfigurationWidget *RunnerSource::createConfigurationWidget(const KConfigGroup &group) | ||
3459 | 402 | { | ||
3460 | 403 | return new RunnerConfigurationWidget(group); | ||
3461 | 404 | } | ||
3462 | 405 | |||
3463 | 406 | } // namespace Homerun | ||
3464 | 407 | |||
3465 | 408 | #include <runnermodel.moc> | ||
3466 | 409 | 0 | ||
3467 | === removed file 'components/runnermodel.h' | |||
3468 | --- components/runnermodel.h 2012-11-14 21:30:06 +0000 | |||
3469 | +++ components/runnermodel.h 1970-01-01 00:00:00 +0000 | |||
3470 | @@ -1,150 +0,0 @@ | |||
3471 | 1 | /* | ||
3472 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
3473 | 3 | |||
3474 | 4 | Based on RunnerModel class. RunnerModel class copyright: | ||
3475 | 5 | |||
3476 | 6 | Copyright 2011 Aaron Seigo <aseigo@kde.org> | ||
3477 | 7 | |||
3478 | 8 | This library is free software; you can redistribute it and/or | ||
3479 | 9 | modify it under the terms of the GNU Library General Public | ||
3480 | 10 | License as published by the Free Software Foundation; either | ||
3481 | 11 | version 2 of the License, or (at your option) any later version. | ||
3482 | 12 | |||
3483 | 13 | This library is distributed in the hope that it will be useful, | ||
3484 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3485 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3486 | 16 | Library General Public License for more details. | ||
3487 | 17 | |||
3488 | 18 | You should have received a copy of the GNU Library General Public License | ||
3489 | 19 | along with this library; see the file COPYING.LIB. If not, write to | ||
3490 | 20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
3491 | 21 | Boston, MA 02110-1301, USA. | ||
3492 | 22 | */ | ||
3493 | 23 | #ifndef RUNNERMODEL_H | ||
3494 | 24 | #define RUNNERMODEL_H | ||
3495 | 25 | |||
3496 | 26 | // Local | ||
3497 | 27 | #include <abstractsource.h> | ||
3498 | 28 | |||
3499 | 29 | // Qt | ||
3500 | 30 | #include <QAbstractListModel> | ||
3501 | 31 | #include <QStringList> | ||
3502 | 32 | |||
3503 | 33 | // KDE | ||
3504 | 34 | #include <KConfig> | ||
3505 | 35 | #include <KConfigGroup> | ||
3506 | 36 | #include <Plasma/QueryMatch> | ||
3507 | 37 | |||
3508 | 38 | class QTimer; | ||
3509 | 39 | |||
3510 | 40 | namespace Plasma { | ||
3511 | 41 | class RunnerManager; | ||
3512 | 42 | } | ||
3513 | 43 | |||
3514 | 44 | namespace Homerun { | ||
3515 | 45 | |||
3516 | 46 | class RunnerSubModel : public QAbstractListModel | ||
3517 | 47 | { | ||
3518 | 48 | Q_OBJECT | ||
3519 | 49 | Q_PROPERTY(QString name READ name CONSTANT) | ||
3520 | 50 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
3521 | 51 | public: | ||
3522 | 52 | explicit RunnerSubModel(const QString &runnerId, const QString &name, QObject *parent = 0); | ||
3523 | 53 | |||
3524 | 54 | enum { | ||
3525 | 55 | FavoriteIdRole = Qt::UserRole + 1 | ||
3526 | 56 | }; | ||
3527 | 57 | |||
3528 | 58 | QString runnerId() const { return m_runnerId; } | ||
3529 | 59 | QString name() const { return m_name; } | ||
3530 | 60 | |||
3531 | 61 | void setMatches(const QList<Plasma::QueryMatch> &matches); | ||
3532 | 62 | |||
3533 | 63 | int count() const; | ||
3534 | 64 | |||
3535 | 65 | int rowCount(const QModelIndex &parent = QModelIndex()) const; | ||
3536 | 66 | |||
3537 | 67 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | ||
3538 | 68 | |||
3539 | 69 | Q_INVOKABLE bool trigger(int row); | ||
3540 | 70 | |||
3541 | 71 | Q_SIGNALS: | ||
3542 | 72 | void countChanged(); | ||
3543 | 73 | |||
3544 | 74 | void triggerRequested(const Plasma::QueryMatch&); | ||
3545 | 75 | |||
3546 | 76 | private: | ||
3547 | 77 | QString m_runnerId; | ||
3548 | 78 | QString m_name; | ||
3549 | 79 | |||
3550 | 80 | QList<Plasma::QueryMatch> m_matches; | ||
3551 | 81 | }; | ||
3552 | 82 | |||
3553 | 83 | /** | ||
3554 | 84 | * | ||
3555 | 85 | */ | ||
3556 | 86 | class RunnerModel : public QAbstractListModel | ||
3557 | 87 | { | ||
3558 | 88 | Q_OBJECT | ||
3559 | 89 | /** | ||
3560 | 90 | * @property string set the KRunner query | ||
3561 | 91 | */ | ||
3562 | 92 | Q_PROPERTY(QString query WRITE scheduleQuery READ currentQuery NOTIFY queryChanged) | ||
3563 | 93 | |||
3564 | 94 | Q_PROPERTY(bool running READ running NOTIFY runningChanged) | ||
3565 | 95 | |||
3566 | 96 | public: | ||
3567 | 97 | explicit RunnerModel(QObject *parent = 0); | ||
3568 | 98 | ~RunnerModel(); | ||
3569 | 99 | |||
3570 | 100 | Q_INVOKABLE QObject *modelForRow(int row) const; | ||
3571 | 101 | |||
3572 | 102 | void setAllowedRunners(const QStringList &runners); | ||
3573 | 103 | |||
3574 | 104 | int rowCount(const QModelIndex &parent = QModelIndex()) const; // reimp | ||
3575 | 105 | QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const; // reimp | ||
3576 | 106 | |||
3577 | 107 | bool running() const; | ||
3578 | 108 | |||
3579 | 109 | QString currentQuery() const; | ||
3580 | 110 | |||
3581 | 111 | public Q_SLOTS: | ||
3582 | 112 | void scheduleQuery(const QString &query); | ||
3583 | 113 | |||
3584 | 114 | Q_SIGNALS: | ||
3585 | 115 | void queryChanged(); | ||
3586 | 116 | void runningChanged(bool); | ||
3587 | 117 | |||
3588 | 118 | private Q_SLOTS: | ||
3589 | 119 | void startQuery(); | ||
3590 | 120 | void queryHasFinished(); | ||
3591 | 121 | void matchesChanged(const QList<Plasma::QueryMatch> &matches); | ||
3592 | 122 | void trigger(const Plasma::QueryMatch&); | ||
3593 | 123 | |||
3594 | 124 | private: | ||
3595 | 125 | void createManager(); | ||
3596 | 126 | void loadRunners(); | ||
3597 | 127 | void clear(); | ||
3598 | 128 | |||
3599 | 129 | Plasma::RunnerManager *m_manager; | ||
3600 | 130 | QTimer *m_startQueryTimer; | ||
3601 | 131 | QTimer *m_runningChangedTimeout; | ||
3602 | 132 | |||
3603 | 133 | QList<RunnerSubModel *> m_models; | ||
3604 | 134 | QStringList m_pendingRunnersList; | ||
3605 | 135 | bool m_running; | ||
3606 | 136 | QString m_pendingQuery; | ||
3607 | 137 | }; | ||
3608 | 138 | |||
3609 | 139 | class RunnerSource : public AbstractSource | ||
3610 | 140 | { | ||
3611 | 141 | public: | ||
3612 | 142 | RunnerSource(QObject *parent); | ||
3613 | 143 | QAbstractItemModel *createModelFromConfigGroup(const KConfigGroup &group); | ||
3614 | 144 | SourceConfigurationWidget *createConfigurationWidget(const KConfigGroup &group); | ||
3615 | 145 | bool isConfigurable() const; | ||
3616 | 146 | }; | ||
3617 | 147 | |||
3618 | 148 | } // namespace Homerun | ||
3619 | 149 | |||
3620 | 150 | #endif /* RUNNERMODEL_H */ | ||
3621 | 151 | 0 | ||
3622 | === removed file 'components/sessionmodel.cpp' | |||
3623 | --- components/sessionmodel.cpp 2012-11-14 21:30:06 +0000 | |||
3624 | +++ components/sessionmodel.cpp 1970-01-01 00:00:00 +0000 | |||
3625 | @@ -1,137 +0,0 @@ | |||
3626 | 1 | /* | ||
3627 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
3628 | 3 | Copyright (C) 2012 Shaun Reich <shaun.reich@blue-systems.com> | ||
3629 | 4 | |||
3630 | 5 | This library is free software; you can redistribute it and/or | ||
3631 | 6 | modify it under the terms of the GNU Library General Public | ||
3632 | 7 | License as published by the Free Software Foundation; either | ||
3633 | 8 | version 2 of the License, or (at your option) any later version. | ||
3634 | 9 | |||
3635 | 10 | This library is distributed in the hope that it will be useful, | ||
3636 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3637 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3638 | 13 | Library General Public License for more details. | ||
3639 | 14 | |||
3640 | 15 | You should have received a copy of the GNU Library General Public License | ||
3641 | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
3642 | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
3643 | 18 | Boston, MA 02110-1301, USA. | ||
3644 | 19 | */ | ||
3645 | 20 | |||
3646 | 21 | // Own | ||
3647 | 22 | #include "sessionmodel.h" | ||
3648 | 23 | |||
3649 | 24 | //Qt | ||
3650 | 25 | #include <QDBusConnection> | ||
3651 | 26 | #include <QDBusInterface> | ||
3652 | 27 | #include <QDBusPendingCall> | ||
3653 | 28 | |||
3654 | 29 | // KDE | ||
3655 | 30 | #include <KAuthorized> | ||
3656 | 31 | #include <KDebug> | ||
3657 | 32 | #include <KIcon> | ||
3658 | 33 | #include <KLocale> | ||
3659 | 34 | #include <kworkspace/kdisplaymanager.h> | ||
3660 | 35 | #include <kworkspace/kworkspace.h> | ||
3661 | 36 | |||
3662 | 37 | namespace Homerun { | ||
3663 | 38 | |||
3664 | 39 | SessionModel::SessionModel(QObject *parent) | ||
3665 | 40 | : QAbstractListModel(parent) | ||
3666 | 41 | { | ||
3667 | 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. | ||
3668 | 43 | //otherwise the user is hunting for the power buttons and for some reason it isn't where it should be. | ||
3669 | 44 | if (KAuthorized::authorizeKAction("lock_screen")) { | ||
3670 | 45 | SessionAction lock; | ||
3671 | 46 | lock.name = i18nc("an action", "Lock"); | ||
3672 | 47 | lock.type = Lock; | ||
3673 | 48 | lock.iconName = "system-lock-screen"; | ||
3674 | 49 | m_sessionList.append(lock); | ||
3675 | 50 | } | ||
3676 | 51 | |||
3677 | 52 | if (KDisplayManager().isSwitchable() && KAuthorized::authorize(QLatin1String("switch_user"))) { | ||
3678 | 53 | SessionAction switchUser; | ||
3679 | 54 | switchUser.name = i18nc("an action", "Switch User"); | ||
3680 | 55 | switchUser.type = SwitchUser; | ||
3681 | 56 | switchUser.iconName = "system-switch-user"; | ||
3682 | 57 | m_sessionList.append(switchUser); | ||
3683 | 58 | } | ||
3684 | 59 | |||
3685 | 60 | const bool canLogout = KAuthorized::authorizeKAction("logout") && KAuthorized::authorize("logout"); | ||
3686 | 61 | if (canLogout) { | ||
3687 | 62 | SessionAction logout; | ||
3688 | 63 | logout.name = i18nc("an action", "Logout"); | ||
3689 | 64 | logout.type = Logout; | ||
3690 | 65 | logout.iconName = "system-log-out"; | ||
3691 | 66 | m_sessionList.append(logout); | ||
3692 | 67 | } | ||
3693 | 68 | } | ||
3694 | 69 | |||
3695 | 70 | SessionModel::~SessionModel() | ||
3696 | 71 | { | ||
3697 | 72 | } | ||
3698 | 73 | |||
3699 | 74 | int SessionModel::count() const | ||
3700 | 75 | { | ||
3701 | 76 | return m_sessionList.count(); | ||
3702 | 77 | } | ||
3703 | 78 | |||
3704 | 79 | QString SessionModel::name() const | ||
3705 | 80 | { | ||
3706 | 81 | return i18n("Session"); | ||
3707 | 82 | } | ||
3708 | 83 | |||
3709 | 84 | int SessionModel::rowCount(const QModelIndex &index) const | ||
3710 | 85 | { | ||
3711 | 86 | if (index.isValid()) { | ||
3712 | 87 | return 0; | ||
3713 | 88 | } | ||
3714 | 89 | return m_sessionList.count(); | ||
3715 | 90 | } | ||
3716 | 91 | |||
3717 | 92 | QVariant SessionModel::data(const QModelIndex &index, int role) const | ||
3718 | 93 | { | ||
3719 | 94 | SessionAction action = m_sessionList.value(index.row()); | ||
3720 | 95 | |||
3721 | 96 | if (role == Qt::DisplayRole) { | ||
3722 | 97 | return action.name; | ||
3723 | 98 | } else if (role == Qt::DecorationRole) { | ||
3724 | 99 | return KIcon(action.iconName); | ||
3725 | 100 | } else { | ||
3726 | 101 | kWarning() << "Unhandled role" << role; | ||
3727 | 102 | return QVariant(); | ||
3728 | 103 | } | ||
3729 | 104 | } | ||
3730 | 105 | |||
3731 | 106 | bool SessionModel::trigger(int row) | ||
3732 | 107 | { | ||
3733 | 108 | SessionAction action = m_sessionList.value(row); | ||
3734 | 109 | |||
3735 | 110 | switch (action.type) { | ||
3736 | 111 | case Logout: | ||
3737 | 112 | KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeNone); | ||
3738 | 113 | break; | ||
3739 | 114 | |||
3740 | 115 | case SwitchUser: { | ||
3741 | 116 | QDBusConnection bus = QDBusConnection::sessionBus(); | ||
3742 | 117 | QDBusInterface interface("org.kde.krunner", "/App", "org.kde.krunner", bus); | ||
3743 | 118 | |||
3744 | 119 | interface.asyncCall("switchUser"); | ||
3745 | 120 | } | ||
3746 | 121 | break; | ||
3747 | 122 | |||
3748 | 123 | case Lock: { | ||
3749 | 124 | QDBusConnection bus = QDBusConnection::sessionBus(); | ||
3750 | 125 | QDBusInterface interface("org.freedesktop.ScreenSaver", "/ScreenSaver", "org.freedesktop.ScreenSaver", bus); | ||
3751 | 126 | |||
3752 | 127 | interface.asyncCall("Lock"); | ||
3753 | 128 | } | ||
3754 | 129 | break; | ||
3755 | 130 | } | ||
3756 | 131 | |||
3757 | 132 | return true; | ||
3758 | 133 | } | ||
3759 | 134 | |||
3760 | 135 | } // namespace Homerun | ||
3761 | 136 | |||
3762 | 137 | #include "sessionmodel.moc" | ||
3763 | 138 | 0 | ||
3764 | === removed file 'components/sessionmodel.h' | |||
3765 | --- components/sessionmodel.h 2012-11-14 21:30:06 +0000 | |||
3766 | +++ components/sessionmodel.h 1970-01-01 00:00:00 +0000 | |||
3767 | @@ -1,72 +0,0 @@ | |||
3768 | 1 | /* | ||
3769 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
3770 | 3 | Copyright 2012 (C) Shaun Reich <shaun.reich@blue-systems.com> | ||
3771 | 4 | |||
3772 | 5 | This library is free software; you can redistribute it and/or | ||
3773 | 6 | modify it under the terms of the GNU Library General Public | ||
3774 | 7 | License as published by the Free Software Foundation; either | ||
3775 | 8 | version 2 of the License, or (at your option) any later version. | ||
3776 | 9 | |||
3777 | 10 | This library is distributed in the hope that it will be useful, | ||
3778 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3779 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3780 | 13 | Library General Public License for more details. | ||
3781 | 14 | |||
3782 | 15 | You should have received a copy of the GNU Library General Public License | ||
3783 | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
3784 | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
3785 | 18 | Boston, MA 02110-1301, USA. | ||
3786 | 19 | */ | ||
3787 | 20 | |||
3788 | 21 | #ifndef SESSIONMODEL_H | ||
3789 | 22 | #define SESSIONMODEL_H | ||
3790 | 23 | |||
3791 | 24 | #include <QAbstractListModel> | ||
3792 | 25 | |||
3793 | 26 | #include <KService> | ||
3794 | 27 | |||
3795 | 28 | class QString; | ||
3796 | 29 | |||
3797 | 30 | namespace Homerun { | ||
3798 | 31 | |||
3799 | 32 | enum ActionType { | ||
3800 | 33 | Logout, | ||
3801 | 34 | SwitchUser, | ||
3802 | 35 | Lock | ||
3803 | 36 | }; | ||
3804 | 37 | |||
3805 | 38 | struct SessionAction | ||
3806 | 39 | { | ||
3807 | 40 | QString name; | ||
3808 | 41 | QString iconName; | ||
3809 | 42 | ActionType type; | ||
3810 | 43 | }; | ||
3811 | 44 | |||
3812 | 45 | class SessionModel : public QAbstractListModel | ||
3813 | 46 | { | ||
3814 | 47 | Q_OBJECT | ||
3815 | 48 | Q_PROPERTY(QString name READ name CONSTANT) | ||
3816 | 49 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
3817 | 50 | |||
3818 | 51 | public: | ||
3819 | 52 | SessionModel(QObject *parent = 0); | ||
3820 | 53 | ~SessionModel(); | ||
3821 | 54 | |||
3822 | 55 | int count() const; | ||
3823 | 56 | QString name() const; | ||
3824 | 57 | |||
3825 | 58 | int rowCount(const QModelIndex & = QModelIndex()) const; | ||
3826 | 59 | QVariant data(const QModelIndex &, int role = Qt::DisplayRole) const; | ||
3827 | 60 | |||
3828 | 61 | Q_INVOKABLE bool trigger(int row); | ||
3829 | 62 | |||
3830 | 63 | Q_SIGNALS: | ||
3831 | 64 | void countChanged(); | ||
3832 | 65 | |||
3833 | 66 | private: | ||
3834 | 67 | QList<SessionAction> m_sessionList; | ||
3835 | 68 | }; | ||
3836 | 69 | |||
3837 | 70 | } // namespace Homerun | ||
3838 | 71 | |||
3839 | 72 | #endif | ||
3840 | 73 | 0 | ||
3841 | === added file 'components/shadoweffect.cpp' | |||
3842 | --- components/shadoweffect.cpp 1970-01-01 00:00:00 +0000 | |||
3843 | +++ components/shadoweffect.cpp 2013-03-01 15:15:27 +0000 | |||
3844 | @@ -0,0 +1,222 @@ | |||
3845 | 1 | /* | ||
3846 | 2 | * Copyright 2013 Aurélien Gâteau <agateau@kde.org> | ||
3847 | 3 | * | ||
3848 | 4 | * This program is free software; you can redistribute it and/or modify | ||
3849 | 5 | * it under the terms of the GNU Library General Public License as | ||
3850 | 6 | * published by the Free Software Foundation; either version 2, or | ||
3851 | 7 | * (at your option) any later version. | ||
3852 | 8 | * | ||
3853 | 9 | * This program is distributed in the hope that it will be useful, | ||
3854 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3855 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3856 | 12 | * GNU Library General Public License for more details | ||
3857 | 13 | * | ||
3858 | 14 | * You should have received a copy of the GNU Library General Public | ||
3859 | 15 | * License along with this program; if not, write to the | ||
3860 | 16 | * Free Software Foundation, Inc., | ||
3861 | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
3862 | 18 | */ | ||
3863 | 19 | // Self | ||
3864 | 20 | #include <shadoweffect.h> | ||
3865 | 21 | |||
3866 | 22 | // Local | ||
3867 | 23 | |||
3868 | 24 | // KDE | ||
3869 | 25 | #include <KDebug> | ||
3870 | 26 | #include <Plasma/PaintUtils> | ||
3871 | 27 | |||
3872 | 28 | // Qt | ||
3873 | 29 | #include <QPainter> | ||
3874 | 30 | #include <QPaintEngine> | ||
3875 | 31 | |||
3876 | 32 | ShadowEffect::ShadowEffect(QObject *parent) | ||
3877 | 33 | : QGraphicsEffect(parent) | ||
3878 | 34 | , m_xOffset(0) | ||
3879 | 35 | , m_yOffset(1) | ||
3880 | 36 | , m_blurRadius(3) | ||
3881 | 37 | { | ||
3882 | 38 | } | ||
3883 | 39 | |||
3884 | 40 | ShadowEffect::~ShadowEffect() | ||
3885 | 41 | { | ||
3886 | 42 | } | ||
3887 | 43 | |||
3888 | 44 | qreal ShadowEffect::xOffset() const | ||
3889 | 45 | { | ||
3890 | 46 | return m_xOffset; | ||
3891 | 47 | } | ||
3892 | 48 | |||
3893 | 49 | qreal ShadowEffect::yOffset() const | ||
3894 | 50 | { | ||
3895 | 51 | return m_yOffset; | ||
3896 | 52 | } | ||
3897 | 53 | |||
3898 | 54 | qreal ShadowEffect::blurRadius() const | ||
3899 | 55 | { | ||
3900 | 56 | return m_blurRadius; | ||
3901 | 57 | } | ||
3902 | 58 | |||
3903 | 59 | QColor ShadowEffect::color() const | ||
3904 | 60 | { | ||
3905 | 61 | return m_color; | ||
3906 | 62 | } | ||
3907 | 63 | |||
3908 | 64 | #define SETTER(prop) \ | ||
3909 | 65 | if (prop == value) { \ | ||
3910 | 66 | return; \ | ||
3911 | 67 | } \ | ||
3912 | 68 | prop = value; | ||
3913 | 69 | |||
3914 | 70 | #define SETTER_REAL(prop) \ | ||
3915 | 71 | if (qFuzzyCompare(prop, value)) { \ | ||
3916 | 72 | return; \ | ||
3917 | 73 | } \ | ||
3918 | 74 | prop = value; | ||
3919 | 75 | |||
3920 | 76 | void ShadowEffect::setXOffset(qreal value) | ||
3921 | 77 | { | ||
3922 | 78 | SETTER_REAL(m_xOffset); | ||
3923 | 79 | m_shadow = QImage(); | ||
3924 | 80 | updateBoundingRect(); | ||
3925 | 81 | xOffsetChanged(m_xOffset); | ||
3926 | 82 | } | ||
3927 | 83 | |||
3928 | 84 | void ShadowEffect::setYOffset(qreal value) | ||
3929 | 85 | { | ||
3930 | 86 | SETTER_REAL(m_yOffset); | ||
3931 | 87 | m_shadow = QImage(); | ||
3932 | 88 | updateBoundingRect(); | ||
3933 | 89 | yOffsetChanged(m_yOffset); | ||
3934 | 90 | } | ||
3935 | 91 | |||
3936 | 92 | void ShadowEffect::setBlurRadius(qreal value) | ||
3937 | 93 | { | ||
3938 | 94 | SETTER_REAL(m_blurRadius); | ||
3939 | 95 | m_shadow = QImage(); | ||
3940 | 96 | updateBoundingRect(); | ||
3941 | 97 | blurRadiusChanged(m_blurRadius); | ||
3942 | 98 | } | ||
3943 | 99 | |||
3944 | 100 | void ShadowEffect::setColor(const QColor &value) | ||
3945 | 101 | { | ||
3946 | 102 | SETTER(m_color); | ||
3947 | 103 | m_shadow = QImage(); | ||
3948 | 104 | update(); | ||
3949 | 105 | colorChanged(m_color); | ||
3950 | 106 | } | ||
3951 | 107 | |||
3952 | 108 | void ShadowEffect::resetColor() | ||
3953 | 109 | { | ||
3954 | 110 | setColor(QColor()); | ||
3955 | 111 | } | ||
3956 | 112 | |||
3957 | 113 | QRectF ShadowEffect::boundingRectFor(const QRectF &rect) const | ||
3958 | 114 | { | ||
3959 | 115 | qreal padding = m_blurRadius * 2; | ||
3960 | 116 | return rect.united( | ||
3961 | 117 | rect.translated(m_xOffset, m_yOffset) | ||
3962 | 118 | .adjusted(-padding, -padding, padding, padding) | ||
3963 | 119 | ); | ||
3964 | 120 | } | ||
3965 | 121 | |||
3966 | 122 | QImage ShadowEffect::generateShadow(const QPixmap &px) const | ||
3967 | 123 | { | ||
3968 | 124 | if (px.isNull()) { | ||
3969 | 125 | return QImage(); | ||
3970 | 126 | } | ||
3971 | 127 | |||
3972 | 128 | // Generate shadow in tmp | ||
3973 | 129 | QImage tmp(px.size(), QImage::Format_ARGB32_Premultiplied); | ||
3974 | 130 | tmp.fill(0); | ||
3975 | 131 | QPainter tmpPainter(&tmp); | ||
3976 | 132 | tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); | ||
3977 | 133 | tmpPainter.drawPixmap(m_xOffset, m_yOffset, px); | ||
3978 | 134 | tmpPainter.end(); | ||
3979 | 135 | QColor color = m_color.isValid() ? m_color : computeColorFromSource(); | ||
3980 | 136 | Plasma::PaintUtils::shadowBlur(tmp, m_blurRadius, color); | ||
3981 | 137 | return tmp; | ||
3982 | 138 | } | ||
3983 | 139 | |||
3984 | 140 | void ShadowEffect::draw(QPainter *painter) | ||
3985 | 141 | { | ||
3986 | 142 | if (m_blurRadius <= 0 && qFuzzyIsNull(m_xOffset) && qFuzzyIsNull(m_yOffset)) { | ||
3987 | 143 | drawSource(painter); | ||
3988 | 144 | return; | ||
3989 | 145 | } | ||
3990 | 146 | |||
3991 | 147 | PixmapPadMode mode = PadToEffectiveBoundingRect; | ||
3992 | 148 | if (painter->paintEngine()->type() == QPaintEngine::OpenGL2) { | ||
3993 | 149 | mode = NoPad; | ||
3994 | 150 | } | ||
3995 | 151 | |||
3996 | 152 | // Draw pixmap in device coordinates to avoid pixmap scaling. | ||
3997 | 153 | QPoint offset; | ||
3998 | 154 | const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode); | ||
3999 | 155 | if (pixmap.isNull()) { | ||
4000 | 156 | return; | ||
4001 | 157 | } | ||
4002 | 158 | |||
4003 | 159 | QTransform restoreTransform = painter->worldTransform(); | ||
4004 | 160 | painter->setWorldTransform(QTransform()); | ||
4005 | 161 | if (m_shadow.isNull()) { | ||
4006 | 162 | m_shadow = generateShadow(pixmap); | ||
4007 | 163 | } | ||
4008 | 164 | // Draw shadow (draw it twice to darken it) | ||
4009 | 165 | painter->drawImage(offset, m_shadow); | ||
4010 | 166 | painter->drawImage(offset, m_shadow); | ||
4011 | 167 | // Draw the actual pixmap | ||
4012 | 168 | painter->drawPixmap(offset, pixmap); | ||
4013 | 169 | painter->setWorldTransform(restoreTransform); | ||
4014 | 170 | } | ||
4015 | 171 | |||
4016 | 172 | void ShadowEffect::sourceChanged(ChangeFlags flags) | ||
4017 | 173 | { | ||
4018 | 174 | switch (flags) { | ||
4019 | 175 | case SourceAttached: | ||
4020 | 176 | case SourceBoundingRectChanged: | ||
4021 | 177 | case SourceInvalidated: | ||
4022 | 178 | m_shadow = QImage(); | ||
4023 | 179 | break; | ||
4024 | 180 | case SourceDetached: | ||
4025 | 181 | break; | ||
4026 | 182 | } | ||
4027 | 183 | } | ||
4028 | 184 | |||
4029 | 185 | |||
4030 | 186 | /********************************************************** | ||
4031 | 187 | * UGLYNESS | ||
4032 | 188 | * This is a severely trimmed copy of an internal class defined in qt: | ||
4033 | 189 | * src/gui/effects/qgraphicseffect_p.h | ||
4034 | 190 | *********************************************************/ | ||
4035 | 191 | class QGraphicsEffectSource | ||
4036 | 192 | { | ||
4037 | 193 | public: | ||
4038 | 194 | const QGraphicsItem *graphicsItem() const; | ||
4039 | 195 | }; | ||
4040 | 196 | /********************************************************** | ||
4041 | 197 | * /UGLYNESS | ||
4042 | 198 | *********************************************************/ | ||
4043 | 199 | |||
4044 | 200 | |||
4045 | 201 | QColor ShadowEffect::computeColorFromSource() const | ||
4046 | 202 | { | ||
4047 | 203 | const QGraphicsItem *item = source()->graphicsItem(); | ||
4048 | 204 | if (!item) { | ||
4049 | 205 | kWarning() << "No source item!"; | ||
4050 | 206 | return Qt::black; | ||
4051 | 207 | } | ||
4052 | 208 | const QGraphicsObject *obj = item->toGraphicsObject(); | ||
4053 | 209 | if (!obj) { | ||
4054 | 210 | kWarning() << "Source is not a QGraphicsObject"; | ||
4055 | 211 | return Qt::black; | ||
4056 | 212 | } | ||
4057 | 213 | QVariant variant = obj->property("color"); | ||
4058 | 214 | if (!variant.canConvert<QColor>()) { | ||
4059 | 215 | kWarning() << "Source has no 'color' property, or its 'color' property is not a QColor!"; | ||
4060 | 216 | return Qt::black; | ||
4061 | 217 | } | ||
4062 | 218 | int value = variant.value<QColor>().value(); | ||
4063 | 219 | return value > 128 ? Qt::black : Qt::white; | ||
4064 | 220 | } | ||
4065 | 221 | |||
4066 | 222 | #include <shadoweffect.moc> | ||
4067 | 0 | 223 | ||
4068 | === added file 'components/shadoweffect.h' | |||
4069 | --- components/shadoweffect.h 1970-01-01 00:00:00 +0000 | |||
4070 | +++ components/shadoweffect.h 2013-03-01 15:15:27 +0000 | |||
4071 | @@ -0,0 +1,87 @@ | |||
4072 | 1 | /* | ||
4073 | 2 | * Copyright 2013 Aurélien Gâteau <agateau@kde.org> | ||
4074 | 3 | * | ||
4075 | 4 | * This program is free software; you can redistribute it and/or modify | ||
4076 | 5 | * it under the terms of the GNU Library General Public License as | ||
4077 | 6 | * published by the Free Software Foundation; either version 2, or | ||
4078 | 7 | * (at your option) any later version. | ||
4079 | 8 | * | ||
4080 | 9 | * This program is distributed in the hope that it will be useful, | ||
4081 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4082 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4083 | 12 | * GNU Library General Public License for more details | ||
4084 | 13 | * | ||
4085 | 14 | * You should have received a copy of the GNU Library General Public | ||
4086 | 15 | * License along with this program; if not, write to the | ||
4087 | 16 | * Free Software Foundation, Inc., | ||
4088 | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
4089 | 18 | */ | ||
4090 | 19 | #ifndef SHADOWEFFECT_H | ||
4091 | 20 | #define SHADOWEFFECT_H | ||
4092 | 21 | |||
4093 | 22 | // Local | ||
4094 | 23 | |||
4095 | 24 | // Qt | ||
4096 | 25 | #include <QGraphicsEffect> | ||
4097 | 26 | |||
4098 | 27 | // KDE | ||
4099 | 28 | |||
4100 | 29 | /** | ||
4101 | 30 | * An effect which draws a halo | ||
4102 | 31 | */ | ||
4103 | 32 | class ShadowEffect : public QGraphicsEffect | ||
4104 | 33 | { | ||
4105 | 34 | Q_OBJECT | ||
4106 | 35 | Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY xOffsetChanged) | ||
4107 | 36 | Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY yOffsetChanged) | ||
4108 | 37 | Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged) | ||
4109 | 38 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | ||
4110 | 39 | public: | ||
4111 | 40 | explicit ShadowEffect(QObject *parent = 0); | ||
4112 | 41 | ~ShadowEffect(); | ||
4113 | 42 | |||
4114 | 43 | QRectF boundingRectFor(const QRectF &rect) const; // reimp | ||
4115 | 44 | |||
4116 | 45 | qreal xOffset() const; | ||
4117 | 46 | |||
4118 | 47 | qreal yOffset() const; | ||
4119 | 48 | |||
4120 | 49 | qreal blurRadius() const; | ||
4121 | 50 | QColor color() const; | ||
4122 | 51 | |||
4123 | 52 | /** | ||
4124 | 53 | * Use this method if you set the color manually and now want ShadowEffect | ||
4125 | 54 | * to pick the color automatically, based on the source object. | ||
4126 | 55 | */ | ||
4127 | 56 | Q_INVOKABLE void resetColor(); | ||
4128 | 57 | |||
4129 | 58 | public Q_SLOTS: | ||
4130 | 59 | void setXOffset(qreal dx); | ||
4131 | 60 | void setYOffset(qreal dy); | ||
4132 | 61 | void setBlurRadius(qreal blurRadius); | ||
4133 | 62 | void setColor(const QColor &color); | ||
4134 | 63 | |||
4135 | 64 | Q_SIGNALS: | ||
4136 | 65 | void xOffsetChanged(qreal); | ||
4137 | 66 | void yOffsetChanged(qreal); | ||
4138 | 67 | void blurRadiusChanged(qreal blurRadius); | ||
4139 | 68 | void colorChanged(const QColor &color); | ||
4140 | 69 | |||
4141 | 70 | protected: | ||
4142 | 71 | void draw(QPainter *painter); // reimp | ||
4143 | 72 | void sourceChanged(ChangeFlags flags); // reimp | ||
4144 | 73 | |||
4145 | 74 | private: | ||
4146 | 75 | qreal m_xOffset; | ||
4147 | 76 | qreal m_yOffset; | ||
4148 | 77 | qreal m_blurRadius; | ||
4149 | 78 | QColor m_color; | ||
4150 | 79 | |||
4151 | 80 | QImage m_shadow; | ||
4152 | 81 | |||
4153 | 82 | QImage generateShadow(const QPixmap &px) const; | ||
4154 | 83 | |||
4155 | 84 | QColor computeColorFromSource() const; | ||
4156 | 85 | }; | ||
4157 | 86 | |||
4158 | 87 | #endif /* SHADOWEFFECT_H */ | ||
4159 | 0 | 88 | ||
4160 | === removed file 'components/sourceid.cpp' | |||
4161 | --- components/sourceid.cpp 2012-11-14 21:30:06 +0000 | |||
4162 | +++ components/sourceid.cpp 1970-01-01 00:00:00 +0000 | |||
4163 | @@ -1,163 +0,0 @@ | |||
4164 | 1 | /* | ||
4165 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
4166 | 3 | |||
4167 | 4 | This library is free software; you can redistribute it and/or | ||
4168 | 5 | modify it under the terms of the GNU Lesser General Public | ||
4169 | 6 | License as published by the Free Software Foundation; either | ||
4170 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
4171 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
4172 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
4173 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
4174 | 11 | |||
4175 | 12 | This library is distributed in the hope that it will be useful, | ||
4176 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4177 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
4178 | 15 | Lesser General Public License for more details. | ||
4179 | 16 | |||
4180 | 17 | You should have received a copy of the GNU Lesser General Public | ||
4181 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
4182 | 19 | */ | ||
4183 | 20 | // Self | ||
4184 | 21 | #include <sourceid.h> | ||
4185 | 22 | |||
4186 | 23 | // Local | ||
4187 | 24 | |||
4188 | 25 | // KDE | ||
4189 | 26 | #include <KDebug> | ||
4190 | 27 | |||
4191 | 28 | // Qt | ||
4192 | 29 | #include <QStringList> | ||
4193 | 30 | |||
4194 | 31 | static const char SOURCE_NAME_SEPARATOR = ':'; | ||
4195 | 32 | |||
4196 | 33 | #define ARG_SEPARATOR ';' | ||
4197 | 34 | #define ARG_SEPARATOR_STR ";" | ||
4198 | 35 | static const char ARG_KEY_VALUE_SEPARATOR = '='; | ||
4199 | 36 | |||
4200 | 37 | //- SourceId ---------------------------------- | ||
4201 | 38 | QString SourceId::name() const | ||
4202 | 39 | { | ||
4203 | 40 | return m_name; | ||
4204 | 41 | } | ||
4205 | 42 | |||
4206 | 43 | void SourceId::setName(const QString &name) | ||
4207 | 44 | { | ||
4208 | 45 | m_name = name; | ||
4209 | 46 | } | ||
4210 | 47 | |||
4211 | 48 | SourceArguments &SourceId::arguments() | ||
4212 | 49 | { | ||
4213 | 50 | return m_arguments; | ||
4214 | 51 | } | ||
4215 | 52 | |||
4216 | 53 | const SourceArguments &SourceId::arguments() const | ||
4217 | 54 | { | ||
4218 | 55 | return m_arguments; | ||
4219 | 56 | } | ||
4220 | 57 | |||
4221 | 58 | QString SourceId::toString() const | ||
4222 | 59 | { | ||
4223 | 60 | if (m_arguments.isEmpty()) { | ||
4224 | 61 | return m_name; | ||
4225 | 62 | } | ||
4226 | 63 | return m_name % SOURCE_NAME_SEPARATOR % m_arguments.toString(); | ||
4227 | 64 | } | ||
4228 | 65 | |||
4229 | 66 | SourceId SourceId::fromString(const QString &sourceString, bool *ok) | ||
4230 | 67 | { | ||
4231 | 68 | *ok = true; | ||
4232 | 69 | SourceId sourceId; | ||
4233 | 70 | |||
4234 | 71 | int idx = sourceString.indexOf(SOURCE_NAME_SEPARATOR); | ||
4235 | 72 | if (idx == -1) { | ||
4236 | 73 | sourceId.setName(sourceString); | ||
4237 | 74 | return sourceId; | ||
4238 | 75 | } | ||
4239 | 76 | |||
4240 | 77 | sourceId.m_name = sourceString.left(idx); | ||
4241 | 78 | QString args = sourceString.mid(idx + 1); | ||
4242 | 79 | |||
4243 | 80 | sourceId.m_arguments = SourceArguments::fromString(args, ok); | ||
4244 | 81 | if (!*ok) { | ||
4245 | 82 | return SourceId(); | ||
4246 | 83 | } | ||
4247 | 84 | return sourceId; | ||
4248 | 85 | } | ||
4249 | 86 | |||
4250 | 87 | bool SourceId::isValid() const | ||
4251 | 88 | { | ||
4252 | 89 | return !m_name.isEmpty(); | ||
4253 | 90 | } | ||
4254 | 91 | |||
4255 | 92 | //- SourceArguments --------------------------- | ||
4256 | 93 | static QString escapeValue(const QString &src) | ||
4257 | 94 | { | ||
4258 | 95 | QString dst = src; | ||
4259 | 96 | dst.replace('\\', "\\\\"); // must be done first | ||
4260 | 97 | dst.replace(ARG_SEPARATOR, "\\" ARG_SEPARATOR_STR); | ||
4261 | 98 | return dst; | ||
4262 | 99 | } | ||
4263 | 100 | |||
4264 | 101 | static QStringList split(const QString &src) | ||
4265 | 102 | { | ||
4266 | 103 | bool escaped = false; | ||
4267 | 104 | QStringList lst; | ||
4268 | 105 | QString token; | ||
4269 | 106 | auto it = src.constBegin(), end = src.constEnd(); | ||
4270 | 107 | for (; it != end; ++it) { | ||
4271 | 108 | const QChar ch = *it; | ||
4272 | 109 | if (escaped) { | ||
4273 | 110 | escaped = false; | ||
4274 | 111 | } else if (ch == '\\') { | ||
4275 | 112 | escaped = true; | ||
4276 | 113 | continue; | ||
4277 | 114 | } else if (ch == ARG_SEPARATOR) { | ||
4278 | 115 | lst.append(token); | ||
4279 | 116 | token.clear(); | ||
4280 | 117 | continue; | ||
4281 | 118 | } | ||
4282 | 119 | token.append(ch); | ||
4283 | 120 | } | ||
4284 | 121 | lst.append(token); | ||
4285 | 122 | return lst; | ||
4286 | 123 | } | ||
4287 | 124 | |||
4288 | 125 | SourceArguments SourceArguments::fromString(const QString &str, bool *ok) | ||
4289 | 126 | { | ||
4290 | 127 | Q_ASSERT(ok); | ||
4291 | 128 | *ok = true; | ||
4292 | 129 | SourceArguments args; | ||
4293 | 130 | if (str.isEmpty()) { | ||
4294 | 131 | return args; | ||
4295 | 132 | } | ||
4296 | 133 | |||
4297 | 134 | QStringList tokens = split(str); | ||
4298 | 135 | Q_FOREACH(const QString &token, tokens) { | ||
4299 | 136 | int idx = token.indexOf(ARG_KEY_VALUE_SEPARATOR); | ||
4300 | 137 | if (idx == -1) { | ||
4301 | 138 | kWarning() << "Invalid argument" << token << "in" << str; | ||
4302 | 139 | *ok = false; | ||
4303 | 140 | return SourceArguments(); | ||
4304 | 141 | } | ||
4305 | 142 | QString key = token.left(idx); | ||
4306 | 143 | QString value = token.mid(idx + 1); | ||
4307 | 144 | args.insert(key, value); | ||
4308 | 145 | } | ||
4309 | 146 | return args; | ||
4310 | 147 | } | ||
4311 | 148 | |||
4312 | 149 | SourceArguments &SourceArguments::add(const QString &key, const QString &value) | ||
4313 | 150 | { | ||
4314 | 151 | insert(key, value); | ||
4315 | 152 | return *this; | ||
4316 | 153 | } | ||
4317 | 154 | |||
4318 | 155 | QString SourceArguments::toString() const | ||
4319 | 156 | { | ||
4320 | 157 | QStringList lst; | ||
4321 | 158 | auto it = constBegin(), end = constEnd(); | ||
4322 | 159 | for (; it != end ; ++it) { | ||
4323 | 160 | lst << it.key() % ARG_KEY_VALUE_SEPARATOR % escapeValue(it.value()); | ||
4324 | 161 | } | ||
4325 | 162 | return lst.join(ARG_SEPARATOR_STR); | ||
4326 | 163 | } | ||
4327 | 164 | 0 | ||
4328 | === removed file 'components/sourceid.h' | |||
4329 | --- components/sourceid.h 2012-11-14 21:30:06 +0000 | |||
4330 | +++ components/sourceid.h 1970-01-01 00:00:00 +0000 | |||
4331 | @@ -1,66 +0,0 @@ | |||
4332 | 1 | /* | ||
4333 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
4334 | 3 | |||
4335 | 4 | This library is free software; you can redistribute it and/or | ||
4336 | 5 | modify it under the terms of the GNU Lesser General Public | ||
4337 | 6 | License as published by the Free Software Foundation; either | ||
4338 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
4339 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
4340 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
4341 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
4342 | 11 | |||
4343 | 12 | This library is distributed in the hope that it will be useful, | ||
4344 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4345 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
4346 | 15 | Lesser General Public License for more details. | ||
4347 | 16 | |||
4348 | 17 | You should have received a copy of the GNU Lesser General Public | ||
4349 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
4350 | 19 | */ | ||
4351 | 20 | #ifndef SOURCEID_H | ||
4352 | 21 | #define SOURCEID_H | ||
4353 | 22 | |||
4354 | 23 | // Local | ||
4355 | 24 | |||
4356 | 25 | // Qt | ||
4357 | 26 | #include <QHash> | ||
4358 | 27 | #include <QString> | ||
4359 | 28 | |||
4360 | 29 | // KDE | ||
4361 | 30 | |||
4362 | 31 | /** | ||
4363 | 32 | * The arguments of a source. Used within a SourceId instance. | ||
4364 | 33 | */ | ||
4365 | 34 | class SourceArguments : public QHash<QString, QString> | ||
4366 | 35 | { | ||
4367 | 36 | public: | ||
4368 | 37 | SourceArguments &add(const QString &key, const QString &value); | ||
4369 | 38 | |||
4370 | 39 | QString toString() const; | ||
4371 | 40 | |||
4372 | 41 | static SourceArguments fromString(const QString &, bool *ok); | ||
4373 | 42 | }; | ||
4374 | 43 | |||
4375 | 44 | /** | ||
4376 | 45 | * Represents a source and its optional arguments | ||
4377 | 46 | */ | ||
4378 | 47 | class SourceId | ||
4379 | 48 | { | ||
4380 | 49 | public: | ||
4381 | 50 | void setName(const QString &); | ||
4382 | 51 | QString name() const; | ||
4383 | 52 | SourceArguments &arguments(); | ||
4384 | 53 | const SourceArguments &arguments() const; | ||
4385 | 54 | |||
4386 | 55 | QString toString() const; | ||
4387 | 56 | |||
4388 | 57 | static SourceId fromString(const QString &, bool *ok); | ||
4389 | 58 | |||
4390 | 59 | bool isValid() const; | ||
4391 | 60 | |||
4392 | 61 | private: | ||
4393 | 62 | QString m_name; | ||
4394 | 63 | SourceArguments m_arguments; | ||
4395 | 64 | }; | ||
4396 | 65 | |||
4397 | 66 | #endif /* SOURCEID_H */ | ||
4398 | 67 | 0 | ||
4399 | === modified file 'components/sourceregistry.cpp' | |||
4400 | --- components/sourceregistry.cpp 2012-11-14 21:30:06 +0000 | |||
4401 | +++ components/sourceregistry.cpp 2013-03-01 15:15:27 +0000 | |||
4402 | @@ -23,18 +23,20 @@ | |||
4403 | 23 | // Local | 23 | // Local |
4404 | 24 | #include <abstractsource.h> | 24 | #include <abstractsource.h> |
4405 | 25 | #include <customtypes.h> | 25 | #include <customtypes.h> |
4406 | 26 | #include <dirmodel.h> | ||
4407 | 27 | #include <favoriteappsmodel.h> | ||
4408 | 28 | |||
4409 | 29 | #include <groupedinstalledappsmodel.h> | ||
4410 | 30 | #include <libhomerun_config.h> | 26 | #include <libhomerun_config.h> |
4411 | 31 | #include <favoriteplacesmodel.h> | ||
4412 | 32 | #include <powermodel.h> | ||
4413 | 33 | #include <runnermodel.h> | ||
4414 | 34 | #include <installedappsmodel.h> | ||
4415 | 35 | #include <sessionmodel.h> | ||
4416 | 36 | #include <sourceconfigurationdialog.h> | 27 | #include <sourceconfigurationdialog.h> |
4417 | 37 | 28 | ||
4418 | 29 | #include <sources/dir/dirmodel.h> | ||
4419 | 30 | #include <sources/favorites/favoriteappsmodel.h> | ||
4420 | 31 | #include <sources/favorites/favoriteplacesmodel.h> | ||
4421 | 32 | #include <sources/installedapps/installedappsmodel.h> | ||
4422 | 33 | #include <sources/installedapps/groupedinstalledappsmodel.h> | ||
4423 | 34 | #include <sources/power/powermodel.h> | ||
4424 | 35 | #include <sources/runners/singlerunnermodel.h> | ||
4425 | 36 | #include <sources/runners/runnermodel.h> | ||
4426 | 37 | #include <sources/session/openedsessionsmodel.h> | ||
4427 | 38 | #include <sources/session/sessionmodel.h> | ||
4428 | 39 | |||
4429 | 38 | // KDE | 40 | // KDE |
4430 | 39 | #include <KConfigGroup> | 41 | #include <KConfigGroup> |
4431 | 40 | #include <KDebug> | 42 | #include <KDebug> |
4432 | @@ -42,6 +44,7 @@ | |||
4433 | 42 | #include <KPluginInfo> | 44 | #include <KPluginInfo> |
4434 | 43 | #include <KPluginLoader> | 45 | #include <KPluginLoader> |
4435 | 44 | #include <KServiceTypeTrader> | 46 | #include <KServiceTypeTrader> |
4436 | 47 | #include <Plasma/PluginLoader> | ||
4437 | 45 | 48 | ||
4438 | 46 | // Qt | 49 | // Qt |
4439 | 47 | #include <QApplication> | 50 | #include <QApplication> |
4440 | @@ -218,6 +221,20 @@ | |||
4441 | 218 | } | 221 | } |
4442 | 219 | return sourceInfo->source; | 222 | return sourceInfo->source; |
4443 | 220 | } | 223 | } |
4444 | 224 | |||
4445 | 225 | void registerSingleRunnerSources() | ||
4446 | 226 | { | ||
4447 | 227 | KPluginInfo::List list = Plasma::PluginLoader::pluginLoader()->listRunnerInfo(); | ||
4448 | 228 | Q_FOREACH(const KPluginInfo &info, list) { | ||
4449 | 229 | if (!info.property("X-Plasma-AdvertiseSingleRunnerQueryMode").toBool()) { | ||
4450 | 230 | continue; | ||
4451 | 231 | } | ||
4452 | 232 | QString runnerId = info.pluginName(); | ||
4453 | 233 | SingleRunnerSource *source = new SingleRunnerSource(runnerId, q); | ||
4454 | 234 | QString name = i18n("Runner: %1", info.name()); | ||
4455 | 235 | registerSource("SingleRunner/" + runnerId, source, name, info.comment()); | ||
4456 | 236 | } | ||
4457 | 237 | } | ||
4458 | 221 | }; | 238 | }; |
4459 | 222 | 239 | ||
4460 | 223 | //- SourceRegistry -------------------------------------------- | 240 | //- SourceRegistry -------------------------------------------- |
4461 | @@ -259,11 +276,17 @@ | |||
4462 | 259 | i18n("Session"), | 276 | i18n("Session"), |
4463 | 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") |
4464 | 261 | ); | 278 | ); |
4465 | 279 | d->registerSource("OpenedSessions", new SimpleSource<OpenedSessionsModel>(this), | ||
4466 | 280 | i18n("Opened Sessions"), | ||
4467 | 281 | i18n("Provide buttons to switch to opened sessions") | ||
4468 | 282 | ); | ||
4469 | 262 | d->registerSource("Runner", new RunnerSource(this), | 283 | d->registerSource("Runner", new RunnerSource(this), |
4470 | 263 | i18n("KRunner"), | 284 | i18n("KRunner"), |
4471 | 264 | i18n("Perform searchs using a selection of runners") | 285 | i18n("Perform searchs using a selection of runners") |
4472 | 265 | ); | 286 | ); |
4473 | 266 | 287 | ||
4474 | 288 | d->registerSingleRunnerSources(); | ||
4475 | 289 | |||
4476 | 267 | d->listSourcePlugins(); | 290 | d->listSourcePlugins(); |
4477 | 268 | } | 291 | } |
4478 | 269 | 292 | ||
4479 | 270 | 293 | ||
4480 | === added directory 'components/sources' | |||
4481 | === added directory 'components/sources/dir' | |||
4482 | === added file 'components/sources/dir/dirconfigurationwidget.cpp' | |||
4483 | --- components/sources/dir/dirconfigurationwidget.cpp 1970-01-01 00:00:00 +0000 | |||
4484 | +++ components/sources/dir/dirconfigurationwidget.cpp 2013-03-01 15:15:27 +0000 | |||
4485 | @@ -0,0 +1,67 @@ | |||
4486 | 1 | /* | ||
4487 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
4488 | 3 | |||
4489 | 4 | This library is free software; you can redistribute it and/or | ||
4490 | 5 | modify it under the terms of the GNU Lesser General Public | ||
4491 | 6 | License as published by the Free Software Foundation; either | ||
4492 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
4493 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
4494 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
4495 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
4496 | 11 | |||
4497 | 12 | This library is distributed in the hope that it will be useful, | ||
4498 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4499 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
4500 | 15 | Lesser General Public License for more details. | ||
4501 | 16 | |||
4502 | 17 | You should have received a copy of the GNU Lesser General Public | ||
4503 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
4504 | 19 | */ | ||
4505 | 20 | // Self | ||
4506 | 21 | #include <dirconfigurationwidget.h> | ||
4507 | 22 | |||
4508 | 23 | // Local | ||
4509 | 24 | #include <ui_dirconfigurationwidget.h> | ||
4510 | 25 | |||
4511 | 26 | // KDE | ||
4512 | 27 | #include <KGlobalSettings> | ||
4513 | 28 | #include <KUrlRequester> | ||
4514 | 29 | |||
4515 | 30 | // Qt | ||
4516 | 31 | #include <QDir> | ||
4517 | 32 | #include <QVBoxLayout> | ||
4518 | 33 | |||
4519 | 34 | using namespace Homerun; | ||
4520 | 35 | |||
4521 | 36 | DirConfigurationWidget::DirConfigurationWidget(const KConfigGroup &group) | ||
4522 | 37 | : SourceConfigurationWidget(group) | ||
4523 | 38 | , m_ui(new Ui_DirConfigurationWidget) | ||
4524 | 39 | { | ||
4525 | 40 | m_ui->setupUi(this); | ||
4526 | 41 | |||
4527 | 42 | QFont helpFont = KGlobalSettings::smallestReadableFont(); | ||
4528 | 43 | m_ui->titleHelpLabel->setFont(helpFont); | ||
4529 | 44 | |||
4530 | 45 | KUrl url = group.readPathEntry("rootUrl", QDir::homePath()); | ||
4531 | 46 | if (url.isValid()) { | ||
4532 | 47 | m_ui->urlRequester->setUrl(url); | ||
4533 | 48 | } | ||
4534 | 49 | |||
4535 | 50 | m_ui->titleLineEdit->setText(group.readEntry("rootName", QString())); | ||
4536 | 51 | } | ||
4537 | 52 | |||
4538 | 53 | DirConfigurationWidget::~DirConfigurationWidget() | ||
4539 | 54 | { | ||
4540 | 55 | delete m_ui; | ||
4541 | 56 | } | ||
4542 | 57 | |||
4543 | 58 | void DirConfigurationWidget::save() | ||
4544 | 59 | { | ||
4545 | 60 | KUrl url = m_ui->urlRequester->url().url(); | ||
4546 | 61 | QString title = m_ui->titleLineEdit->text(); | ||
4547 | 62 | |||
4548 | 63 | configGroup().writePathEntry("rootUrl", url.url()); | ||
4549 | 64 | configGroup().writeEntry("rootName", title); | ||
4550 | 65 | } | ||
4551 | 66 | |||
4552 | 67 | #include <dirconfigurationwidget.moc> | ||
4553 | 0 | 68 | ||
4554 | === added file 'components/sources/dir/dirconfigurationwidget.h' | |||
4555 | --- components/sources/dir/dirconfigurationwidget.h 1970-01-01 00:00:00 +0000 | |||
4556 | +++ components/sources/dir/dirconfigurationwidget.h 2013-03-01 15:15:27 +0000 | |||
4557 | @@ -0,0 +1,48 @@ | |||
4558 | 1 | /* | ||
4559 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
4560 | 3 | |||
4561 | 4 | This library is free software; you can redistribute it and/or | ||
4562 | 5 | modify it under the terms of the GNU Lesser General Public | ||
4563 | 6 | License as published by the Free Software Foundation; either | ||
4564 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
4565 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
4566 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
4567 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
4568 | 11 | |||
4569 | 12 | This library is distributed in the hope that it will be useful, | ||
4570 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4571 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
4572 | 15 | Lesser General Public License for more details. | ||
4573 | 16 | |||
4574 | 17 | You should have received a copy of the GNU Lesser General Public | ||
4575 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
4576 | 19 | */ | ||
4577 | 20 | #ifndef DIRCONFIGURATIONWIDGET_H | ||
4578 | 21 | #define DIRCONFIGURATIONWIDGET_H | ||
4579 | 22 | |||
4580 | 23 | // Local | ||
4581 | 24 | #include <sourceconfigurationwidget.h> | ||
4582 | 25 | |||
4583 | 26 | // Qt | ||
4584 | 27 | |||
4585 | 28 | // KDE | ||
4586 | 29 | |||
4587 | 30 | class Ui_DirConfigurationWidget; | ||
4588 | 31 | |||
4589 | 32 | /** | ||
4590 | 33 | * Configuration widget for the Dir source | ||
4591 | 34 | */ | ||
4592 | 35 | class DirConfigurationWidget : public Homerun::SourceConfigurationWidget | ||
4593 | 36 | { | ||
4594 | 37 | Q_OBJECT | ||
4595 | 38 | public: | ||
4596 | 39 | DirConfigurationWidget(const KConfigGroup &group); | ||
4597 | 40 | ~DirConfigurationWidget(); | ||
4598 | 41 | |||
4599 | 42 | void save(); // reimp | ||
4600 | 43 | |||
4601 | 44 | private: | ||
4602 | 45 | Ui_DirConfigurationWidget *m_ui; | ||
4603 | 46 | }; | ||
4604 | 47 | |||
4605 | 48 | #endif /* DIRCONFIGURATIONWIDGET_H */ | ||
4606 | 0 | 49 | ||
4607 | === added file 'components/sources/dir/dirconfigurationwidget.ui' | |||
4608 | --- components/sources/dir/dirconfigurationwidget.ui 1970-01-01 00:00:00 +0000 | |||
4609 | +++ components/sources/dir/dirconfigurationwidget.ui 2013-03-01 15:15:27 +0000 | |||
4610 | @@ -0,0 +1,83 @@ | |||
4611 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
4612 | 2 | <ui version="4.0"> | ||
4613 | 3 | <class>DirConfigurationWidget</class> | ||
4614 | 4 | <widget class="QWidget" name="DirConfigurationWidget"> | ||
4615 | 5 | <property name="geometry"> | ||
4616 | 6 | <rect> | ||
4617 | 7 | <x>0</x> | ||
4618 | 8 | <y>0</y> | ||
4619 | 9 | <width>400</width> | ||
4620 | 10 | <height>85</height> | ||
4621 | 11 | </rect> | ||
4622 | 12 | </property> | ||
4623 | 13 | <property name="sizePolicy"> | ||
4624 | 14 | <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | ||
4625 | 15 | <horstretch>0</horstretch> | ||
4626 | 16 | <verstretch>0</verstretch> | ||
4627 | 17 | </sizepolicy> | ||
4628 | 18 | </property> | ||
4629 | 19 | <property name="minimumSize"> | ||
4630 | 20 | <size> | ||
4631 | 21 | <width>400</width> | ||
4632 | 22 | <height>0</height> | ||
4633 | 23 | </size> | ||
4634 | 24 | </property> | ||
4635 | 25 | <property name="windowTitle"> | ||
4636 | 26 | <string/> | ||
4637 | 27 | </property> | ||
4638 | 28 | <layout class="QFormLayout" name="formLayout"> | ||
4639 | 29 | <item row="1" column="0"> | ||
4640 | 30 | <widget class="QLabel" name="label_2"> | ||
4641 | 31 | <property name="text"> | ||
4642 | 32 | <string>Folder to show:</string> | ||
4643 | 33 | </property> | ||
4644 | 34 | <property name="buddy"> | ||
4645 | 35 | <cstring>urlRequester</cstring> | ||
4646 | 36 | </property> | ||
4647 | 37 | </widget> | ||
4648 | 38 | </item> | ||
4649 | 39 | <item row="1" column="1"> | ||
4650 | 40 | <widget class="KUrlRequester" name="urlRequester"> | ||
4651 | 41 | <property name="mode"> | ||
4652 | 42 | <set>KFile::Directory|KFile::ExistingOnly</set> | ||
4653 | 43 | </property> | ||
4654 | 44 | </widget> | ||
4655 | 45 | </item> | ||
4656 | 46 | <item row="2" column="1"> | ||
4657 | 47 | <widget class="QLineEdit" name="titleLineEdit"/> | ||
4658 | 48 | </item> | ||
4659 | 49 | <item row="2" column="0"> | ||
4660 | 50 | <widget class="QLabel" name="label"> | ||
4661 | 51 | <property name="text"> | ||
4662 | 52 | <string>Title:</string> | ||
4663 | 53 | </property> | ||
4664 | 54 | <property name="buddy"> | ||
4665 | 55 | <cstring>titleLineEdit</cstring> | ||
4666 | 56 | </property> | ||
4667 | 57 | </widget> | ||
4668 | 58 | </item> | ||
4669 | 59 | <item row="3" column="1"> | ||
4670 | 60 | <widget class="QLabel" name="titleHelpLabel"> | ||
4671 | 61 | <property name="sizePolicy"> | ||
4672 | 62 | <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> | ||
4673 | 63 | <horstretch>0</horstretch> | ||
4674 | 64 | <verstretch>0</verstretch> | ||
4675 | 65 | </sizepolicy> | ||
4676 | 66 | </property> | ||
4677 | 67 | <property name="text"> | ||
4678 | 68 | <string>If title is left empty, the folder name will be used</string> | ||
4679 | 69 | </property> | ||
4680 | 70 | </widget> | ||
4681 | 71 | </item> | ||
4682 | 72 | </layout> | ||
4683 | 73 | </widget> | ||
4684 | 74 | <customwidgets> | ||
4685 | 75 | <customwidget> | ||
4686 | 76 | <class>KUrlRequester</class> | ||
4687 | 77 | <extends>QFrame</extends> | ||
4688 | 78 | <header>kurlrequester.h</header> | ||
4689 | 79 | </customwidget> | ||
4690 | 80 | </customwidgets> | ||
4691 | 81 | <resources/> | ||
4692 | 82 | <connections/> | ||
4693 | 83 | </ui> | ||
4694 | 0 | 84 | ||
4695 | === added file 'components/sources/dir/dirmodel.cpp' | |||
4696 | --- components/sources/dir/dirmodel.cpp 1970-01-01 00:00:00 +0000 | |||
4697 | +++ components/sources/dir/dirmodel.cpp 2013-03-01 15:15:27 +0000 | |||
4698 | @@ -0,0 +1,259 @@ | |||
4699 | 1 | /* | ||
4700 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
4701 | 3 | |||
4702 | 4 | This library is free software; you can redistribute it and/or | ||
4703 | 5 | modify it under the terms of the GNU Lesser General Public | ||
4704 | 6 | License as published by the Free Software Foundation; either | ||
4705 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
4706 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
4707 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
4708 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
4709 | 11 | |||
4710 | 12 | This library is distributed in the hope that it will be useful, | ||
4711 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4712 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
4713 | 15 | Lesser General Public License for more details. | ||
4714 | 16 | |||
4715 | 17 | You should have received a copy of the GNU Lesser General Public | ||
4716 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
4717 | 19 | */ | ||
4718 | 20 | // Self | ||
4719 | 21 | #include <dirmodel.h> | ||
4720 | 22 | |||
4721 | 23 | // Local | ||
4722 | 24 | #include <dirconfigurationwidget.h> | ||
4723 | 25 | #include <favoriteplacesmodel.h> | ||
4724 | 26 | |||
4725 | 27 | // libhomerun | ||
4726 | 28 | #include <actionlist.h> | ||
4727 | 29 | #include <pathmodel.h> | ||
4728 | 30 | |||
4729 | 31 | // KDE | ||
4730 | 32 | #include <KConfigGroup> | ||
4731 | 33 | #include <KDebug> | ||
4732 | 34 | #include <KDirModel> | ||
4733 | 35 | #include <KDirLister> | ||
4734 | 36 | |||
4735 | 37 | // Qt | ||
4736 | 38 | #include <QDir> | ||
4737 | 39 | |||
4738 | 40 | namespace Homerun | ||
4739 | 41 | { | ||
4740 | 42 | |||
4741 | 43 | static const char *SOURCE_ID = "Dir"; | ||
4742 | 44 | |||
4743 | 45 | static inline KFileItem itemForIndex(const QModelIndex &index) | ||
4744 | 46 | { | ||
4745 | 47 | return index.data(KDirModel::FileItemRole).value<KFileItem>(); | ||
4746 | 48 | } | ||
4747 | 49 | |||
4748 | 50 | //- DirModel ------------------------------------------------------ | ||
4749 | 51 | QVariantMap DirModel::sourceArguments(const KUrl &rootUrl, const QString &rootName, const KUrl &url) | ||
4750 | 52 | { | ||
4751 | 53 | QVariantMap args; | ||
4752 | 54 | args.insert("rootUrl", rootUrl.url()); | ||
4753 | 55 | args.insert("rootName", rootName); | ||
4754 | 56 | args.insert("url", url.url()); | ||
4755 | 57 | return args; | ||
4756 | 58 | } | ||
4757 | 59 | |||
4758 | 60 | |||
4759 | 61 | DirModel::DirModel(QObject *parent) | ||
4760 | 62 | : KDirSortFilterProxyModel(parent) | ||
4761 | 63 | , m_pathModel(new PathModel(this)) | ||
4762 | 64 | { | ||
4763 | 65 | setSourceModel(new KDirModel(this)); | ||
4764 | 66 | setSortFoldersFirst(true); | ||
4765 | 67 | |||
4766 | 68 | QHash<int, QByteArray> roles; | ||
4767 | 69 | roles.insert(Qt::DisplayRole, "display"); | ||
4768 | 70 | roles.insert(Qt::DecorationRole, "decoration"); | ||
4769 | 71 | roles.insert(DirModel::FavoriteIdRole, "favoriteId"); | ||
4770 | 72 | roles.insert(DirModel::HasActionListRole, "hasActionList"); | ||
4771 | 73 | roles.insert(DirModel::ActionListRole, "actionList"); | ||
4772 | 74 | setRoleNames(roles); | ||
4773 | 75 | |||
4774 | 76 | dirLister()->setDelayedMimeTypes(true); | ||
4775 | 77 | connect(dirLister(), SIGNAL(started(KUrl)), SLOT(emitRunningChanged())); | ||
4776 | 78 | connect(dirLister(), SIGNAL(completed()), SLOT(emitRunningChanged())); | ||
4777 | 79 | } | ||
4778 | 80 | |||
4779 | 81 | void DirModel::init(const KUrl &rootUrl, const QString &rootName, const KUrl &url) | ||
4780 | 82 | { | ||
4781 | 83 | m_rootUrl = rootUrl; | ||
4782 | 84 | m_rootName = rootName; | ||
4783 | 85 | initPathModel(url); | ||
4784 | 86 | dirLister()->openUrl(url); | ||
4785 | 87 | } | ||
4786 | 88 | |||
4787 | 89 | void DirModel::initPathModel(const KUrl &openedUrl) | ||
4788 | 90 | { | ||
4789 | 91 | QVariantMap args = sourceArguments(m_rootUrl, m_rootName, m_rootUrl); | ||
4790 | 92 | m_pathModel->addPath(m_rootName, SOURCE_ID, args); | ||
4791 | 93 | |||
4792 | 94 | KUrl rootUrl = m_rootUrl; | ||
4793 | 95 | // Needed for KUrl::relativeUrl | ||
4794 | 96 | rootUrl.adjustPath(KUrl::AddTrailingSlash); | ||
4795 | 97 | QString relativePath = KUrl::relativeUrl(rootUrl, openedUrl); | ||
4796 | 98 | if (relativePath == "./") { | ||
4797 | 99 | return; | ||
4798 | 100 | } | ||
4799 | 101 | KUrl url = m_rootUrl; | ||
4800 | 102 | Q_FOREACH(const QString &token, relativePath.split('/')) { | ||
4801 | 103 | if (token.isEmpty()) { | ||
4802 | 104 | // Just in case relativePath ends with '/' | ||
4803 | 105 | continue; | ||
4804 | 106 | } | ||
4805 | 107 | url.addPath(token); | ||
4806 | 108 | args["url"] = url.url(); | ||
4807 | 109 | m_pathModel->addPath(token, SOURCE_ID, args); | ||
4808 | 110 | } | ||
4809 | 111 | } | ||
4810 | 112 | |||
4811 | 113 | KDirLister *DirModel::dirLister() const | ||
4812 | 114 | { | ||
4813 | 115 | return static_cast<KDirModel *>(sourceModel())->dirLister(); | ||
4814 | 116 | } | ||
4815 | 117 | |||
4816 | 118 | QVariant DirModel::data(const QModelIndex &index, int role) const | ||
4817 | 119 | { | ||
4818 | 120 | if (role != FavoriteIdRole && role != HasActionListRole && role != ActionListRole) { | ||
4819 | 121 | return QSortFilterProxyModel::data(index, role); | ||
4820 | 122 | } | ||
4821 | 123 | if (index.row() < 0 || index.row() >= rowCount()) { | ||
4822 | 124 | return QVariant(); | ||
4823 | 125 | } | ||
4824 | 126 | if (role == HasActionListRole) { | ||
4825 | 127 | return true; | ||
4826 | 128 | } | ||
4827 | 129 | KFileItem item = itemForIndex(index); | ||
4828 | 130 | if (role == FavoriteIdRole) { | ||
4829 | 131 | if (item.isDir()) { | ||
4830 | 132 | return FavoritePlacesModel::favoriteIdFromUrl(item.url()); | ||
4831 | 133 | } else { | ||
4832 | 134 | return QString(); | ||
4833 | 135 | } | ||
4834 | 136 | } else if (role == ActionListRole) { | ||
4835 | 137 | return ActionList::createListForFileItem(item); | ||
4836 | 138 | } | ||
4837 | 139 | // Never reached | ||
4838 | 140 | return QVariant(); | ||
4839 | 141 | } | ||
4840 | 142 | |||
4841 | 143 | int DirModel::count() const | ||
4842 | 144 | { | ||
4843 | 145 | return rowCount(QModelIndex()); | ||
4844 | 146 | } | ||
4845 | 147 | |||
4846 | 148 | QString DirModel::name() const | ||
4847 | 149 | { | ||
4848 | 150 | return m_rootName; | ||
4849 | 151 | } | ||
4850 | 152 | |||
4851 | 153 | bool DirModel::running() const | ||
4852 | 154 | { | ||
4853 | 155 | return !dirLister()->isFinished(); | ||
4854 | 156 | } | ||
4855 | 157 | |||
4856 | 158 | PathModel *DirModel::pathModel() const | ||
4857 | 159 | { | ||
4858 | 160 | return m_pathModel; | ||
4859 | 161 | } | ||
4860 | 162 | |||
4861 | 163 | QString DirModel::query() const | ||
4862 | 164 | { | ||
4863 | 165 | return filterRegExp().pattern(); | ||
4864 | 166 | } | ||
4865 | 167 | |||
4866 | 168 | void DirModel::setQuery(const QString &value) | ||
4867 | 169 | { | ||
4868 | 170 | if (value == query()) { | ||
4869 | 171 | return; | ||
4870 | 172 | } | ||
4871 | 173 | setFilterRegExp(QRegExp(value, Qt::CaseInsensitive)); | ||
4872 | 174 | queryChanged(value); | ||
4873 | 175 | } | ||
4874 | 176 | |||
4875 | 177 | void DirModel::emitRunningChanged() | ||
4876 | 178 | { | ||
4877 | 179 | runningChanged(running()); | ||
4878 | 180 | } | ||
4879 | 181 | |||
4880 | 182 | bool DirModel::trigger(int row, const QString &actionId, const QVariant &actionArg) | ||
4881 | 183 | { | ||
4882 | 184 | QModelIndex idx = index(row, 0); | ||
4883 | 185 | KFileItem item = itemForIndex(idx); | ||
4884 | 186 | |||
4885 | 187 | if (actionId.isEmpty()) { | ||
4886 | 188 | if (item.isDir()) { | ||
4887 | 189 | openSourceRequested(SOURCE_ID, sourceArguments(m_rootUrl, m_rootName, item.url())); | ||
4888 | 190 | return false; | ||
4889 | 191 | } else { | ||
4890 | 192 | item.run(); | ||
4891 | 193 | return true; | ||
4892 | 194 | } | ||
4893 | 195 | } | ||
4894 | 196 | bool close = false; | ||
4895 | 197 | if (ActionList::handleFileItemAction(item, actionId, actionArg, &close)) { | ||
4896 | 198 | return close; | ||
4897 | 199 | } | ||
4898 | 200 | return false; | ||
4899 | 201 | } | ||
4900 | 202 | |||
4901 | 203 | //- DirSource ------------------------------------------------------- | ||
4902 | 204 | DirSource::DirSource(QObject *parent) | ||
4903 | 205 | : AbstractSource(parent) | ||
4904 | 206 | {} | ||
4905 | 207 | |||
4906 | 208 | QAbstractItemModel *DirSource::createModelFromArguments(const QVariantMap &args) | ||
4907 | 209 | { | ||
4908 | 210 | KUrl rootUrl = args.value("rootUrl").toString(); | ||
4909 | 211 | QString rootName = args.value("rootName").toString(); | ||
4910 | 212 | KUrl url = args.value("url").toString(); | ||
4911 | 213 | return createModel(rootUrl, rootName, url); | ||
4912 | 214 | } | ||
4913 | 215 | |||
4914 | 216 | QAbstractItemModel *DirSource::createModelFromConfigGroup(const KConfigGroup &group) | ||
4915 | 217 | { | ||
4916 | 218 | KUrl rootUrl = group.readPathEntry("rootUrl", QDir::homePath()); | ||
4917 | 219 | QString rootName = group.readEntry("rootName", QString()); | ||
4918 | 220 | return createModel(rootUrl, rootName, KUrl()); | ||
4919 | 221 | } | ||
4920 | 222 | |||
4921 | 223 | QAbstractItemModel *DirSource::createModel(const KUrl &rootUrl_, const QString &rootName_, const KUrl &url_) | ||
4922 | 224 | { | ||
4923 | 225 | KUrl rootUrl = rootUrl_; | ||
4924 | 226 | QString rootName = rootName_; | ||
4925 | 227 | KUrl url = url_; | ||
4926 | 228 | if (!rootUrl.isValid()) { | ||
4927 | 229 | rootUrl = KUrl::fromPath(QDir::homePath()); | ||
4928 | 230 | } | ||
4929 | 231 | |||
4930 | 232 | if (rootName.isEmpty()) { | ||
4931 | 233 | rootName = rootUrl.fileName(); | ||
4932 | 234 | if (rootName.isEmpty()) { | ||
4933 | 235 | rootName = rootUrl.prettyUrl(); | ||
4934 | 236 | } | ||
4935 | 237 | } | ||
4936 | 238 | if (!url.isValid()) { | ||
4937 | 239 | url = rootUrl; | ||
4938 | 240 | } | ||
4939 | 241 | |||
4940 | 242 | DirModel *model = new DirModel; | ||
4941 | 243 | model->init(rootUrl, rootName, url); | ||
4942 | 244 | return model; | ||
4943 | 245 | } | ||
4944 | 246 | |||
4945 | 247 | bool DirSource::isConfigurable() const | ||
4946 | 248 | { | ||
4947 | 249 | return true; | ||
4948 | 250 | } | ||
4949 | 251 | |||
4950 | 252 | SourceConfigurationWidget *DirSource::createConfigurationWidget(const KConfigGroup &group) | ||
4951 | 253 | { | ||
4952 | 254 | return new DirConfigurationWidget(group); | ||
4953 | 255 | } | ||
4954 | 256 | |||
4955 | 257 | } // namespace Homerun | ||
4956 | 258 | |||
4957 | 259 | #include <dirmodel.moc> | ||
4958 | 0 | 260 | ||
4959 | === added file 'components/sources/dir/dirmodel.h' | |||
4960 | --- components/sources/dir/dirmodel.h 1970-01-01 00:00:00 +0000 | |||
4961 | +++ components/sources/dir/dirmodel.h 2013-03-01 15:15:27 +0000 | |||
4962 | @@ -0,0 +1,113 @@ | |||
4963 | 1 | /* | ||
4964 | 2 | Copyright 2012 Aurélien Gâteau <agateau@kde.org> | ||
4965 | 3 | |||
4966 | 4 | This library is free software; you can redistribute it and/or | ||
4967 | 5 | modify it under the terms of the GNU Lesser General Public | ||
4968 | 6 | License as published by the Free Software Foundation; either | ||
4969 | 7 | version 2.1 of the License, or (at your option) version 3, or any | ||
4970 | 8 | later version accepted by the membership of KDE e.V. (or its | ||
4971 | 9 | successor approved by the membership of KDE e.V.), which shall | ||
4972 | 10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
4973 | 11 | |||
4974 | 12 | This library is distributed in the hope that it will be useful, | ||
4975 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4976 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
4977 | 15 | Lesser General Public License for more details. | ||
4978 | 16 | |||
4979 | 17 | You should have received a copy of the GNU Lesser General Public | ||
4980 | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
4981 | 19 | */ | ||
4982 | 20 | #ifndef DIRMODEL_H | ||
4983 | 21 | #define DIRMODEL_H | ||
4984 | 22 | |||
4985 | 23 | // Local | ||
4986 | 24 | #include <abstractsource.h> | ||
4987 | 25 | |||
4988 | 26 | // Qt | ||
4989 | 27 | |||
4990 | 28 | // KDE | ||
4991 | 29 | #include <KDirSortFilterProxyModel> | ||
4992 | 30 | #include <KUrl> | ||
4993 | 31 | |||
4994 | 32 | class KDirLister; | ||
4995 | 33 | |||
4996 | 34 | namespace Homerun { | ||
4997 | 35 | |||
4998 | 36 | class PathModel; | ||
4999 | 37 | |||
5000 | 38 | /** |
The diff has been truncated for viewing.
Great, thanks! according- to-package- name libhomerun-dev => libdevel
I fixed one additional thing:
W: libhomerun-dev: wrong-section-