~ubuntu-branches/ubuntu/quantal/ircp-tray/quantal

« back to all changes in this revision

Viewing changes to .pc/01-libnotify-0.7.patch/src/ircptray_main.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2011-08-05 02:24:46 UTC
  • mfrom: (0.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20110805022446-csa7fpk11d4tdmf1
Tags: 0.7.6-1.1
* Non-maintainer upload.
* Port to libnotify 0.7 (Closes: #630284)
  - Add debian/patches/01-libnotify-0.7.patch.
  - Bump Build-Depends on libnotify-dev to (>= 0.7.0).
* Don't look for translatable files in .pc/ as otherwise intltool will fail.
  - Add debian/patches/03-skip-po.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ircptray_main.c
 
2
 *
 
3
 * Copyright (C) 2004-2007 Xin Zhen
 
4
 * Copyright (C) 2008 Daniele Napolitano
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; either version 2
 
9
 * of the License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 */
 
20
 
 
21
#include <config.h>
 
22
#include "ircptray_main.h"
 
23
#include "debug.h"
 
24
 
 
25
#include <libnotify/notification.h>
 
26
#include <libnotify/notify.h>
 
27
 
 
28
#include <gtk/gtk.h>
 
29
#include <glib/gi18n-lib.h>
 
30
#include "ircptray_trayicon.h"
 
31
#include "resources.h"
 
32
#include "sendfile.h"
 
33
#include "recvfile.h"
 
34
#include "irda_misc.h"
 
35
 
 
36
/* Discover interval in seconds */
 
37
#define DISCOVERER_POLL_INTERVAL 3
 
38
/* user config path */
 
39
#define CONFIG_FILENAME "/ircp-tray.conf"
 
40
 
 
41
GtkStatusIcon* AppTrayIcon;
 
42
 
 
43
static gboolean check_irda_config()
 
44
{
 
45
 
 
46
        if (g_file_test("/var/run/irattach.pid", G_FILE_TEST_EXISTS))
 
47
            return TRUE;
 
48
        else {
 
49
            g_printerr("WW: /var/run/irattach.pid not found, assumed irattach not running");
 
50
            return FALSE;
 
51
        }
 
52
 
 
53
        /*
 
54
        char* data;
 
55
        FILE* fp;
 
56
        char** v1, ** v2;
 
57
        short int result;
 
58
 
 
59
        data = g_malloc(15);
 
60
        fp = fopen("/etc/default/irda-utils", "r");
 
61
 
 
62
        if(fp)
 
63
        {
 
64
                while(fgets(data, 15, fp))
 
65
                        if(g_str_has_prefix (data, "ENABLE") == TRUE) break;
 
66
 
 
67
                data = g_strstrip(data);
 
68
                v1 = g_strsplit(data, "=", 2);
 
69
                v2 = g_strsplit(v1[1], "\"", 3);
 
70
                result = strncmp("false", v2[1], 5 );
 
71
                fclose(fp);
 
72
        }
 
73
 
 
74
        printf("IrDA enabled: %s\n", v2[1]);
 
75
 
 
76
        g_strfreev(v2);
 
77
        g_strfreev(v1);
 
78
        g_free(data);
 
79
 
 
80
        if(result == 0) return FALSE;
 
81
        else return TRUE;
 
82
        */
 
83
 
 
84
}
 
85
 
 
86
void version_onclick(GtkMenuItem *menuitem, gpointer user_data)
 
87
{
 
88
 
 
89
        char* authors[] = {
 
90
                "Xin Zhen <xinzhen@pub.minidns.net>",
 
91
                "Daniele Napolitano <dnax88@gmail.com>",
 
92
                "",
 
93
                "Marcel Holtmann",
 
94
                "Pontus Fuchs",
 
95
                "Ragnar Henriksen",
 
96
                NULL
 
97
        };
 
98
 
 
99
        char* artists[] = {
 
100
                "Icon design: Jakub Steiner <jimmac@ximian.com>",
 
101
                "Animation: Dieter Vanderfaeillie <dieter.vanderfaeillie@gmail.com>",
 
102
                NULL
 
103
        };
 
104
 
 
105
        /* Feel free to put your names here translators :-) */
 
106
        char* translators = _("translator-credits");
 
107
 
 
108
        gtk_show_about_dialog(NULL,
 
109
                          "authors", authors,
 
110
                                      "artists", artists,
 
111
                                      "translator-credits", strcmp("translator-credits", translators) ? translators : NULL,
 
112
                          "comments", _("A utility for IrDA OBEX beaming and receiving"),
 
113
                          "copyright", "Copyright © 2004-2007 Xin Zhen \"LoneStar\"\nCopyright © 2008-2010 Daniele Napolitano \"DnaX\"",
 
114
                          "version", VERSION,
 
115
                          "website", "http://launchpad.net/ircp-tray",
 
116
                                      "logo-icon-name", MAIN_ICON,
 
117
                           NULL);
 
118
 
 
119
}
 
120
 
 
121
/* Get last save directory from user config file */
 
122
char* config_get_lastsavedir()
 
123
{
 
124
        char* lastsavedir = NULL;
 
125
        char* configfilename;
 
126
        GKeyFile* config;
 
127
 
 
128
        configfilename = g_strconcat (g_get_user_config_dir(),
 
129
                                      CONFIG_FILENAME,
 
130
                                      NULL);
 
131
 
 
132
        config = g_key_file_new();
 
133
        g_key_file_load_from_file(config, configfilename,
 
134
                G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
 
135
        lastsavedir = g_key_file_get_string(config, "General", "LastSaveDir",
 
136
                                                NULL);
 
137
        g_key_file_free(config);
 
138
        g_free(configfilename);
 
139
 
 
140
        return lastsavedir;
 
141
}
 
142
 
 
143
/* Save last save directory from user config file */
 
144
void config_set_lastsavedir(char* dir)
 
145
{
 
146
        char* configfilename;
 
147
        GKeyFile* config;
 
148
        char* configstr;
 
149
        FILE *configfile;
 
150
 
 
151
        configfilename = g_strconcat (g_get_user_config_dir(),
 
152
                                      CONFIG_FILENAME,
 
153
                                      NULL);
 
154
    g_print("%s\n", configfilename);
 
155
        config = g_key_file_new();
 
156
        g_key_file_load_from_file(config, configfilename,
 
157
                G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
 
158
        g_key_file_set_string(config, "General", "LastSaveDir", dir);
 
159
 
 
160
        configstr = g_key_file_to_data(config, NULL, NULL);
 
161
 
 
162
        configfile = fopen(configfilename, "w");
 
163
        fprintf(configfile, configstr, NULL);
 
164
        fclose(configfile);
 
165
 
 
166
        g_free(configstr);
 
167
        g_free(configfilename);
 
168
        g_key_file_free(config);
 
169
 
 
170
}
 
171
 
 
172
char* get_log_path()
 
173
{
 
174
        char* logfile;
 
175
        char filename[] = "/.ircp-tray_log";
 
176
 
 
177
        logfile = g_malloc(strlen(g_get_home_dir())+strlen(filename)+1);
 
178
        g_sprintf(logfile, "%s%s", g_get_home_dir(), filename);
 
179
 
 
180
        return logfile;
 
181
}
 
182
void log_file(const char* message)
 
183
{
 
184
        char* logfile;
 
185
        FILE* fp;
 
186
        char tmstr[21];
 
187
        time_t tm = time(NULL);
 
188
 
 
189
        printf("%s\n", message);
 
190
        strftime(tmstr, 20, "%x %X", localtime(&tm));
 
191
 
 
192
        logfile = get_log_path();
 
193
 
 
194
        fp = fopen(logfile, "a");
 
195
        if(fp) {
 
196
                fprintf(fp, "[%s] %s\n", tmstr, message);
 
197
                fclose(fp);
 
198
        }
 
199
        g_free(logfile);
 
200
}
 
201
 
 
202
static char *discoverer_name;
 
203
static int discoverer_hints[2];
 
204
 
 
205
/* Do some things on device discovered */
 
206
static void
 
207
gui_update_on_discovery (gchar *device_name)
 
208
{
 
209
    /* Refresh tray icon */
 
210
        trayicon_set_icon(ICON_TRAY);
 
211
 
 
212
        /* Update icon tray tooltip */
 
213
        gchar *tooltip_msg;
 
214
 
 
215
        tooltip_msg = g_strdup_printf (_("Infrared File Transfer: %s"), device_name);
 
216
        trayicon_set_tooltip_text(tooltip_msg);
 
217
        g_free(tooltip_msg);
 
218
 
 
219
        /* Activate device info menù item */
 
220
        trayicon_set_info_menuitem_sensitive(TRUE);
 
221
}
 
222
 
 
223
/* Do some things on device disappeared */
 
224
static void
 
225
gui_update_on_disappearing (guint num_devices)
 
226
{
 
227
    /* Refresh tray icon */
 
228
        trayicon_set_icon(ICON_TRAY_INACTIVE);
 
229
 
 
230
        /* Update icon tray tooltip */
 
231
        trayicon_set_tooltip_text(_("Infrared File Transfer") );
 
232
 
 
233
        /* Disable device info menù item on zero devices */
 
234
        if ( num_devices <= 0 )
 
235
            trayicon_set_info_menuitem_sensitive(FALSE);
 
236
 
 
237
}
 
238
 
 
239
/* Send notify on device discovered */
 
240
static void
 
241
notify_on_discovering (gchar *device_name, gchar *icon )
 
242
{
 
243
    NotifyNotification *notification = NULL;
 
244
        gchar *notify_msg;
 
245
 
 
246
        notify_msg = g_strdup_printf( _("Remote device discovered: %s"),
 
247
                                                              device_name);
 
248
 
 
249
        notification = notify_notification_new (g_get_application_name(),
 
250
                                            notify_msg,
 
251
                                            icon,
 
252
                                            NULL);
 
253
    if (notification == NULL) {
 
254
        g_warning("failed to setup notification");
 
255
        return;
 
256
    }
 
257
 
 
258
        notify_notification_attach_to_status_icon (notification, AppTrayIcon);
 
259
 
 
260
        if (!notify_notification_show (notification, NULL))
 
261
            g_warning("failed to send notification");
 
262
 
 
263
        /* destroy intantly if there isn't actions */
 
264
        g_object_unref(G_OBJECT(notification));
 
265
 
 
266
}
 
267
 
 
268
/* Send notify on device disappeared */
 
269
static void
 
270
notify_on_disappearing (gchar *device_name, gchar *icon )
 
271
{
 
272
    NotifyNotification *notification = NULL;
 
273
    gchar *notify_msg;
 
274
 
 
275
    notify_msg = g_strdup_printf( _("Remote device %s disappeared"),
 
276
                                                              device_name);
 
277
 
 
278
        notification = notify_notification_new (g_get_application_name(),
 
279
                                       notify_msg,
 
280
                                       icon,
 
281
                                       NULL);
 
282
 
 
283
        if (notification != NULL) {
 
284
            notify_notification_attach_to_status_icon (notification, AppTrayIcon);
 
285
 
 
286
                if (!notify_notification_show (notification, NULL))
 
287
                        g_warning("failed to send notification\n");
 
288
                g_object_unref(G_OBJECT(notification));
 
289
        }
 
290
        else
 
291
            g_warning("failed to setup notification");
 
292
 
 
293
}
 
294
 
 
295
GList *DevicesList;
 
296
guint NumDevices;
 
297
 
 
298
/* Function called each X seconds that detect device discovered
 
299
 * and disappeared. Then send notification and update GUI. */
 
300
static gboolean discover_do(gpointer data)
 
301
{
 
302
        GList *list;
 
303
    int i, c;
 
304
    dev_info *device, *device2;
 
305
    guint8 list_length;
 
306
    gboolean found;
 
307
 
 
308
        list = irda_discover_devices();
 
309
    list_length = g_list_length(list);
 
310
 
 
311
    /* Check for added devices */
 
312
    for(i = 0; i < list_length; i++)
 
313
    {
 
314
        device = g_list_nth_data(list, i);
 
315
 
 
316
        if(DevicesList == NULL)
 
317
        {
 
318
            /* Device discovered */
 
319
            g_print("* Device discovered: %s [0x%08x]\n",
 
320
                      device->name, device->daddr);
 
321
 
 
322
            notify_on_discovering (device->name, device->icon);
 
323
            gui_update_on_discovery (device->name);
 
324
 
 
325
            if(device->hints[1] & 0x20) {
 
326
                if(discoverer_name)
 
327
                    g_free(discoverer_name);
 
328
                discoverer_name = g_strdup(device->name);
 
329
                discoverer_hints[0] = device->hints[0];
 
330
                discoverer_hints[1] = device->hints[1];
 
331
            }
 
332
 
 
333
            continue;
 
334
        }
 
335
        for(c = 0; c < NumDevices; c++)
 
336
        {
 
337
            device2 = g_list_nth_data(DevicesList, c);
 
338
 
 
339
            if( device->daddr == device2->daddr ) {
 
340
 
 
341
                found = TRUE;
 
342
                break;
 
343
            }
 
344
            else
 
345
                found = FALSE;
 
346
        }
 
347
        /* Device discovered */
 
348
        if(found == FALSE)
 
349
        {
 
350
            g_print("* Device discovered: %s [0x%08x]\n",
 
351
                      device->name, device->daddr);
 
352
 
 
353
            notify_on_discovering (device->name, device->icon);
 
354
            gui_update_on_discovery (device->name);
 
355
 
 
356
            if(device->hints[1] & 0x20) {
 
357
                if(discoverer_name)
 
358
                    g_free(discoverer_name);
 
359
                discoverer_name = g_strdup(device->name);
 
360
                discoverer_hints[0] = device->hints[0];
 
361
                discoverer_hints[1] = device->hints[1];
 
362
            }
 
363
 
 
364
        }
 
365
    }
 
366
 
 
367
    /* Check for removed devices */
 
368
    for(i = 0; i < NumDevices; i++)
 
369
    {
 
370
        device = g_list_nth_data(DevicesList, i);
 
371
        found = FALSE;
 
372
 
 
373
        if(list != NULL)
 
374
            for(c = 0; c < list_length; c++)
 
375
            {
 
376
                    device2 = g_list_nth_data(list, c);
 
377
 
 
378
                    if(device->daddr == device2->daddr)
 
379
                    {
 
380
                        found = TRUE;
 
381
                        break;
 
382
                    }
 
383
                }
 
384
 
 
385
        /* Device disappeared */
 
386
            if(found == FALSE)
 
387
        {
 
388
            g_print("* Device disappeared: %s [0x%08x]\n",
 
389
                      device->name, device->daddr);
 
390
 
 
391
            notify_on_disappearing (device->name, device->icon);
 
392
            gui_update_on_disappearing (list_length);
 
393
 
 
394
            if(g_strcmp0(discoverer_name, device->name) == 0) {
 
395
                //discoverer_name = NULL;
 
396
                discoverer_hints[0] = 0;
 
397
                discoverer_hints[1] = 0;
 
398
            }
 
399
 
 
400
        }
 
401
    }
 
402
 
 
403
    free_devices_list (DevicesList);
 
404
    DevicesList = list;
 
405
    NumDevices = list_length;
 
406
 
 
407
    g_timeout_add_seconds(DISCOVERER_POLL_INTERVAL,
 
408
                              discover_do, NULL);
 
409
 
 
410
    return FALSE;
 
411
}
 
412
 
 
413
 
 
414
static void device_discovery_start()
 
415
{
 
416
    g_print("* Start polling of devices in range, interval %d seconds\n",
 
417
                                        DISCOVERER_POLL_INTERVAL);
 
418
        discover_do(NULL);
 
419
}
 
420
 
 
421
char* discoverer_get_name()
 
422
{
 
423
        return discoverer_name;
 
424
}
 
425
 
 
426
int* discoverer_get_hints()
 
427
{
 
428
        return discoverer_hints;
 
429
}
 
430
 
 
431
int discoverer_is_in_range()
 
432
{
 
433
        return NumDevices > 0;
 
434
}
 
435
 
 
436
static void
 
437
on_dialog_response (GtkDialog *dialog, gint response, gpointer ok_handler_data)
 
438
{
 
439
        if (response == GTK_RESPONSE_CLOSE) {
 
440
                gtk_widget_destroy (GTK_WIDGET (dialog));
 
441
 
 
442
                DEBUG(5,"Dialog destroyed\n");
 
443
        }
 
444
}
 
445
 
 
446
GtkWidget *
 
447
show_device_info_cb( void *data )
 
448
{
 
449
        GtkWidget *info;
 
450
        GtkWidget *vbox1;
 
451
        GtkWidget *close;
 
452
        GtkWidget *table1;
 
453
        GtkWidget *label1;
 
454
        GtkWidget *ck1;
 
455
        GtkWidget *aa1;
 
456
        gint i;
 
457
        gint y;
 
458
        GList *devs;
 
459
        dev_info *dev;
 
460
        gchar *labels[] = {_("<b>Hints</b>"),
 
461
                           _("PNP"),
 
462
                           _("PDA"),
 
463
                           _("COMPUTER"),
 
464
                           _("PRINTER"),
 
465
                           _("MODEM"),
 
466
                           _("FAX"),
 
467
                           _("LAN"),
 
468
                           _("EXTENSION"),
 
469
                           _("TELEPHONY"),
 
470
                           _("FILESERVER"),
 
471
                           _("COMM"),
 
472
                           _("MESSAGE"),
 
473
                           _("HTTP"),
 
474
                           _("OBEX"),
 
475
                           NULL
 
476
        };
 
477
 
 
478
        if ( NumDevices <= 0 )
 
479
                return 0;
 
480
 
 
481
        info = gtk_dialog_new ();
 
482
 
 
483
        // Window title
 
484
        gtk_window_set_title (GTK_WINDOW (info), _("Information"));
 
485
        gtk_window_set_resizable( GTK_WINDOW (info), FALSE );
 
486
 
 
487
        // RGBA patch
 
488
        //GdkScreen *screen = gtk_widget_get_screen(info);
 
489
        //GdkColormap *colormap = gdk_screen_get_rgba_colormap (screen);
 
490
 
 
491
        //if (colormap)
 
492
        //      gtk_widget_set_default_colormap(colormap);
 
493
 
 
494
        gtk_window_set_destroy_with_parent (GTK_WINDOW (info), TRUE);
 
495
        gtk_dialog_set_default_response (GTK_DIALOG (info), GTK_RESPONSE_CLOSE);
 
496
 
 
497
        vbox1 =  gtk_dialog_get_content_area (GTK_DIALOG (info));
 
498
        gtk_widget_show (vbox1);
 
499
 
 
500
        table1 = gtk_table_new (15, NumDevices+1, TRUE);
 
501
        gtk_widget_show (table1);
 
502
        gtk_box_pack_start (GTK_BOX (vbox1), table1, TRUE, TRUE, 0);
 
503
 
 
504
        /* Create labels */
 
505
        i = 0;
 
506
        while ( labels[i] ) {
 
507
                label1 = gtk_label_new (_(labels[i]));
 
508
                gtk_widget_show (label1);
 
509
                gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, i, i+1,
 
510
                                  (GtkAttachOptions) (GTK_FILL),
 
511
                                  (GtkAttachOptions) (0), 5, 0);
 
512
                gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT);
 
513
                gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);
 
514
                gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
 
515
                i++;
 
516
        }
 
517
 
 
518
        /* Adding checkboxes */
 
519
        devs = DevicesList;
 
520
        i = 0;
 
521
        while ( devs )
 
522
        {
 
523
                dev = (dev_info*) devs->data;
 
524
 
 
525
                label1 = gtk_label_new( dev->name );
 
526
                gtk_widget_show (label1);
 
527
                gtk_table_attach (GTK_TABLE (table1), label1, i+1, i+2, 0, 1,
 
528
                                  (GtkAttachOptions) (GTK_FILL),
 
529
                                  (GtkAttachOptions) (0), 5, 0);
 
530
                gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT);
 
531
                gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
 
532
 
 
533
                y = 1;
 
534
                while ( labels[y] ) {
 
535
                        ck1 = gtk_check_button_new();
 
536
                        gtk_widget_set_can_focus (ck1, FALSE);
 
537
                        gtk_widget_set_sensitive (ck1, FALSE);
 
538
 
 
539
                        if ( (y <= 8) && (dev->hints[0] & 1<<(y-1)) )
 
540
                                gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(ck1), 1 );
 
541
 
 
542
                        if ( (y > 7) && (dev->hints[1] & 1<<(y-9)) )
 
543
                                gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(ck1), 1 );
 
544
 
 
545
                        gtk_widget_show (ck1);
 
546
                        gtk_table_attach (GTK_TABLE (table1), ck1, i+1, i+2, y, y+1,
 
547
                                          (GtkAttachOptions) (GTK_FILL),
 
548
                                          (GtkAttachOptions) (0), 5, 0);
 
549
                        y++;
 
550
                }
 
