File: tray.c

package info (click to toggle)
multisync 0.82-9
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 15,784 kB
  • ctags: 5,488
  • sloc: ansic: 36,511; sh: 17,141; yacc: 1,377; makefile: 837
file content (171 lines) | stat: -rw-r--r-- 5,081 bytes parent folder | download | duplicates (4)
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
/* 
   MultiSync - A PIM data synchronization program

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 2 as
   published by the Free Software Foundation;

   In addition, as a special exception, Bo Lincoln <lincoln@lysator.liu.se>
   gives permission to link the code of this program with
   the OpenSSL library (or with modified versions of OpenSSL that use the
   same license as OpenSSL), and distribute linked combinations including
   the two.  You must obey the GNU General Public License in all
   respects for all of the code used other than OpenSSL.  If you modify
   this file, you may extend this exception to your version of the
   file, but you are not obligated to do so.  If you do not wish to
   do so, delete this exception statement from your version.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
   IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
   CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 
   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

   ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 
   COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 
   SOFTWARE IS DISCLAIMED.
*/

/*
 *  $Id: tray.c,v 1.2 2003/07/27 19:34:32 lincoln Exp $
 */

/* includes */
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <glib.h>
#include <gtk/gtk.h>
#include <gconf/gconf-client.h>
#include <gnome.h>
#include "callbacks.h"
#include "eggtrayicon.h"
#include "tray.h"

#include "syncengine.h"

extern GtkWidget* mainwindow; 

/* globals */
static EggTrayIcon *tray = NULL;
static GtkWidget *menu = NULL;

static gboolean tray_show_mainwindow(GtkWidget *widget, gboolean *force) {
    if (mainwindow && !*force) {
      sync_hide_gui();
    } else {
      sync_show_gui();
    }	
    return FALSE;
}

static gboolean tray_clicked(GtkWidget *widget, GdkEventButton *event) {
    static gboolean force = FALSE;

    if (event->type != GDK_BUTTON_PRESS) {
	return FALSE;
    }
    if (event->button == 1) {
	tray_show_mainwindow(widget, &force);
    } else  if (event->button == 3) {
	gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL,
		NULL, event->button, event->time);
	return TRUE;
    }

    return FALSE;
}

static gboolean tray_destroyed(GtkWidget *widget, GdkEvent *event) {
    return TRUE;
}

void show_tray() {
  GtkWidget *image, *box, *item;
  char *filename;
  static gboolean force = TRUE;

  tray = egg_tray_icon_new("Multisync");

  filename = g_strdup_printf("%s/%s", PACKAGE_DATA_DIR, 
			     "pixmaps/multisync-16.png");
  image = gtk_image_new_from_file (filename);
  g_free(filename);

  box = gtk_event_box_new();
  g_signal_connect(G_OBJECT(box), "button_press_event", 
		   G_CALLBACK(tray_clicked), NULL);

  menu = gtk_menu_new ();

  /* Main menu */
  item = gtk_menu_item_new_with_label ("Main Window");
  g_signal_connect(G_OBJECT (item), "activate", 
		   G_CALLBACK (tray_show_mainwindow), &force);
  gtk_widget_show (item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);

  /* About */
  item = gtk_image_menu_item_new_from_stock (GNOME_STOCK_MENU_ABOUT, NULL);
  g_signal_connect(G_OBJECT (item), "activate", 
		   G_CALLBACK (on_aboutmenu_activate), NULL);
  gtk_widget_show (item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);

  /* Quit */
#if 0
  item = gtk_image_menu_item_new_from_stock (GNOME_STOCK_MENU_QUIT, NULL);
  g_signal_connect(G_OBJECT (item), "activate", 
		   G_CALLBACK (on_mainwindow_delete_event), NULL);
  gtk_widget_show (item);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
#endif

  gtk_container_add(GTK_CONTAINER(box), image);
  gtk_container_add(GTK_CONTAINER(tray), box);
  gtk_widget_show_all(GTK_WIDGET(tray));

  g_signal_connect(G_OBJECT(tray), "destroy-event", 
		   G_CALLBACK(tray_destroyed), NULL);


}

static void
tray_gconf_notify (GConfClient *gconf,
		   guint        cnxn_id,
		   GConfEntry  *entry,
		   gpointer     user_data)
{
  GConfValue  *value;
  gboolean     checked;
  
  if (entry && !strcmp(gconf_entry_get_key(entry), 
			 SYNC_GCONF_PATH"/no_tray_icon")) {
    value = gconf_entry_get_value (entry);
    checked = gconf_value_get_bool (value);
    if (checked && tray) {
      gtk_widget_destroy(GTK_WIDGET(tray));
      tray = NULL;
    }
    if (!checked && !tray)
      show_tray();
  }    
}

void init_tray() {
  GConfClient *gconf = gconf_client_get_default ();

  gconf_client_notify_add (gconf, SYNC_GCONF_PATH"/no_tray_icon",
			   tray_gconf_notify, NULL, NULL, NULL);
  if (!gconf_client_get_bool (gconf, SYNC_GCONF_PATH"/no_tray_icon", 
			      NULL))
    show_tray();
  
  g_object_unref(gconf);

}