-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindicate.c
203 lines (176 loc) · 5.81 KB
/
indicate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <libappindicator/app-indicator.h>
#include "config.h"
#include "indicate.h"
#include "umenu_glade.h"
#include "uabout.h"
#include "uoptions.h"
struct program_options *progopts = NULL;
char pathname[256];
int *force;
static const int user_loc = 6;
static GtkWidget **user_menu_items;
void build_menu(AppIndicator *);
void activate_about (GtkMenuItem *, gpointer);
void activate_options (GtkMenuItem *, gpointer);
void activate_refresh (GtkMenuItem *, gpointer);
void activate_pause (GtkCheckMenuItem *, gpointer);
void activate_jiggle (GtkCheckMenuItem *, gpointer);
void activate_quit (GtkMenuItem *, gpointer);
void activate_user (GtkCheckMenuItem *, gpointer);
void activate_about (GtkMenuItem *menu, gpointer data) {
if (menu == NULL && data == NULL) {
/* Bogus condition to use parameters */
;
}
open_uabout(pathname);
}
void activate_options (GtkMenuItem *menu, gpointer data) {
if (menu == NULL && data == NULL) {
/* Bogus condition to use parameters */
;
}
open_uoptions(pathname, progopts);
}
void activate_refresh (GtkMenuItem *menu, gpointer data) {
struct program_options options;
if (menu == NULL && data == NULL) {
/* Bogus condition to use parameters */
;
}
/* remove_menu_items();*/
get_configuration(&options);
if (options.menu_items != NULL) {
add_menu_items(options.menu_items);
}
}
void activate_pause (GtkCheckMenuItem *menu, gpointer data) {
gboolean pause;
if (data == NULL) {
/* Bogus condition to use parameters */
;
}
pause = gtk_check_menu_item_get_active(menu);
progopts->pause = pause ? 1 : 0;
}
void activate_jiggle (GtkCheckMenuItem *menu, gpointer data) {
gboolean jiggle;
if (data == NULL) {
/* Bogus condition to use parameters */
;
}
jiggle = gtk_check_menu_item_get_active(menu);
progopts->jiggle = jiggle ? 1 : 0;
}
void activate_quit (GtkMenuItem *menu, gpointer data) {
int idx;
if (menu == NULL && data == NULL) {
/* Bogus condition to use parameters */
;
}
*force = 1;
progopts->pause = 0;
progopts->jiggle = 0;
for (idx = 0; idx < progopts->menu_len; idx++) {
if (progopts->userdef[idx] > 1) {
progopts->userdef[idx] = -progopts->userdef[idx];
}
}
gtk_main_quit();
}
void activate_user (GtkCheckMenuItem *menu, gpointer data) {
const char *label;
gboolean active;
int idx = 0;
if (data == NULL) {
/* Bogus condition to use parameters */
;
}
label = gtk_menu_item_get_label((GtkMenuItem *)menu);
active = gtk_check_menu_item_get_active(menu);
for (idx = 0; idx < progopts->menu_len; idx++) {
if (!strcmp(progopts->menu_items[idx], label)) {
progopts->userdef[idx] = active ? 1 : -progopts->userdef[idx];
break;
}
}
}
void stop_indicator (void) {
activate_quit(NULL, NULL);
}
void init_indicator(int argc, char *argv[], char *path, struct program_options *options) {
strcpy(pathname, path);
progopts = options;
gtk_init(&argc, &argv);
load_umenu_from_file(pathname, 0);
}
void *run_indicator(void *arg) {
AppIndicator *indicator;
char icon[256];
force = (int *)arg;
strcpy(icon, pathname);
strcat(icon, "/clock_ind.png");
indicator = app_indicator_new("uManage-client", icon,
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_attention_icon(indicator, "indicator-messages-new");
build_menu(indicator);
gtk_main ();
return arg;
}
void build_menu(AppIndicator *indicator) {
app_indicator_set_menu(indicator, GTK_MENU(umenu_Indicator_Menu));
gtk_widget_show_all((GtkWidget*)umenu_Indicator_Menu);
g_signal_connect(umenu_Menu_Quit, "activate", G_CALLBACK(activate_quit), NULL);
g_signal_connect(umenu_Menu_Opts, "activate", G_CALLBACK(activate_options), NULL);
g_signal_connect(umenu_Menu_Refresh, "activate", G_CALLBACK(activate_refresh), NULL);
g_signal_connect(umenu_Menu_About, "activate", G_CALLBACK(activate_about), NULL);
g_signal_connect(umenu_Menu_Pause, "toggled", G_CALLBACK(activate_pause), NULL);
g_signal_connect(umenu_Menu_Jiggle, "toggled", G_CALLBACK(activate_jiggle), NULL);
}
int add_menu_items(char **items) {
int idx,
count = 0,
loc = 7;
GtkWidget *item;
for (idx = 0; items[idx] != NULL; idx++) {
++count;
}
user_menu_items = malloc(sizeof(GtkWidget*) * (count + 2));
user_menu_items[count + 1] = NULL;
for (idx = 0; idx < count; idx++) {
item = gtk_check_menu_item_new_with_label(items[idx]);
user_menu_items[idx] = item;
g_signal_connect(item, "activate", G_CALLBACK(activate_user), NULL);
gtk_menu_shell_insert((GtkMenuShell *)umenu_Indicator_Menu, item, loc);
++loc;
}
if (idx > 0) {
item = gtk_separator_menu_item_new();
g_object_ref((GObject*)item);
gtk_menu_shell_insert((GtkMenuShell *)umenu_Indicator_Menu, item, loc);
user_menu_items[count] = item;
g_object_unref((GObject*)item);
}
return idx;
}
int remove_menu_items(void) {
int idx;
GtkWidget *item;
if (user_menu_items == NULL) {
return 0;
}
for (idx = 0; user_menu_items[idx] != NULL; idx++) {
item = user_menu_items[idx];
g_object_ref((GObject*)item);
gtk_container_remove((GtkContainer*)umenu_Indicator_Menu, item);
/* gtk_widget_destroy((GtkWidget*)item);*/
g_object_unref((GObject*)item);
user_menu_items[idx] = NULL;
}
free(user_menu_items);
user_menu_items = NULL;
return idx;
}