551
                devs = devs->next;
 
552
                i++;
 
553
        }
 
554
 
 
555
        /* Create close button */
 
556
        aa1 = gtk_dialog_get_action_area (GTK_DIALOG (info));
 
557
        gtk_widget_show (aa1);
 
558
        gtk_button_box_set_layout (GTK_BUTTON_BOX (aa1), GTK_BUTTONBOX_END);
 
559
 
 
560
        close = gtk_button_new_from_stock ("gtk-close");
 
561
        gtk_widget_show (close);
 
562
        gtk_dialog_add_action_widget (GTK_DIALOG (info), close, GTK_RESPONSE_CLOSE);
 
563
        gtk_widget_set_can_default (close, TRUE);
 
564
 
 
565
        g_signal_connect (GTK_OBJECT (info), "response",
 
566
                            G_CALLBACK (on_dialog_response),
 
567
                            NULL);
 
568
 
 
569
        gtk_widget_show(info);
 
570
 
 
571
        return info;
 
572
}
 
573
 
 
574
int clean_log_file( GtkWidget* w, gpointer data )
 
575
{
 
576
        GtkTextBuffer *buffer = data;
 
577
        GtkTextIter *start_iter, *end_iter;
 
578
        char* logfile;
 
579
 
 
580
        logfile = get_log_path();
 
581
 
 
582
        if(g_remove (logfile))
 
583
        {
 
584
                g_print("Deleted log file: %s\n", logfile);
 
585
                gtk_text_buffer_set_text (buffer, "", -1);
 
586
                g_free(logfile);
 
587
                return TRUE;
 
588
        }
 
589
        else
 
590
        {
 
591
                g_free(logfile);
 
592
                return FALSE;
 
593
        }
 
594
}
 
