ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

unity-taskbar.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
00024 #define FORBIDDEN_SYMBOL_EXCEPTION_time_h
00025 #include "common/scummsys.h"
00026 
00027 #if defined(POSIX) && defined(USE_TASKBAR) && defined(USE_UNITY)
00028 
00029 #define GLIB_DISABLE_DEPRECATION_WARNINGS
00030 
00031 #include "backends/taskbar/unity/unity-taskbar.h"
00032 
00033 #include "common/textconsole.h"
00034 
00035 #include <unity.h>
00036 
00037 UnityTaskbarManager::UnityTaskbarManager() {
00038     /*
00039      *  Deprecated in Glib >= 2.36.0
00040      */
00041     if (!glib_check_version(2, 36, 0)) {
00042         g_type_init();
00043     }
00044 
00045     _loop = g_main_loop_new(NULL, FALSE);
00046 
00047     _launcher = unity_launcher_entry_get_for_desktop_id("residualvm.desktop");
00048 }
00049 
00050 UnityTaskbarManager::~UnityTaskbarManager() {
00051     g_main_loop_unref(_loop);
00052     _loop = NULL;
00053 }
00054 
00055 void UnityTaskbarManager::setProgressValue(int completed, int total) {
00056     if (_launcher == NULL)
00057         return;
00058 
00059     double percentage = (double)completed / (double)total;
00060     unity_launcher_entry_set_progress(_launcher, percentage);
00061     unity_launcher_entry_set_progress_visible(_launcher, TRUE);
00062 }
00063 
00064 void UnityTaskbarManager::setProgressState(TaskbarProgressState state) {
00065     if (_launcher == NULL)
00066         return;
00067 
00068     switch (state) {
00069     default:
00070         warning("[UnityTaskbarManager::setProgressState] Unknown state / Not implemented (%d)", state);
00071         // fallback to noprogress state
00072 
00073     case kTaskbarNoProgress:
00074         unity_launcher_entry_set_progress_visible(_launcher, FALSE);
00075         break;
00076 
00077     // Unity only support two progress states as of 3.0: visible or not visible
00078     // We show progress in all of those states
00079     case kTaskbarIndeterminate:
00080     case kTaskbarNormal:
00081     case kTaskbarError:
00082     case kTaskbarPaused:
00083         unity_launcher_entry_set_progress_visible(_launcher, TRUE);
00084         break;
00085     }
00086 }
00087 
00088 void UnityTaskbarManager::addRecent(const Common::String &name, const Common::String &description) {
00089     warning("[UnityTaskbarManager::addRecent] Not implemented");
00090 }
00091 
00092 void UnityTaskbarManager::setCount(int count) {
00093     if (_launcher == NULL)
00094         return;
00095 
00096     unity_launcher_entry_set_count(_launcher, count);
00097 
00098     unity_launcher_entry_set_count_visible(_launcher, (count == 0) ? FALSE : TRUE);
00099 }
00100 
00101 // Unity requires the glib event loop to the run to function properly
00102 // as events are sent asynchronously
00103 bool UnityTaskbarManager::pollEvent(Common::Event &event) {
00104     if (!_loop)
00105         return false;
00106 
00107     // Get context
00108     GMainContext *context = g_main_loop_get_context(_loop);
00109     if (!context)
00110         return false;
00111 
00112     // Dispatch events
00113     g_main_context_iteration(context, FALSE);
00114 
00115     return false;
00116 }
00117 
00118 #endif


Generated on Sat Feb 16 2019 05:01:10 for ResidualVM by doxygen 1.7.1
curved edge   curved edge