+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file widget_location.h
+ * @author Iwanek Tomasz (t.iwanek@smasung.com)
+ */
+#ifndef WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H
+#define WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H
+
+#include <string>
+
+#include <dpl/shared_ptr.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+
+/**
+ * @brief The WidgetLocation class
+ *
+ * Object that stores locations of several files/directories according
+ * to package name
+ *
+ * Current package layout (of installed package) is following:
+ *
+ * /opt/apps/[package_name]
+ * \_____________ /data
+ * \_____________ /bin
+ * \_____________ /bin/[id_of_installed_package]
+ * \_____________ /res/wgt/
+ * \___ config.xml
+ * \___ [widgets_archive_content]
+ *
+ * 1) Normal Widget
+ * Developer provides content of res/wgt directory (package contains that directory as root).
+ *
+ * 2) For OSP Service Hybrid App is actually a bit different:
+ * Root is OSP Service directory, WebApp content is located in [root]/res/wgt
+ *
+ * Temporary directory is directory when widget is placed at the begining
+ * of installation process. After parsing process of config.xml, destination directory is created.
+ */
+class WidgetLocation
+{
+ class DirectoryDeletor
+ {
+ public:
+ DirectoryDeletor();
+ ~DirectoryDeletor();
+ std::string getTempPath() const;
+ private:
+ std::string m_dirpath;
+ };
+
+public:
+ DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
+ DECLARE_EXCEPTION_TYPE(Base, NoTemporaryPath)
+ /**
+ * @brief WidgetLocation
+ *
+ * Creates useless object. Needed by DPL::Optional
+ */
+ WidgetLocation();
+ /**
+ * @brief WidgetLocation Builds paths for widget location during uninstallation
+ *
+ * Uninstallation process needs only installed package directory.
+ *
+ * @param widgetname name of widget
+ */
+ WidgetLocation(const std::string & widgetname);
+ /**
+ * @brief WidgetLocation Builds paths for widget location during installation
+ *
+ * @param widgetname name of widget
+ * @param browserRequest is browser Request
+ * @param sourcePath given source path
+ * @param t declaraced type of widget if type is needed
+ *
+ * In destruction removes temporary directory
+ */
+ WidgetLocation(const std::string & widgetname, std::string sourcePath,
+ bool browserRequest = false, WrtDB::PkgType t = WrtDB::PKG_TYPE_TIZEN_WEBAPP);
+ ~WidgetLocation();
+
+ // Installed paths
+ std::string getInstallationDir() const; // /opt/apps
+ std::string getPackageInstallationDir() const; // /opt/apps/[package]
+ std::string getSourceDir() const; // /opt/apps/[package]/res/wgt
+ std::string getBinaryDir() const; // /opt/apps/[package]/bin
+ std::string getBackupDir() const; // /opt/apps/[package]/backup
+
+ bool browserRequest() const;
+
+ // Temporary paths
+ /**
+ * @brief getTemporaryRootDir
+ * @return value of root for developer's provide package (root of unpacked .wgt file)
+ */
+ std::string getTemporaryPackageDir() const;
+ /**
+ * @brief getTemporaryRootDir
+ *
+ * Value of this will differs according to type of installed widget.
+ *
+ * @return value of root for content in temporary directory to be copied into 'res/wgt'
+ */
+ std::string getTemporaryRootDir() const;
+ /**
+ * @brief getConfigurationDir Returns rott directory for configuration requirements
+ *
+ * 1) For packed widgets it is just root of unpacked sources
+ * 2) For browser installation it is directory name of widget passed to installer
+ *
+ * @return configuration directory
+ */
+ std::string getConfigurationDir() const;
+
+ //icons
+ /**
+ * @brief setIconTargetFilenameForLocale set installed ion path according to locale
+ * @param icon path of application icon
+ */
+ void setIconTargetFilenameForLocale(const std::string &icon);
+ /**
+ * @brief getIconTargetFilename gets icon path suffix for locale
+ * @param languageTag language tag
+ * @return value of suffix of path
+ */
+ DPL::String getIconTargetFilename(const DPL::String& languageTag) const;
+ /**
+ * @brief getIconTargetFilename gets icon full path
+ * @param languageTag language tag
+ * @return value of full path
+ */
+ std::string getInstalledIconPath() const;
+
+ /**
+ * @brief getWidgetSourcePath return widget's source path given to installer
+ * @return value of source path
+ */
+ std::string getWidgetSource() const;
+
+private:
+ std::string m_widgetSource; // Source widget zip file/widget url
+ bool m_browser; // is browser request installation
+ std::string m_pkgname; //name of package
+ std::string m_iconPath; //installed icon path
+ WrtDB::PkgType m_type;
+ DPL::SharedPtr<DirectoryDeletor> m_temp; //directory
+};
+
+#endif // WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H