~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to Clipper/src/applet-init.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
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.
 
11
*
 
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/>.
 
18
*/
 
19
 
 
20
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include "stdlib.h"
 
30
 
 
31
#include "applet-config.h"
 
32
#include "applet-notifications.h"
 
33
#include "applet-clipboard.h"
 
34
#include "applet-struct.h"
 
35
#include "applet-init.h"
 
36
 
 
37
 
 
38
CD_APPLET_DEFINITION ("Clipper",
 
39
        1, 6, 3,
 
40
        CAIRO_DOCK_CATEGORY_ACCESSORY,
 
41
        N_("This applet keeps a trace of the clipboard and mouse selection,\n"
 
42
        "so that you can recall them quickly. It's a clone of the well-know Klipper.\n"
 
43
        "It supports clipboard and mouse selection, predefined actions, and persistent items.\n"
 
44
        "Left-click to popup the clipboard and mouse selection history,\n"
 
45
        "Drop text on the icon to create persistent items, and middle-clck to recall them."),
 
46
        "Fabrice Rey (Fabounet)")
 
47
 
 
48
 
 
49
//\___________ Here is where you initiate your applet. myConfig is already set at this point, and also myIcon, myContainer, myDock, myDesklet (and myDrawContext if you're in dock mode). The macro CD_APPLET_MY_CONF_FILE and CD_APPLET_MY_KEY_FILE can give you access to the applet's conf-file and its corresponding key-file (also available during reload). If you're in desklet mode, myDrawContext is still NULL, and myIcon's buffers has not been filled, because you may not need them then (idem when reloading).
 
50
CD_APPLET_INIT_BEGIN
 
51
        if (myDesklet)
 
52
        {
 
53
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
54
        }
 
55
        
 
56
        if (myIcon->acFileName == NULL)
 
57
        {
 
58
                CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON (MY_APPLET_ICON_FILE);
 
59
        }
 
60
        
 
61
        GtkClipboard *pClipBoard;
 
62
        if (myConfig.iItemType & CD_CLIPPER_CLIPBOARD)
 
63
        {
 
64
                pClipBoard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 
65
                myData.iSidClipboardOwnerChange = g_signal_connect (G_OBJECT (pClipBoard), "owner-change", G_CALLBACK(cd_clipper_selection_owner_changed), NULL);
 
66
        }
 
67
        
 
68
        if (myConfig.iItemType & CD_CLIPPER_PRIMARY)
 
69
        {
 
70
                pClipBoard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
 
71
                myData.iSidPrimaryOwnerChange = g_signal_connect (G_OBJECT (pClipBoard), "owner-change", G_CALLBACK(cd_clipper_selection_owner_changed), NULL);
 
72
        }
 
73
        
 
74
        //_on_text_received (NULL, "http://test.fr", NULL);
 
75
        //_on_text_received (NULL, "http://truc.fr", NULL);
 
76
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
 
77
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
 
78
        CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
 
79
        CD_APPLET_REGISTER_FOR_DROP_DATA_EVENT;
 
80
CD_APPLET_INIT_END
 
81
 
 
82
 
 
83
//\___________ Here is where you stop your applet. myConfig and myData are still valid, but will be reseted to 0 at the end of the function. In the end, your applet will go back to its original state, as if it had never been activated.
 
84
CD_APPLET_STOP_BEGIN
 
85
        CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
 
86
        CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
 
87
        CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
 
88
        CD_APPLET_UNREGISTER_FOR_DROP_DATA_EVENT;
 
89
        
 
90
        GtkClipboard *pClipBoard;
 
91
        if (myData.iSidClipboardOwnerChange != 0)
 
92
        {
 
93
                pClipBoard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 
94
                g_signal_handler_disconnect (pClipBoard, myData.iSidClipboardOwnerChange);
 
95
        }
 
96
        if (myData.iSidPrimaryOwnerChange != 0)
 
97
        {
 
98
                pClipBoard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
 
99
                g_signal_handler_disconnect (pClipBoard, myData.iSidPrimaryOwnerChange);
 
100
        }
 
101
CD_APPLET_STOP_END
 
102
 
 
103
 
 
104
//\___________ The reload occurs in 2 occasions : when the user changes the applet's config, and when the user reload the cairo-dock's config or modify the desklet's size. The macro CD_APPLET_MY_CONFIG_CHANGED can tell you this. myConfig has already been reloaded at this point if you're in the first case, myData is untouched. You also have the macro CD_APPLET_MY_CONTAINER_TYPE_CHANGED that can tell you if you switched from dock/desklet to desklet/dock mode.
 
105
CD_APPLET_RELOAD_BEGIN
 
106
        if (myDesklet)
 
107
        {
 
108
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
109
                gtk_widget_queue_draw (myDesklet->pWidget);
 
110
        }
 
111
        
 
112
        //\_______________ On recharge les donnees qui ont pu changer.
 
113
        if (CD_APPLET_MY_CONFIG_CHANGED)
 
114
        {
 
115
                if (myIcon->acFileName == NULL)
 
116
                {
 
117
                        CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON (MY_APPLET_ICON_FILE);
 
118
                }
 
119
                
 
120
                g_list_foreach (myData.pActions, (GFunc) cd_clipper_free_action, NULL);
 
121
                g_list_free (myData.pActions);
 
122
                myData.pActions = NULL;
 
123
                myData.bActionsLoaded = FALSE;
 
124
                
 
125
                GtkClipboard *pClipBoard;
 
126
                if (myConfig.iItemType & CD_CLIPPER_CLIPBOARD)
 
127
                {
 
128
                        if (myData.iSidClipboardOwnerChange == 0)
 
129
                        {
 
130
                                pClipBoard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 
131
                                myData.iSidClipboardOwnerChange = g_signal_connect (G_OBJECT (pClipBoard), "owner-change", G_CALLBACK(cd_clipper_selection_owner_changed), NULL);
 
132
                        }
 
133
                }
 
134
                else
 
135
                {
 
136
                        if (myData.iSidClipboardOwnerChange != 0)
 
137
                        {
 
138
                                pClipBoard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 
139
                                g_signal_handler_disconnect (pClipBoard, myData.iSidClipboardOwnerChange);
 
140
                                myData.iSidClipboardOwnerChange = 0;
 
141
                        }
 
142
                }
 
143
                
 
144
                if (myConfig.iItemType & CD_CLIPPER_PRIMARY)
 
145
                {
 
146
                        if (myData.iSidPrimaryOwnerChange == 0)
 
147
                        {
 
148
                                pClipBoard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
 
149
                                myData.iSidPrimaryOwnerChange = g_signal_connect (G_OBJECT (pClipBoard), "owner-change", G_CALLBACK(cd_clipper_selection_owner_changed), NULL);
 
150
                        }
 
151
                }
 
152
                else
 
153
                {
 
154
                        if (myData.iSidPrimaryOwnerChange != 0)
 
155
                        {
 
156
                                pClipBoard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
 
157
                                g_signal_handler_disconnect (pClipBoard, myData.iSidPrimaryOwnerChange);
 
158
                                myData.iSidPrimaryOwnerChange = 0;
 
159
                        }
 
160
                }
 
161
        }
 
162
CD_APPLET_RELOAD_END