595
 
 
596
static void
 
597
on_dialog_log_response(GtkDialog *dialog, gint response, gpointer ok_handler_data)
 
598
{
 
599
        if (response == GTK_RESPONSE_CLOSE) {
 
600
                gtk_widget_destroy (GTK_WIDGET (dialog));
 
601
 
 
602
                DEBUG(5,"Log Dialog destroyed\n");
 
603
        }
 
604
}
 
605
 
 
606
GtkWidget* show_log_file( void *data )
 
607
{
 
608
        GtkWidget *dialog, *button_clear, *button_close;
 
609
        GtkWidget *view, *scroll, *frame;
 
610
        GtkTextBuffer *buffer;
 
611
 
 
612
        char* logfile;
 
613
        char* content;
 
614
        FILE* fp;
 
615
        int len;
 
616
 
 
617
        logfile = get_log_path();
 
618
 
 
619
        content = g_malloc0(64 * 1024);
 
620
 
 
621
        fp = fopen(logfile, "r");
 
622
        if (fp)
 
623
                len = fread(content, 1, 64 * 1024, fp);
 
624
        else
 
625
                len = 0;
 
626
 
 
627
        // Dialog
 
628
        dialog = gtk_dialog_new();
 
629
        gtk_window_set_title (GTK_WINDOW (dialog), _("History"));
 
630
        gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE);
 
