2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Filesystem/Path.h>
18 #include <vconf-keys.h>
19 #include <Commons/Exception.h>
20 #include <Filesystem/Manager.h>
21 #include <Profile/IManager.h>
23 namespace WrtDeviceApis {
26 Filesystem::Api::IPathPtr Desktop::getWallpaper() const
28 // TODO: conversion...?
29 return Filesystem::Api::IPath::create(m_wallpaperKey.getString());
32 void Desktop::setWallpaper(const Filesystem::Api::IPathPtr& path)
34 // TODO: probably we shouldn't expose full path
35 std::string p = path->getFullPath();
36 if (!Filesystem::Manager::fileExists(p)) {
37 LogError("Wallpaper not found. Path: " << p);
38 Throw(Commons::PlatformException);
40 m_wallpaperKey.setValue(p);
43 void Desktop::setWallpaper(const Api::EventSetWallpaperPtr& event)
45 EventSetWallpaperReqReceiver::PostRequest(event);
48 void Desktop::OnRequestReceived(const Api::EventSetWallpaperPtr& event)
52 if (Api::IManager::getInstance().getDesktopCount() == 0) {
53 Throw(Commons::UnsupportedException);
55 Api::IDesktopPtr desktop = Api::IManager::getInstance().getDesktop(
58 LogError("No default desktop.");
59 Throw(Commons::UnsupportedException);
62 desktop->setWallpaper(Filesystem::Api::IPath::create(event->getPathRef()));
64 Catch(Commons::PlatformException) {
65 LogError("platform exception");
66 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
68 Catch(Commons::UnsupportedException) {
69 LogError("unsupported exception");
70 event->setExceptionCode(Commons::ExceptionCodes::UnsupportedException);
72 Catch(Commons::InvalidArgumentException) {
73 LogError("invalid argument exception");
74 event->setExceptionCode(
75 Commons::ExceptionCodes::InvalidArgumentException);
79 Desktop::Desktop() : EventSetWallpaperReqReceiver(Commons::ThreadEnum::PROFILE_THREAD),
80 m_wallpaperKey(VCONFKEY_BGSET)