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

« back to all changes in this revision

Viewing changes to tomboy/src/tomboy-notifications.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
#include <stdlib.h>
 
21
#include <glib/gi18n.h>
 
22
#define __USE_POSIX
 
23
#include <time.h>
 
24
 
 
25
#include "tomboy-dbus.h"
 
26
#include "tomboy-draw.h"
 
27
#include "tomboy-struct.h"
 
28
#include "tomboy-notifications.h"
 
29
 
 
30
 
 
31
CD_APPLET_ON_CLICK_BEGIN
 
32
        if (pClickedIcon != NULL && pClickedIcon != myIcon)
 
33
        {
 
34
                cd_message("tomboy : %s",pClickedIcon->acCommand);
 
35
                showNote(pClickedIcon->acCommand);
 
36
        }
 
37
        else if (pClickedIcon == myIcon && ! myData.opening)  // possible si on l'a quitte apres le demarrage de l'applet.
 
38
        {
 
39
                dbus_detect_tomboy();
 
40
                if (! myData.opening)
 
41
                {
 
42
                        dbus_detect_tomboy();
 
43
                        free_all_notes ();
 
44
                        getAllNotes();
 
45
                        cd_tomboy_load_notes();
 
46
                }
 
47
        }
 
48
        else
 
49
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
50
CD_APPLET_ON_CLICK_END
 
51
 
 
52
 
 
53
static void _cd_tomboy_create_new_note (Icon *pIcon)
 
54
{
 
55
        if (pIcon == NULL)
 
56
                pIcon = myIcon;
 
57
        gchar *note_title;
 
58
        if (myConfig.bAutoNaming)
 
59
        {
 
60
                g_print ("on nomme automatiquement cette note\n");
 
61
                note_title = g_new0 (gchar, 50+1);
 
62
                time_t epoch = (time_t) time (NULL);
 
63
                struct tm currentTime;
 
64
                localtime_r (&epoch, &currentTime);
 
65
                strftime (note_title, 50, "%a-%d-%b_%r", &currentTime);
 
66
        }
 
67
        else
 
68
        {
 
69
                g_print ("on demande le nom de la nouvelle note ...\n");
 
70
                note_title = cairo_dock_show_demand_and_wait (D_("Note name : "),
 
71
                        pIcon,
 
72
                        (pIcon != myIcon && myDock ? CAIRO_CONTAINER (myIcon->pSubDock) : myContainer),
 
73
                        NULL);
 
74
                g_print ("on a recu '%s'\n", note_title);
 
75
        }
 
76
        cd_message ("%s (%s)", __func__, note_title);
 
77
        gchar *note_name = addNote(note_title);
 
78
        cd_debug (" note_name <- %s", note_name);
 
79
        showNote(note_name);
 
80
        g_free (note_name);
 
81
        g_free (note_title);
 
82
}
 
83
static void _cd_tomboy_add_note (GtkMenuItem *menu_item, Icon *pIcon)
 
84
{
 
85
        _cd_tomboy_create_new_note (pIcon);
 
86
}
 
87
static void _cd_tomboy_delete_note (GtkMenuItem *menu_item, Icon *pIcon)
 
88
{
 
89
        if (pIcon == NULL)
 
90
                return ;
 
91
        if (myConfig.bAskBeforeDelete)
 
92
        {
 
93
                gchar *cQuestion = g_strdup_printf ("%s (%s)", D_("Delete this note ?"), pIcon->acName);
 
94
                int iAnswer = cairo_dock_ask_question_and_wait (cQuestion, pIcon, myDock ? CAIRO_CONTAINER (myIcon->pSubDock) : myContainer);
 
95
                g_free (cQuestion);
 
96
                if (iAnswer != GTK_RESPONSE_YES)
 
97
                        return ;
 
98
        }
 
99
        deleteNote (pIcon->acCommand);
 
100
}
 
101
static void _cd_tomboy_reload_notes (GtkMenuItem *menu_item, Icon *pIcon)
 
102
{
 
103
        free_all_notes ();
 
104
        getAllNotes();
 
105
        cd_tomboy_load_notes();
 
106
}
 
107
static void _cd_tomboy_search_for_content (GtkMenuItem *menu_item, Icon *pIcon)
 
108
{
 
109
        gchar *cContent = cairo_dock_show_demand_and_wait (D_("Search for :"),
 
110
                (pIcon != NULL ? pIcon : myIcon),
 
111
                (pIcon != NULL && myDock ? CAIRO_CONTAINER (myIcon->pSubDock) : myContainer),
 
112
                NULL);
 
113
        if (cContent != NULL)
 
114
        {
 
115
                cd_tomboy_reset_icon_marks (FALSE);
 
116
                gchar *cContents[2] = {cContent, NULL};
 
117
                GList *pList = cd_tomboy_find_notes_with_contents (cContents);
 
118
                g_free (cContent);
 
119
                if (pList != NULL)
 
120
                {
 
121
                        cd_tomboy_mark_icons (pList, TRUE);
 
122
                        g_list_free (pList);
 
123
                        if (myDock)
 
124
                                cairo_dock_show_dock_at_mouse (myIcon->pSubDock);
 
125
                }
 
126
        }
 
127
}
 
128
static void _cd_tomboy_search_for_tag (GtkMenuItem *menu_item, Icon *pIcon)
 