631
        gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
632
        g_object_set (dialog, "border_width", 5, NULL);
 
633
 
 
634
        // RGBA support
 
635
        GdkScreen *screen = gtk_widget_get_screen(dialog);
 
636
        GdkColormap *colormap = gdk_screen_get_rgba_colormap (screen);
 
637
 
 
638
        if (colormap)
 
639
                gtk_widget_set_default_colormap(colormap);
 
640
 
 
641
        // Frame
 
642
 
 
643
        frame = gtk_frame_new( _("<b>Transfers History</b>") );
 
644
        gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_NONE);
 
645
        gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), frame);
 
646
 
 
647
        // Frame Label
 
648
        gtk_label_set_use_markup( GTK_LABEL( gtk_frame_get_label_widget (GTK_FRAME(frame))), TRUE );
 
649
 
 
650
        // Scroll
 
651
        scroll = gtk_scrolled_window_new(NULL, NULL);
 
652
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scroll),
 
653
                                        GTK_POLICY_AUTOMATIC,
 
654
                                        GTK_POLICY_AUTOMATIC);
 
655
        gtk_container_add (GTK_CONTAINER (frame), scroll);
 
656
        gtk_widget_set_size_request(scroll, 400, 200);
 
657
 
 
658
        // TextView
 
659
        view = gtk_text_view_new ();
 
