~ubuntu-branches/ubuntu/saucy/alarm-clock-applet/saucy

« back to all changes in this revision

Viewing changes to src/ui.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin, Chow Loong Jin, Peter Pentchev
  • Date: 2011-03-29 00:25:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110329002540-73r2b2w3qss8wont
Tags: 0.3.2-1
[ Chow Loong Jin ]
* [48e1cb8] New upstream release:
  + New features:
    - Add support for application indicators
    - Countdown label for application indicator
    - New status icon indicating triggered alarms
  + Bugs fixed:
    - Add countdown label (for application indicator) (LP: #565302)
    - Create ~/.config/autostart if it doesn't exist (LP: #610632)
    - Add support for libnotify 0.7 (LP: #671962)
    - Properly stop triggered alarms that are not playing sound (LP: #682999)
    - Add support for application indicators (LP: #704956)
    - Clicking on status icon should bring up list instead of snoozing
      (LP: #706832)
  + Translation updates:
    - ar, courtesy of Ahmed Mohammed
    - ast, courtesy of Xuacu Saturio <xuacusk8@gmail.com>
    - be, courtesy of Mikola Tsekhan <mail@tsekhan.com>
    - ca, courtesy of I. De Marchi
    - cs, courtesy of Oliwer <linuch@centrum.cz>
    - de, courtesy of Christoph Wickert
    - es, courtesy of Fitoschido <fitoschido@gmail.com>
    - et, courtesy of Tarmo Ilves <tarmo.ilves.001@mail.ee>
    - fi, courtesy of Jiri Grönroos
    - fo, courtesy of Gunleif Joensen
    - fr, courtesy of Nicolas Delvaux
    - gl, courtesy of Miguel Anxo Bouzada <mbouzada@gmail.com>
    - he, courtesy of Yaron <sh.yaron@gmail.com>
    - hu, courtesy of Papp Bence <papp.bence89@gmail.com>
    - id, courtesy of Arief Setiadi Wibowo <q_thrynx@yahoo.com>
    - ja, courtesy of jugger Yamamoto
    - ka, courtesy of Giorgi Maghlakelidze <acidlabz@gmail.com>
    - la, courtesy of nivek1385 <nivek1385@yeltrahnivek.com>
    - nb, courtesy of Johannes H. Jensen <joh@pseudoberries.com>
    - nl, courtesy of Rachid
    - pl, courtesy of XeonBloomfield
    - pt_BR, courtesy of André Gondim <andregondim@ubuntu.com>
    - ru, courtesy of Сергій Матрунчик (SkyMan)
    - tr, courtesy of Burak Ilgıcıoğlu
    - uk, courtesy of Сергій Матрунчик (SkyMan)
    - zh_CN, courtesy of Lele Long <schemacs@gmail.com>
    - zh_TW, courtesy of Cheng-Chia Tseng <pswo10680@gmail.com>
* [002292e] Drop README.source since we use debsrc3.0
* [8dbb35e] No-change Standards-Version (3.8.4 → 3.9.1)
* [45f456f] Drop override_dh_auto_install (no longer needed)

[ Peter Pentchev ]
* [e8eaaa5] Fix a typo in the get-orig-source target.

Show diffs side-by-side

added added

removed removed

Lines of Context:
176
176
    NotifyNotification *n;
177
177
    GError *error = NULL;
178
178
 
179
 
    n = notify_notification_new_with_status_icon (summary, body, icon,
180
 
                                                  applet->status_icon);
 
179
    // Gotta love API breakage...
 
180
#ifdef HAVE_LIBNOTIFY_0_7
 
181
    n = notify_notification_new (summary, body, icon);
 
182
#else
 
183
    n = notify_notification_new (summary, body, icon, NULL);
 
184
#endif
181
185
    
182
186
    if (!notify_notification_show (n, &error)) {
183
187
        g_warning ("Failed to send notification: %s", error->message);
187
191
        g_object_unref(G_OBJECT(n));
188
192
}
189
193
 
 
194
void
 
195
alarm_applet_label_update (AlarmApplet *applet)
 
196
{
 
197
#ifdef HAVE_APP_INDICATOR
 
198
        GList *l;
 
199
        Alarm *a;
 
200
        Alarm *next_alarm = NULL;
 
201
        struct tm *tm;
 
202
        gchar *tmp;
 
203
        gboolean show_label = gtk_toggle_action_get_active (applet->action_toggle_show_label);
 
204
 
 
205
        if (!show_label) {
 
206
                app_indicator_set_label (applet->app_indicator, NULL, NULL);
 
207
                return;
 
208
        }
 
209
 
 
210
        //
 
211
        // Show countdown
 
212
        //
 
213
        for (l = applet->alarms; l; l = l->next) {
 
214
                a = ALARM (l->data);
 
215
                if (!a->active) continue;
 
216
 
 
217
                if (!next_alarm || a->timestamp < next_alarm->timestamp) {
 
218
                        next_alarm = a;
 
219
                }
 
220
        }
 
221
 
 
222
        if (!next_alarm) {
 
223
                // No upcoming alarms
 
224
                app_indicator_set_label (applet->app_indicator, NULL, NULL);
 
225
                return;
 
226
        }
 
227
 
 
228
        tm = alarm_get_remain (next_alarm);
 
229
        tmp = g_strdup_printf("%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
 
230
        app_indicator_set_label (applet->app_indicator, tmp, NULL);
 
231
        g_free(tmp);
 
232
 
 
233
#endif
 
234
}
 
235
 
 
236
/*
 
237
 * Updates label etc
 
238
 */
 
239
static gboolean
 
240
alarm_applet_ui_update (AlarmApplet *applet)
 
241
{
 
242
        alarm_applet_label_update (applet);
 
243
 
 
244
        //alarm_applet_update_tooltip (applet);
 
245
 
 
246
        return TRUE;
 
247
}
 
248
 
190
249
 
191
250
 
192
251
 
220
279
 
221
280
    /* Initialize preferences dialog */
222
281
    prefs_init (applet);
 
282
 
 
283
    /* Set up UI updater */
 
284
        alarm_applet_ui_update (applet);
 
285
        g_timeout_add_seconds (1, (GSourceFunc)alarm_applet_ui_update, applet);
223
286
}
224
287
 
225
288
/*
228
291
static void
229
292
alarm_applet_status_init (AlarmApplet *applet)
230
293
{
 
294
        applet->status_menu = GTK_WIDGET (gtk_builder_get_object (applet->ui, "status_menu"));
 
295
 
 
296
#ifdef HAVE_APP_INDICATOR
 
297
        applet->app_indicator = app_indicator_new(PACKAGE_NAME, ALARM_ICON,
 
298
                        APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
 
299
        app_indicator_set_status (applet->app_indicator, APP_INDICATOR_STATUS_ACTIVE);
 
300
        app_indicator_set_attention_icon (applet->app_indicator, TRIGGERED_ICON);
 
301
        app_indicator_set_menu (applet->app_indicator, GTK_MENU (applet->status_menu));
 
302
#else
231
303
    applet->status_icon = GTK_STATUS_ICON (gtk_builder_get_object (applet->ui, "status_icon"));
232
 
    applet->status_menu = GTK_WIDGET (gtk_builder_get_object (applet->ui, "status_menu"));
233
304
 
234
305
    gtk_status_icon_set_visible (applet->status_icon, TRUE);
 
306
#endif
235
307
}
236
308
 
237
309
/*
240
312
void
241
313
alarm_applet_status_update (AlarmApplet *applet)
242
314
{
 
315
#ifdef HAVE_APP_INDICATOR
 
316
        if (applet->n_triggered > 0) {
 
317
            app_indicator_set_status (applet->app_indicator, APP_INDICATOR_STATUS_ATTENTION);
 
318
        } else {
 
319
            app_indicator_set_status (applet->app_indicator, APP_INDICATOR_STATUS_ACTIVE);
 
320
        }
 
321
#else
 
322
    if (applet->n_triggered > 0) {
 
323
        gtk_status_icon_set_from_icon_name (applet->status_icon, TRIGGERED_ICON);
 
324
    } else {
 
325
        gtk_status_icon_set_from_icon_name (applet->status_icon, ALARM_ICON);
 
326
    }
243
327
    gtk_status_icon_set_blinking (applet->status_icon, applet->n_triggered > 0);
 
328
#endif
244
329
}
245
330
 
246
331
/*
247
332
 * Status icon callbacks:
248
333
 */
249
 
 
250
334
G_MODULE_EXPORT void
251
335
alarm_applet_status_activate (GtkStatusIcon *status_icon,
252
336
                                                          gpointer       user_data)
253
337
{
 
338
#ifndef HAVE_APP_INDICATOR
254
339
    AlarmApplet *applet = (AlarmApplet *)user_data;
255
 
 
256
 
    // Snooze triggered alarms if any
257
 
    if (applet->n_triggered > 0) {
258
 
        gtk_action_activate (applet->action_snooze_all);
259
 
    } else {
260
 
        // No alarms triggered, toggle list window
261
 
        gtk_action_activate (GTK_ACTION (applet->action_toggle_list_win));
262
 
    }
 
340
    
 
341
    // Toggle list window
 
342
    gtk_action_activate (GTK_ACTION (applet->action_toggle_list_win));
 
343
#endif
263
344
}
264
345
 
265
346
G_MODULE_EXPORT void
268
349
                           guint           activate_time,
269
350
                           gpointer        user_data)
270
351
{
 
352
#ifndef HAVE_APP_INDICATOR
271
353
    AlarmApplet *applet = (AlarmApplet *)user_data;
272
354
 
273
355
    gtk_menu_popup (GTK_MENU (applet->status_menu),
277
359
                    status_icon,
278
360
                    button,
279
361
                    activate_time);
 
362
#endif
280
363
}
281
364
 
282
365
/*