2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include "applet-launcher.h"
22
#include "applet-struct.h"
24
// if it's not in the exception list
25
static gboolean _is_an_exception (const gchar *cIndicatorName, gchar **cExceptionsList)
27
if (cExceptionsList != NULL)
29
for (int i = 0; cExceptionsList[i] != NULL; i++)
31
if (g_strcmp0 (cIndicatorName, cExceptionsList[i]) == 0)
38
static void _on_file_event (CairoDockFMEventType iEventType, const gchar *cURI, GldiModuleInstance *myApplet)
40
g_return_if_fail (cURI != NULL);
43
/* No need to reload all indicators if one is modified:
44
* these files are modified but the corresponding daemons are not reloaded
46
if (iEventType != CAIRO_DOCK_FILE_MODIFIED) // created/removed
48
cd_debug ("File event: Reload all indicators");
49
cd_indicator_generic_reload_all_indicators (myApplet);
55
void cd_indicator_generic_add_monitor_dir (GldiModuleInstance *myApplet)
57
cairo_dock_fm_add_monitor_full (cd_indicator3_get_directory_path (), TRUE,
58
NULL, (CairoDockFMMonitorCallback) _on_file_event, myApplet);
59
#ifdef IS_INDICATOR_NG
60
cairo_dock_fm_add_monitor_full (INDICATOR_SERVICE_DIR, TRUE,
61
NULL, (CairoDockFMMonitorCallback) _on_file_event, myApplet);
65
void cd_indicator_generic_remove_monitor_dir (void)
67
cairo_dock_fm_remove_monitor_full (cd_indicator3_get_directory_path (),
69
#ifdef IS_INDICATOR_NG
70
cairo_dock_fm_remove_monitor_full (INDICATOR_SERVICE_DIR, TRUE, NULL);
74
GDir * cd_indicator_generic_open_dir_modules (GldiModuleInstance *myApplet)
77
GDir *pDir = g_dir_open (cd_indicator3_get_directory_path (), 0, &error); // all indicators are on the same dir
80
cd_warning ("Failed to load indicator3 modules dir: %s", cd_indicator3_get_directory_path ());
86
GDir * cd_indicator_generic_open_dir_sevices (GldiModuleInstance *myApplet)
88
#ifdef IS_INDICATOR_NG
90
GDir *pDir = g_dir_open (INDICATOR_SERVICE_DIR, 0, &error); // all indicators are on the same dir
93
cd_warning ("Failed to load indicator3 services dir: %s", INDICATOR_SERVICE_DIR);
102
static gint _load_all_indicators_in_dir (GldiModuleInstance *myApplet, GDir *pDir, gboolean bIsModule)
104
// for each indicator file, instanciate a new plugin with it
105
// (useful to place it where we want, all icons are not regrouped into one big icon)
106
const gchar *cFileName;
107
gchar *cInstanceFilePath;
108
GldiModuleInstance *pModuleInstance;
110
while ((cFileName = g_dir_read_name (pDir)) != NULL)
112
if (*cFileName == '\0' || (bIsModule && ! g_str_has_suffix (cFileName, G_MODULE_SUFFIX))
113
|| _is_an_exception (cFileName, myConfig.cExceptionsList))
116
gchar *cUserDataDirPath = gldi_module_get_config_dir (myApplet->pModule);
117
// config file: indicator.so.conf ; e.g. libprintersmenu.so.conf
118
cInstanceFilePath = g_strdup_printf ("%s/%s.conf", cUserDataDirPath, cFileName);
119
if (! g_file_test (cInstanceFilePath, G_FILE_TEST_EXISTS))
121
// new indicator: create the .conf file
122
gchar *cConfFileOriginalPath = g_strdup_printf ("%s/%s",
123
cUserDataDirPath, myApplet->pModule->pVisitCard->cConfFileName);
125
GKeyFile *pKeyFile = cairo_dock_open_key_file (cConfFileOriginalPath);
126
g_free (cConfFileOriginalPath);
127
if (pKeyFile != NULL)
129
// added the indicator in the .conf file
130
g_key_file_set_string (pKeyFile, "Configuration", "indicator", cFileName);
131
// remove exceptions' lists
132
cairo_dock_remove_group_key_from_conf_file (pKeyFile, "Configuration", "except-edit");
133
g_key_file_remove_key (pKeyFile, "Configuration", "exceptions", NULL);
135
cairo_dock_write_keys_to_file (pKeyFile, cInstanceFilePath);
137
g_key_file_free (pKeyFile);
140
// create the new icon
141
pModuleInstance = gldi_module_instance_new (myApplet->pModule, cInstanceFilePath); // we don't have to free cInstanceFilePath
142
myData.pIndicatorsList = g_list_prepend (myData.pIndicatorsList, pModuleInstance);
143
g_free (cUserDataDirPath);
150
gint cd_indicator_generic_load_all_indicators (GldiModuleInstance *myApplet, GDir *pDirModules, GDir *pDirServices)
153
if (pDirModules != NULL)
154
iNbFiles = _load_all_indicators_in_dir (myApplet, pDirModules, TRUE);
155
if (pDirServices != NULL)
156
iNbFiles += _load_all_indicators_in_dir (myApplet, pDirServices, FALSE);
160
void cd_indicator_generic_reload_all_indicators (GldiModuleInstance *myApplet)
162
cd_debug ("Reload all indicators");
163
g_list_foreach (myData.pIndicatorsList, (GFunc)gldi_object_unref, NULL);
165
g_list_free (myData.pIndicatorsList);
166
myData.pIndicatorsList = NULL;
168
GDir *pDirModules = cd_indicator_generic_open_dir_modules (myApplet);
169
GDir *pDirServices = cd_indicator_generic_open_dir_sevices (myApplet);
170
if (pDirModules == NULL && pDirServices == NULL)
172
myApplet->pModule->pVisitCard->iContainerType = CAIRO_DOCK_MODULE_IS_PLUGIN; // dir is empty...
176
myApplet->pModule->pVisitCard->iContainerType = CAIRO_DOCK_MODULE_CAN_DOCK | CAIRO_DOCK_MODULE_CAN_DESKLET;
178
if (cd_indicator_generic_load_all_indicators (myApplet, pDirModules, pDirServices) == 0)
179
myApplet->pModule->pVisitCard->iContainerType = CAIRO_DOCK_MODULE_IS_PLUGIN; // dir is empty...