660
        gtk_text_view_set_editable( GTK_TEXT_VIEW (view), FALSE );
 
661
        gtk_text_view_set_cursor_visible( GTK_TEXT_VIEW (view), FALSE );
 
662
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (scroll), view);
 
663
 
 
664
        // Text Buffer
 
665
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
 
666
        gtk_text_buffer_set_text (buffer, content, len);
 
667
 
 
668
        // Buttons
 
669
        button_clear = gtk_button_new_from_stock( GTK_STOCK_CLEAR );
 
670
        gtk_container_add (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), button_clear);
 
671
 
 
672
        button_close = gtk_button_new_from_stock( GTK_STOCK_CLOSE );
 
673
        gtk_dialog_add_action_widget(GTK_DIALOG (dialog), button_close, GTK_RESPONSE_CLOSE);
 
674
 
 
675
        g_signal_connect (GTK_OBJECT (dialog), "response",
 
676
                            G_CALLBACK (on_dialog_log_response),
 
677
                            NULL);
 
678
 
 
679
        g_signal_connect(G_OBJECT (button_clear),
 
680
         "clicked",
 
681
                   G_CALLBACK (clean_log_file),
 
682
                   buffer);
 
683
 
 
684
        gtk_widget_show_all(dialog);
 
685
 
 
686
        g_free(content);
 