129
{
 
130
        gchar *cTag = cairo_dock_show_demand_and_wait (D_("Search for tag :"),
 
131
                (pIcon != NULL ? pIcon : myIcon),
 
132
                (pIcon != NULL && myDock ? CAIRO_CONTAINER (myIcon->pSubDock) : myContainer),
 
133
                NULL);
 
134
        if (cTag != NULL)
 
135
        {
 
136
                cd_tomboy_reset_icon_marks (FALSE);
 
137
                GList *pList = cd_tomboy_find_notes_with_tag (cTag);
 
138
                g_free (cTag);
 
139
                if (pList != NULL)
 
140
                {
 
141
                        cd_tomboy_mark_icons (pList, TRUE);
 
142
                        g_list_free (pList);
 
143
                        if (myDock)
 
144
                                cairo_dock_show_dock_at_mouse (myIcon->pSubDock);
 
145
                }
 
146
        }
 
147
}
 
148
static void _cd_tomboy_search_for_today (GtkMenuItem *menu_item, Icon *pIcon)
 
149
{
 
150
        GList *pList = cd_tomboy_find_note_for_today ();
 
151
        if (pList != NULL)
 
152
        {
 
153
                cd_tomboy_mark_icons (pList, TRUE);
 
154
                g_list_free (pList);
 
155
                if (myDock)
 
156
                        cairo_dock_show_dock_at_mouse (myIcon->pSubDock);
 
157
        }
 
158
}
 
159
static void _cd_tomboy_search_for_this_week (GtkMenuItem *menu_item, Icon *pIcon)
 
160
{
 
161
        GList *pList = cd_tomboy_find_note_for_this_week ();
 
162
        if (pList != NULL)
 
163
        {
 
164
                cd_tomboy_mark_icons (pList, TRUE);
 
165
                g_list_free (pList);
 
166
                if (myDock)
 
167
                        cairo_dock_show_dock_at_mouse (myIcon->pSubDock);
 
168
        }
 
169
}
 
170
static void _cd_tomboy_search_for_next_week (GtkMenuItem *menu_item, Icon *pIcon)
 
171
{
 
172
        GList *pList = cd_tomboy_find_note_for_next_week ();
 
173
        if (pList != NULL)
 
174
        {
 
175
                cd_tomboy_mark_icons (pList, TRUE);
 
176
                g_list_free (pList);
 
177
                if (myDock)
 
178
                        cairo_dock_show_dock_at_mouse (myIcon->pSubDock);
 
179
        }
 
180
}
 
181
static void _cd_tomboy_reset_marks (GtkMenuItem *menu_item, Icon *pIcon)
 
182
{
 
183
        cd_tomboy_reset_icon_marks (TRUE);
 
184
}
 
185
CD_APPLET_ON_BUILD_MENU_BEGIN
 
186
        CD_APPLET_ADD_IN_MENU(D_("Reload notes"), _cd_tomboy_reload_notes, CD_APPLET_MY_MENU);
 
187
        if (myDock && (myIcon->pSubDock != NULL && pClickedContainer == CAIRO_CONTAINER (myIcon->pSubDock)) || (myIcon->pSubDock == NULL && pClickedContainer == myContainer))
 
188
        {
 
189
                CD_APPLET_ADD_IN_MENU(D_("Add a note"), _cd_tomboy_add_note, CD_APPLET_MY_MENU);
 
190
                
 
191
                if (pClickedIcon != NULL && pClickedIcon !=  myIcon)
 
192
                {
 
193
                        CD_APPLET_ADD_IN_MENU_WITH_DATA (D_("Delete this note"), _cd_tomboy_delete_note, CD_APPLET_MY_MENU, pClickedIcon);
 
194
                }
 
195
                
 
196
                CD_APPLET_ADD_IN_MENU(D_("Search"), _cd_tomboy_search_for_content, CD_APPLET_MY_MENU);
 
197
                CD_APPLET_ADD_IN_MENU(D_("Searh for tag"), _cd_tomboy_search_for_tag, CD_APPLET_MY_MENU);
 
198
                
 
199
                CD_APPLET_ADD_IN_MENU(D_("Search for today's note"), _cd_tomboy_search_for_today, CD_APPLET_MY_MENU);
 
200
                CD_APPLET_ADD_IN_MENU(D_("Search for this week's note"), _cd_tomboy_search_for_this_week, CD_APPLET_MY_MENU);
 
201
                CD_APPLET_ADD_IN_MENU(D_("Search for next week's note"), _cd_tomboy_search_for_next_week, CD_APPLET_MY_MENU);
 
202
                
 
203
                GList *pList = (myDock ? (myIcon->pSubDock ? myIcon->pSubDock->icons : NULL) : myDesklet->icons);
 
204
                Icon *icon;
 
205
                GList *ic;
 
206
                for (ic = pList; ic != NULL; ic = ic->next)
 
207
                {
 
208
                        icon = ic->data;
 
209
                        if (icon->bHasIndicator)
 
210
                        {
 
211
                                CD_APPLET_ADD_IN_MENU(D_("Reset marks"), _cd_tomboy_reset_marks, CD_APPLET_MY_MENU);
 
212
                                break ;
 
213
                        }
 
214
                }
 
215
        }
 
216
        CD_APPLET_ADD_ABOUT_IN_MENU (CD_APPLET_MY_MENU);
 
217
CD_APPLET_ON_BUILD_MENU_END
 
218
 
 
219
 
 
220
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
 
221
        if (pClickedIcon == myIcon && ! myData.opening)  // possible si on l'a quitte apres le demarrage de l'applet.
 
222
        {
 
223
                dbus_detect_tomboy();
 
224
                free_all_notes ();
 
225
                getAllNotes();
 
226
                cd_tomboy_load_notes();
 
227
        }
 
228
        else
 
229
                _cd_tomboy_create_new_note (pClickedIcon);
 
230
CD_APPLET_ON_MIDDLE_CLICK_END