9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Main class for HsHomeScreenClientServiceProvider library. |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 #include <QDir> |
|
19 #include <QFileInfo> |
|
20 |
18 #include "hshomescreenclientserviceprovider.h" |
21 #include "hshomescreenclientserviceprovider.h" |
|
22 #include "hscontentservice.h" |
19 |
23 |
20 #include "hsscene.h" |
24 #include "hsscene.h" |
21 #include "hspage.h" |
|
22 #include "hsdomainmodeldatastructures.h" |
25 #include "hsdomainmodeldatastructures.h" |
23 #include "hswidgethost.h" |
26 #include "hswallpaper.h" |
|
27 #include "hsdatabase.h" |
|
28 #include "hswallpaperhelper.h" |
24 |
29 |
25 const char INTERFACE_NAME[] = "com.nokia.services.hsapplication.IHomeScreenClient"; |
30 #define HSBOUNDARYEFFECT 20 // amount of extra pixels in wallpaper width reserved for boundary effect |
26 |
31 |
27 HsHomeScreenClientServiceProvider::HsHomeScreenClientServiceProvider(QObject* parent) |
32 namespace |
28 : XQServiceProvider(INTERFACE_NAME,parent) |
33 { |
|
34 const char gInterfaceName[] = "com.nokia.services.hsapplication.IHomeScreenClient"; |
|
35 } |
|
36 |
|
37 /*! |
|
38 Constructor. |
|
39 */ |
|
40 HsHomeScreenClientServiceProvider::HsHomeScreenClientServiceProvider(QObject *parent) |
|
41 : XQServiceProvider(gInterfaceName, parent) |
29 { |
42 { |
30 publishAll(); |
43 publishAll(); |
31 } |
44 } |
32 |
45 |
|
46 /*! |
|
47 Destructor. |
|
48 */ |
33 HsHomeScreenClientServiceProvider::~HsHomeScreenClientServiceProvider() |
49 HsHomeScreenClientServiceProvider::~HsHomeScreenClientServiceProvider() |
34 { |
50 { |
35 } |
51 } |
36 |
52 |
37 #ifdef COVERAGE_MEASUREMENT |
53 #ifdef COVERAGE_MEASUREMENT |
38 #pragma CTC SKIP |
54 #pragma CTC SKIP |
39 #endif //COVERAGE_MEASUREMENT |
55 #endif //COVERAGE_MEASUREMENT |
40 |
56 |
41 // this should be moved to HsContentService class |
57 /*! |
|
58 Adds new widget, with the give \a uri and \a preferences, |
|
59 to the active home screen page. |
|
60 */ |
|
61 bool HsHomeScreenClientServiceProvider::addWidget(const QString &uri, const QVariantHash &preferences) |
|
62 { |
|
63 return HsContentService::instance()->addWidget(uri, preferences); |
|
64 } |
42 |
65 |
43 bool HsHomeScreenClientServiceProvider::addWidget(const QString &uri,const QVariantHash &preferences) |
66 /*! |
|
67 Changes \a fileName image to the active home screen page's wallpaper. |
|
68 */ |
|
69 bool HsHomeScreenClientServiceProvider::setWallpaper(const QString &fileName) |
44 { |
70 { |
45 |
71 HsScene *scene = HsScene::instance(); |
46 HsWidgetData widgetData; |
72 |
47 widgetData.uri = uri; |
73 HsDatabase *db = HsDatabase::instance(); |
48 |
74 Q_ASSERT(db); |
49 QScopedPointer<HsWidgetHost> widget(HsWidgetHost::createInstance(widgetData,preferences)); |
75 |
50 |
76 HsSceneData sceneData; |
51 if (!widget.data()) { |
77 if (!db->scene(sceneData)) { |
52 return false; |
78 return false; |
53 } |
79 } |
54 HsPage* activePage = HsScene::instance()->activePage(); |
80 |
55 if (!widget->load() || !activePage->addNewWidget(widget.data())) { |
81 QFileInfo fileInfo(fileName); |
56 widget->deleteFromDatabase(); |
82 QString fileExtension(""); |
57 return false; |
83 if (!fileInfo.suffix().isEmpty()) { |
|
84 fileExtension = fileInfo.suffix(); |
58 } |
85 } |
59 HsWidgetHost* taken = widget.take(); |
86 |
60 taken->initializeWidget(); |
87 QFile::remove(sceneData.portraitWallpaper); |
61 taken->showWidget(); |
88 QFile::remove(sceneData.landscapeWallpaper); |
62 activePage->layoutNewWidgets(); |
89 |
|
90 QString wallpaperDir = HsWallpaper::wallpaperDirectory(); |
|
91 QDir dir(wallpaperDir); |
|
92 if (!dir.exists()) { |
|
93 dir.mkpath(wallpaperDir); |
|
94 } |
|
95 |
|
96 QString portraitPath = HsWallpaper::wallpaperPath( |
|
97 Qt::Vertical, QString(), fileExtension); |
|
98 QString landscapePath = HsWallpaper::wallpaperPath( |
|
99 Qt::Horizontal, QString(), fileExtension); |
|
100 |
|
101 QRect portraitRect = QRect(0, 0, (2 * 360) + HSBOUNDARYEFFECT, 640); |
|
102 QRect landscapeRect = QRect(0, 0, (2 * 640) + HSBOUNDARYEFFECT, 360); |
|
103 QRect sourceRect; // left empty to signal we want to use full size image as source |
|
104 |
|
105 QImage portraitImage = HsWallpaperHelper::processImage(fileName, |
|
106 portraitRect, sourceRect); |
63 |
107 |
|
108 QImage landscapeImage = HsWallpaperHelper::processImage(fileName, |
|
109 landscapeRect, sourceRect); |
|
110 |
|
111 if (!portraitImage.isNull() && !landscapeImage.isNull()) { |
|
112 portraitImage.save(portraitPath); |
|
113 sceneData.portraitWallpaper = portraitPath; |
|
114 |
|
115 landscapeImage.save(landscapePath); |
|
116 sceneData.landscapeWallpaper = landscapePath; |
|
117 |
|
118 if (db->updateScene(sceneData)) { |
|
119 scene->wallpaper()->setImagesById(QString(), fileInfo.suffix()); |
|
120 } |
|
121 } |
|
122 else { |
|
123 // display some error note here |
|
124 } |
64 return true; |
125 return true; |
65 } |
126 } |
|
127 |
66 |
128 |
67 #ifdef COVERAGE_MEASUREMENT |
129 #ifdef COVERAGE_MEASUREMENT |
68 #pragma CTC ENDSKIP |
130 #pragma CTC ENDSKIP |
69 #endif //COVERAGE_MEASUREMENT |
131 #endif //COVERAGE_MEASUREMENT |
70 |
|