687
        if (fp)
 
688
                fclose(fp);
 
689
        g_free(logfile);
 
690
}
 
691
 
 
692
unsigned char
 
693
ircptray_app_new()
 
694
{
 
695
 
 
696
    //sanity check
 
697
    if(!irda_check()) //no irda support
 
698
    {
 
699
        GtkWidget* dialog;
 
700
 
 
701
        g_printerr("EE: irda kernel module not loaded, quit");
 
702
 
 
703
            dialog = gtk_message_dialog_new(NULL,
 
704
                                        GTK_DIALOG_MODAL,
 
705
                                        GTK_MESSAGE_ERROR,
 
706
                                        GTK_BUTTONS_CLOSE,
 
707
                                        _("You don't seem to have IrDA enabled in your kernel, quit."),
 
708
                                        NULL);
 
709
 
 
710
            gtk_dialog_run(GTK_DIALOG(dialog));
 
711
 
 
712
            return FALSE;
 
713
    }
 
714
 
 
715
    if( !check_irda_config() )
 
716
    {
 
717
                GtkWidget* dialog;
 
718
 
 
719
                dialog = gtk_message_dialog_new(NULL,
 
720
                                        GTK_DIALOG_MODAL,
 
721
                                        GTK_MESSAGE_WARNING,
 
722
                                        GTK_BUTTONS_CLOSE,
 
723
                                        _("IrDA service not started!"),
 
724
                                        NULL);
 
725
 
 
726
                gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),
 
727
                _("<i>You must edit <b>\"/etc/default/irda-utils\"</b> and set irattach to start it on boot.\n\nOtherwise, try typing in terminal:\n\n\"sudo irattach /dev/ttyS1 -s\"\n\nRead the irattach manual for more info.\n\n<span color=\"#f00000\" style=\"normal\"><b>%s will not be able to work.</b></span></i>"), g_get_application_name());
 
728
 
 
729
            gtk_window_set_title (GTK_WINDOW(dialog), "Ircp Tray");
 
730
                gtk_dialog_run(GTK_DIALOG(dialog));
 
731
                gtk_widget_destroy(dialog);
 
732
    }
 
733
 
 
734
    notify_init(PACKAGE);
 
735
 
 
736
    AppTrayIcon = trayicon_init();
 
737
 
 
738
    recvfile_listen(TRUE);
 
739
 
 
740
    device_discovery_start();
 
741
 
 
742
    return TRUE;
 
743
}