~ubuntu-branches/ubuntu/vivid/notecase/vivid

« back to all changes in this revision

Viewing changes to src/NodePropertiesDlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Vijay(Vijay)
  • Date: 2007-06-14 00:13:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070614001348-z9e2vbgtenb9nhoo
Tags: 1.5.6-0ubuntu1
* New Upstream release 
*  The libgnomevfs2-dev is also added to Build-Depends 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
////////////////////////////////////////////////////////////////////////////
2
 
// NoteCase notes manager project <http://notecase.sf.net>
3
 
//
4
 
// This code is licensed under BSD license.See "license.txt" for more details.
5
 
//
6
 
// File: Dialog to view/edit document node properties
7
 
////////////////////////////////////////////////////////////////////////////
8
 
 
9
 
#include "NodePropertiesDlg.h"
10
 
#include "support.h"
11
 
#include "gui/FileDialog.h"
12
 
 
13
 
const char *InternalIcon_Index2Name(int nIndex);
14
 
const char **InternalIcon_GetFromIdx(int);
15
 
int InternalIcon_Name2Index(const char *);
16
 
 
17
 
static void on_icon_none_clicked(GtkMenuItem *menuitem, gpointer user_data);
18
 
static void on_icon_internal_clicked(GtkMenuItem *menuitem, gpointer user_data);
19
 
static void on_icon_custom_clicked(GtkMenuItem *menuitem, gpointer user_data);
20
 
static void on_xpm_select_clicked(GtkMenuItem *menuitem, gpointer user_data);
21
 
static void on_internal_combo_selected (GtkComboBox *widget, gpointer user_data);
22
 
 
23
 
NodePropertiesDlg::NodePropertiesDlg()
24
 
{
25
 
}
26
 
 
27
 
NodePropertiesDlg::~NodePropertiesDlg()
28
 
{
29
 
        Destroy();
30
 
}
31
 
 
32
 
void NodePropertiesDlg::Create()
33
 
{
34
 
        m_pDialog = create_node_properties_dialog ();
35
 
 
36
 
        //set node title
37
 
        if(m_strTitle.c_str())
38
 
        {
39
 
                GtkWidget *entry = lookup_widget(m_pDialog, "entry_node_title");
40
 
                gtk_entry_set_text(GTK_ENTRY(entry), m_strTitle.c_str());
41
 
        }
42
 
 
43
 
        //fill internal icons combo
44
 
        GtkWidget *cbo2 = lookup_widget(m_pDialog, "comboboxentry2");
45
 
        for (int i=ICON_INTERNAL_FIRST; i<=ICON_INTERNAL_LAST; i++)
46
 
                gtk_combo_box_append_text(GTK_COMBO_BOX(cbo2), InternalIcon_Index2Name(i));
47
 
 
48
 
        //select first entry in combo (must not be empty selection)
49
 
        gtk_combo_box_set_active(GTK_COMBO_BOX(cbo2), 0);
50
 
}
51
 
 
52
 
const char *NodePropertiesDlg::GetNodeTitle()
53
 
{
54
 
        GtkWidget *entry = lookup_widget(m_pDialog, "entry_node_title");
55
 
        return gtk_entry_get_text(GTK_ENTRY(entry));
56
 
}
57
 
 
58
 
int NodePropertiesDlg::GetIconType()
59
 
{
60
 
        GtkWidget *radio_ico_none       = lookup_widget(m_pDialog, "radio_ico_none");
61
 
        GtkWidget *radio_ico_internal   = lookup_widget(m_pDialog, "radio_ico_internal");
62
 
 
63
 
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_none)))
64
 
                return ICON_NONE;
65
 
        else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_internal))) 
66
 
                return ICON_INTERNAL;
67
 
        return ICON_CUSTOM;
68
 
}
69
 
 
70
 
const char *NodePropertiesDlg::GetIconValue()
71
 
{
72
 
        GtkWidget *cbo2         = lookup_widget(m_pDialog, "comboboxentry2");
73
 
        GtkWidget *entry4       = lookup_widget(m_pDialog, "entry4");
74
 
 
75
 
        switch (GetIconType())
76
 
        {
77
 
                case ICON_INTERNAL:     
78
 
                {
79
 
                #if GTK_CHECK_VERSION(2,6,0) //new API //TOFIX set proper version//
80
 
                        return gtk_combo_box_get_active_text(GTK_COMBO_BOX(cbo2));
81
 
                #else
82
 
                        int nPos = gtk_combo_box_get_active(GTK_COMBO_BOX(cbo2));
83
 
                        if(nPos >= 0)
84
 
                        {
85
 
                                GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbo2));
86
 
                                GtkTreeIter iter;
87
 
                                char szPath[10];
88
 
                                sprintf(szPath, "%d", nPos);
89
 
                                GtkTreePath *path1 = gtk_tree_path_new_from_string (szPath);
90
 
                                if(gtk_tree_model_get_iter(model, &iter, path1))
91
 
                                {
92
 
                                        gchar *value = NULL;
93
 
                                        gtk_tree_model_get (model, &iter, 0, &value, -1);
94
 
                                        return value;
95
 
                                        //g_free(value);
96
 
                                }
97
 
                        }
98
 
                        return NULL;
99
 
                #endif
100
 
                }
101
 
                case ICON_CUSTOM:       return gtk_entry_get_text(GTK_ENTRY(entry4));
102
 
                default:                return "";
103
 
        }
104
 
}
105
 
 
106
 
void NodePropertiesDlg::SetIconType(int nType)
107
 
{
108
 
        GtkWidget *radio_ico_none       = lookup_widget(m_pDialog, "radio_ico_none");
109
 
        GtkWidget *radio_ico_internal   = lookup_widget(m_pDialog, "radio_ico_internal");
110
 
        GtkWidget *radio_ico_custom     = lookup_widget(m_pDialog, "radio_ico_custom");
111
 
        GtkWidget *cbo2                 = lookup_widget(m_pDialog, "comboboxentry2");
112
 
 
113
 
        if(ICON_NONE == nType)
114
 
        {
115
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_ico_none), TRUE);
116
 
                on_icon_none_clicked(NULL, this);
117
 
        }
118
 
        else if(ICON_CUSTOM == nType) 
119
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_ico_custom), TRUE);
120
 
        else
121
 
        {
122
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_ico_internal), TRUE);
123
 
                gtk_combo_box_set_active(GTK_COMBO_BOX(cbo2), nType);
124
 
        }
125
 
 
126
 
        UpdatePreview();
127
 
}
128
 
 
129
 
void NodePropertiesDlg::SetIconValue(const char *szValue)
130
 
{
131
 
        GtkWidget *entry4       = lookup_widget(m_pDialog, "entry4");
132
 
        gtk_entry_set_text(GTK_ENTRY(entry4), szValue);
133
 
 
134
 
        UpdatePreview();
135
 
}
136
 
 
137
 
GtkWidget* NodePropertiesDlg::create_node_properties_dialog ()
138
 
{
139
 
        GtkWidget *node_properties_dialog;
140
 
        GtkWidget *dialog_vbox5;
141
 
        GtkWidget *table4;
142
 
        GtkWidget *label21;
143
 
        GtkWidget *entry_node_title;
144
 
        GtkWidget *label22;
145
 
        GtkWidget *vbox10;
146
 
        GtkWidget *hbox2;
147
 
        GtkWidget *table6;
148
 
        GtkWidget *radio_ico_none;
149
 
        GSList    *radio_ico_none_group = NULL;
150
 
        GtkWidget *radio_ico_internal;
151
 
        GtkWidget *radio_ico_custom;
152
 
        GtkWidget *entry4;
153
 
        GtkWidget *label23;
154
 
        GtkWidget *image1;
155
 
        GtkWidget *button_xpm_select;
156
 
        GtkWidget *comboboxentry2;
157
 
        GtkWidget *dialog_action_area5;
158
 
        GtkWidget *cancelbutton5;
159
 
        GtkWidget *okbutton5;
160
 
        
161
 
        node_properties_dialog = gtk_dialog_new ();
162
 
        gtk_window_set_title (GTK_WINDOW (node_properties_dialog), _("Node Properties"));
163
 
        gtk_window_set_type_hint (GTK_WINDOW (node_properties_dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
164
 
        
165
 
        dialog_vbox5 = GTK_DIALOG (node_properties_dialog)->vbox;
166
 
        gtk_widget_show (dialog_vbox5);
167
 
        
168
 
        table4 = gtk_table_new (2, 2, FALSE);
169
 
        gtk_widget_show (table4);
170
 
        gtk_box_pack_start (GTK_BOX (dialog_vbox5), table4, TRUE, TRUE, 0);
171
 
        
172
 
        label21 = gtk_label_new (_("Title:"));
173
 
        gtk_widget_show (label21);
174
 
        gtk_table_attach (GTK_TABLE (table4), label21, 0, 1, 0, 1,
175
 
                (GtkAttachOptions) (GTK_FILL),
176
 
                (GtkAttachOptions) (0), 0, 0);
177
 
        gtk_misc_set_alignment (GTK_MISC (label21), 0, 0.5);
178
 
        
179
 
        entry_node_title = gtk_entry_new ();
180
 
        gtk_widget_show (entry_node_title);
181
 
        gtk_table_attach (GTK_TABLE (table4), entry_node_title, 1, 2, 0, 1,
182
 
                (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
183
 
                (GtkAttachOptions) (0), 0, 0);
184
 
        
185
 
        label22 = gtk_label_new (_("Icon:"));
186
 
        gtk_widget_show (label22);
187
 
        gtk_table_attach (GTK_TABLE (table4), label22, 0, 1, 1, 2,
188
 
                (GtkAttachOptions) (GTK_FILL),
189
 
                (GtkAttachOptions) (0), 0, 0);
190
 
        gtk_misc_set_alignment (GTK_MISC (label22), 0, 0);
191
 
        
192
 
        vbox10 = gtk_vbox_new (FALSE, 0);
193
 
        gtk_widget_show (vbox10);
194
 
        gtk_table_attach (GTK_TABLE (table4), vbox10, 1, 2, 1, 2,
195
 
                (GtkAttachOptions) (GTK_FILL),
196
 
                (GtkAttachOptions) (GTK_FILL), 0, 0);
197
 
        
198
 
        hbox2 = gtk_hbox_new (FALSE, 0);
199
 
        gtk_widget_show (hbox2);
200
 
        gtk_box_pack_start (GTK_BOX (vbox10), hbox2, FALSE, FALSE, 0);
201
 
        
202
 
        table6 = gtk_table_new (4, 3, FALSE);
203
 
        gtk_widget_show (table6);
204
 
        gtk_box_pack_start (GTK_BOX (hbox2), table6, TRUE, TRUE, 0);
205
 
        
206
 
        radio_ico_none = gtk_radio_button_new_with_mnemonic (NULL, _("None"));
207
 
        gtk_widget_show (radio_ico_none);
208
 
        gtk_table_attach (GTK_TABLE (table6), radio_ico_none, 0, 1, 0, 1,
209
 
                (GtkAttachOptions) (GTK_FILL),
210
 
                (GtkAttachOptions) (0), 0, 0);
211
 
        gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_ico_none), radio_ico_none_group);
212
 
        radio_ico_none_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_ico_none));
213
 
        
214
 
        radio_ico_internal = gtk_radio_button_new_with_mnemonic (NULL, _("Internal"));
215
 
        gtk_widget_show (radio_ico_internal);
216
 
        gtk_table_attach (GTK_TABLE (table6), radio_ico_internal, 0, 1, 1, 2,
217
 
                (GtkAttachOptions) (GTK_FILL),
218
 
                (GtkAttachOptions) (0), 0, 0);
219
 
        gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_ico_internal), radio_ico_none_group);
220
 
        radio_ico_none_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_ico_internal));
221
 
        
222
 
        radio_ico_custom = gtk_radio_button_new_with_mnemonic (NULL, _("Custom"));
223
 
        gtk_widget_show (radio_ico_custom);
224
 
        gtk_table_attach (GTK_TABLE (table6), radio_ico_custom, 0, 1, 2, 3,
225
 
                (GtkAttachOptions) (GTK_FILL),
226
 
                (GtkAttachOptions) (0), 0, 0);
227
 
        gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_ico_custom), radio_ico_none_group);
228
 
        radio_ico_none_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_ico_custom));
229
 
        
230
 
        entry4 = gtk_entry_new ();
231
 
        gtk_entry_set_editable (GTK_ENTRY(entry4), FALSE);
232
 
        gtk_widget_show (entry4);
233
 
        gtk_table_attach (GTK_TABLE (table6), entry4, 1, 2, 2, 3,
234
 
                (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
235
 
                (GtkAttachOptions) (0), 0, 0);
236
 
        
237
 
        label23 = gtk_label_new (_("Preview:"));
238
 
        gtk_widget_show (label23);
239
 
        gtk_table_attach (GTK_TABLE (table6), label23, 0, 1, 3, 4,
240
 
                (GtkAttachOptions) (GTK_FILL),
241
 
                (GtkAttachOptions) (0), 0, 0);
242
 
        gtk_misc_set_alignment (GTK_MISC (label23), 0, 0.5);
243
 
        
244
 
        image1 = gtk_image_new ();
245
 
        gtk_widget_show (image1);
246
 
        gtk_widget_set_size_request(image1, -1, 20);
247
 
        gtk_table_attach (GTK_TABLE (table6), image1, 1, 2, 3, 4,
248
 
                (GtkAttachOptions) (GTK_FILL),
249
 
                (GtkAttachOptions) (GTK_FILL), 0, 0);
250
 
        
251
 
        button_xpm_select = gtk_button_new_with_mnemonic ("...");
252
 
        gtk_widget_show (button_xpm_select);
253
 
        gtk_table_attach (GTK_TABLE (table6), button_xpm_select, 2, 3, 2, 3,
254
 
                (GtkAttachOptions) (GTK_FILL),
255
 
                (GtkAttachOptions) (0), 0, 0);
256
 
        
257
 
        comboboxentry2 = gtk_combo_box_new_text ();
258
 
        gtk_widget_show (comboboxentry2);
259
 
        gtk_table_attach (GTK_TABLE (table6), comboboxentry2, 1, 2, 1, 2,
260
 
                (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
261
 
                (GtkAttachOptions) (GTK_FILL), 0, 0);
262
 
        
263
 
        dialog_action_area5 = GTK_DIALOG (node_properties_dialog)->action_area;
264
 
        gtk_widget_show (dialog_action_area5);
265
 
        gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area5), GTK_BUTTONBOX_END);
266
 
        
267
 
        cancelbutton5 = gtk_button_new_from_stock ("gtk-cancel");
268
 
        gtk_widget_show (cancelbutton5);
269
 
        gtk_dialog_add_action_widget (GTK_DIALOG (node_properties_dialog), cancelbutton5, GTK_RESPONSE_CANCEL);
270
 
        GTK_WIDGET_SET_FLAGS (cancelbutton5, GTK_CAN_DEFAULT);
271
 
        
272
 
        okbutton5 = gtk_button_new_from_stock ("gtk-ok");
273
 
        gtk_widget_show (okbutton5);
274
 
        gtk_dialog_add_action_widget (GTK_DIALOG (node_properties_dialog), okbutton5, GTK_RESPONSE_OK);
275
 
        GTK_WIDGET_SET_FLAGS (okbutton5, GTK_CAN_DEFAULT);
276
 
 
277
 
        g_signal_connect (radio_ico_none,               "clicked",      G_CALLBACK (on_icon_none_clicked), this);
278
 
        g_signal_connect (radio_ico_internal,   "clicked",      G_CALLBACK (on_icon_internal_clicked), this);
279
 
        g_signal_connect (radio_ico_custom,             "clicked",      G_CALLBACK (on_icon_custom_clicked), this);
280
 
        g_signal_connect (button_xpm_select,    "clicked",      G_CALLBACK (on_xpm_select_clicked), this);
281
 
        g_signal_connect (comboboxentry2,               "changed",  G_CALLBACK (on_internal_combo_selected), this);
282
 
 
283
 
        /* Store pointers to all widgets, for use by lookup_widget(). */
284
 
        GLADE_HOOKUP_OBJECT_NO_REF (node_properties_dialog, node_properties_dialog, "node_properties_dialog");
285
 
        GLADE_HOOKUP_OBJECT_NO_REF (node_properties_dialog, dialog_vbox5, "dialog_vbox5");
286
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, table4, "table4");
287
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, label21, "label21");
288
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, entry_node_title, "entry_node_title");
289
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, label22, "label22");
290
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, vbox10, "vbox10");
291
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, hbox2, "hbox2");
292
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, table6, "table6");
293
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, radio_ico_none, "radio_ico_none");
294
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, radio_ico_internal, "radio_ico_internal");
295
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, radio_ico_custom, "radio_ico_custom");
296
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, entry4, "entry4");
297
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, label23, "label23");
298
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, image1, "image1");
299
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, button_xpm_select, "button_xpm_select");
300
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, comboboxentry2, "comboboxentry2");
301
 
        GLADE_HOOKUP_OBJECT_NO_REF (node_properties_dialog, dialog_action_area5, "dialog_action_area5");
302
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, cancelbutton5, "cancelbutton5");
303
 
        GLADE_HOOKUP_OBJECT (node_properties_dialog, okbutton5, "okbutton5");
304
 
        
305
 
        return node_properties_dialog;
306
 
}
307
 
 
308
 
void on_icon_none_clicked(GtkMenuItem *menuitem, gpointer user_data)
309
 
{
310
 
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
311
 
 
312
 
        GtkWidget *radio_ico_none = lookup_widget(pDlg->m_pDialog, "radio_ico_none");
313
 
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_none)))
314
 
        {
315
 
                GtkWidget *cbo2                         = lookup_widget(pDlg->m_pDialog, "comboboxentry2");
316
 
                GtkWidget *entry4                       = lookup_widget(pDlg->m_pDialog, "entry4");
317
 
                GtkWidget *button                       = lookup_widget(pDlg->m_pDialog, "button_xpm_select");
318
 
 
319
 
                gtk_widget_set_sensitive(cbo2, FALSE);
320
 
                gtk_widget_set_sensitive(entry4, FALSE);
321
 
                gtk_widget_set_sensitive(button, FALSE);
322
 
 
323
 
                pDlg->UpdatePreview();
324
 
        }
325
 
}
326
 
 
327
 
void on_icon_internal_clicked(GtkMenuItem *menuitem, gpointer user_data)
328
 
{
329
 
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
330
 
 
331
 
        GtkWidget *radio_ico_internal = lookup_widget(pDlg->m_pDialog, "radio_ico_internal");
332
 
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_internal)))
333
 
        {
334
 
                GtkWidget *cbo2         = lookup_widget(pDlg->m_pDialog, "comboboxentry2");
335
 
                GtkWidget *entry4       = lookup_widget(pDlg->m_pDialog, "entry4");
336
 
                GtkWidget *button       = lookup_widget(pDlg->m_pDialog, "button_xpm_select");
337
 
                
338
 
                gtk_widget_set_sensitive(cbo2, TRUE);
339
 
                gtk_widget_set_sensitive(entry4, FALSE);
340
 
                gtk_widget_set_sensitive(button, FALSE);
341
 
 
342
 
                pDlg->UpdatePreview();
343
 
        }
344
 
}
345
 
 
346
 
void on_icon_custom_clicked(GtkMenuItem *menuitem, gpointer user_data)
347
 
{
348
 
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
349
 
        
350
 
        GtkWidget *radio_ico_custom = lookup_widget(pDlg->m_pDialog, "radio_ico_custom");
351
 
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_custom)))
352
 
        {
353
 
                GtkWidget *cbo2         = lookup_widget(pDlg->m_pDialog, "comboboxentry2");
354
 
                GtkWidget *entry4       = lookup_widget(pDlg->m_pDialog, "entry4");
355
 
                GtkWidget *button       = lookup_widget(pDlg->m_pDialog, "button_xpm_select");
356
 
 
357
 
                gtk_widget_set_sensitive(cbo2, FALSE);
358
 
                gtk_widget_set_sensitive(entry4, TRUE);
359
 
                gtk_widget_set_sensitive(button, TRUE);
360
 
 
361
 
                pDlg->UpdatePreview();
362
 
        }
363
 
}
364
 
 
365
 
void on_xpm_select_clicked(GtkMenuItem *menuitem, gpointer user_data)
366
 
{
367
 
        FileDialog dlg;
368
 
        dlg.AddFilter(_("XPM icon file (*.xpm)"), "*.xpm");
369
 
        if(dlg.DoModal())
370
 
        {
371
 
                NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
372
 
                GtkWidget *entry4       = lookup_widget(pDlg->m_pDialog, "entry4");
373
 
                gtk_entry_set_text(GTK_ENTRY(entry4), dlg.GetFilename());
374
 
 
375
 
                pDlg->UpdatePreview();
376
 
        }
377
 
}
378
 
 
379
 
void NodePropertiesDlg::UpdatePreview()
380
 
{
381
 
        GtkWidget *image1 = lookup_widget(m_pDialog, "image1");
382
 
 
383
 
        int nType = GetIconType();
384
 
        if(ICON_INTERNAL == nType)
385
 
        {
386
 
                int nIcoIdx = InternalIcon_Name2Index(GetIconValue());
387
 
                if(nIcoIdx >= 0)
388
 
                {
389
 
                        const char **szIconData = InternalIcon_GetFromIdx(nIcoIdx);
390
 
                        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (szIconData);
391
 
                        GdkPixbuf *destpix = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_NEAREST);
392
 
                        g_object_unref (G_OBJECT (pixbuf));
393
 
                        gtk_image_set_from_pixbuf (GTK_IMAGE(image1), destpix);
394
 
                        g_object_unref (G_OBJECT (destpix));
395
 
                }
396
 
                else
397
 
                {
398
 
                        gtk_image_set_from_file(GTK_IMAGE(image1), NULL);       //clear image
399
 
                }
400
 
        }
401
 
        else if(ICON_CUSTOM == nType)
402
 
        {
403
 
                GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(GetIconValue(), 16, 16, NULL);
404
 
                if(pixbuf){
405
 
                        gtk_image_set_from_pixbuf (GTK_IMAGE(image1), pixbuf);
406
 
                        g_object_unref (G_OBJECT (pixbuf));
407
 
                }
408
 
                else
409
 
                {
410
 
                        gtk_image_set_from_file(GTK_IMAGE(image1), NULL);       //clear image
411
 
                }
412
 
        }
413
 
        else
414
 
                gtk_image_set_from_file(GTK_IMAGE(image1), NULL);       //clear image
415
 
}
416
 
 
417
 
void on_internal_combo_selected (GtkComboBox *widget, gpointer user_data)
418
 
{
419
 
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
420
 
        pDlg->UpdatePreview();
421
 
}
422
 
 
 
1
////////////////////////////////////////////////////////////////////////////
 
2
// NoteCase notes manager project <http://notecase.sf.net>
 
3
//
 
4
// This code is licensed under BSD license.See "license.txt" for more details.
 
5
//
 
6
// File: Dialog to view/edit document node properties
 
7
////////////////////////////////////////////////////////////////////////////
 
8
 
 
9
#include "NodePropertiesDlg.h"
 
10
#include "support.h"
 
11
#include "callbacks.h"
 
12
#include "gui/FileDialog.h"
 
13
#include "lib/debug.h"
 
14
#include "config.h"
 
15
 
 
16
#ifdef _WIN32
 
17
 #ifndef __MINGW32__
 
18
  #define snprintf _snprintf
 
19
 #endif
 
20
#endif
 
21
 
 
22
extern GtkWidget *g_pNodePropWidget;
 
23
extern GtkWidget *window1;
 
24
 
 
25
const char *InternalIcon_Index2Name(int nIndex);
 
26
const char **InternalIcon_GetFromIdx(int);
 
27
int InternalIcon_Name2Index(const char *);
 
28
int gtkMessageBox(const char *szText, int nButtons = GTK_BUTTONS_OK, int nIcon = GTK_MESSAGE_INFO);
 
29
const char *combo_get_text(GtkWidget *cbo3);
 
30
 
 
31
static void on_icon_none_clicked (GtkMenuItem *menuitem, gpointer user_data);
 
32
static void on_icon_internal_clicked (GtkMenuItem *menuitem, gpointer user_data);
 
33
static void on_icon_custom_clicked (GtkMenuItem *menuitem, gpointer user_data);
 
34
static void on_xpm_select_clicked (GtkMenuItem *menuitem, gpointer user_data);
 
35
static void on_internal_combo_selected (GtkComboBox *widget, gpointer user_data);
 
36
static void on_keyword_add_selected (GtkMenuItem *menuitem, gpointer user_data);
 
37
static void on_keyword_remove_selected (GtkMenuItem *menuitem, gpointer user_data);
 
38
static void on_finished_checked (GtkMenuItem *menuitem, gpointer user_data);
 
39
static void FormatTime(time_t nTime, std::string& strTxt);
 
40
 
 
41
NodePropertiesDlg::NodePropertiesDlg()
 
42
{
 
43
        m_bFinished = false;
 
44
}
 
45
 
 
46
NodePropertiesDlg::~NodePropertiesDlg()
 
47
{
 
48
        g_pNodePropWidget = NULL;
 
49
        Destroy();
 
50
        gtk_window_present(GTK_WINDOW(window1)); //activate main window
 
51
}
 
52
 
 
53
void NodePropertiesDlg::Create()
 
54
{
 
55
        m_pDialog = create_node_properties_dialog ();
 
56
        g_pNodePropWidget = m_pDialog;
 
57
 
 
58
        //set node title
 
59
        if(m_strTitle.c_str())
 
60
        {
 
61
                GtkWidget *entry = lookup_widget(m_pDialog, "entry_node_title");
 
62
                gtk_entry_set_text(GTK_ENTRY(entry), m_strTitle.c_str());
 
63
        }
 
64
 
 
65
        //fill internal icons combo
 
66
        GtkWidget *cbo2 = lookup_widget(m_pDialog, "comboboxentry2");
 
67
        for (int i=ICON_INTERNAL_FIRST; i<=ICON_INTERNAL_LAST; i++)
 
68
                gtk_combo_box_append_text(GTK_COMBO_BOX(cbo2), InternalIcon_Index2Name(i));
 
69
 
 
70
        //select first entry in combo (must not be empty selection)
 
71
        gtk_combo_box_set_active(GTK_COMBO_BOX(cbo2), 0);
 
72
 
 
73
        //fill keywords combo
 
74
        GtkWidget *cbo3 = lookup_widget(m_pDialog, "comboboxentry3");
 
75
        std::string::size_type nPos = m_strKeywords.find(';');
 
76
        while(nPos != std::string::npos){
 
77
                std::string strWord = m_strKeywords.substr(0, nPos);
 
78
                m_strKeywords = m_strKeywords.substr(nPos+1);
 
79
                if(strWord.size()>0)
 
80
                        gtk_combo_box_append_text(GTK_COMBO_BOX(cbo3), strWord.c_str());
 
81
                nPos = m_strKeywords.find(';');
 
82
        }
 
83
        if(m_strKeywords.size()>0)
 
84
                gtk_combo_box_append_text(GTK_COMBO_BOX(cbo3), m_strKeywords.c_str());
 
85
        //select first entry in combo
 
86
        gtk_combo_box_set_active(GTK_COMBO_BOX(cbo3), 0);
 
87
 
 
88
        //set dates (read only)
 
89
        GtkWidget *label_created        = lookup_widget(m_pDialog, "label_created");
 
90
        GtkWidget *label_modified       = lookup_widget(m_pDialog, "label_modified");
 
91
        
 
92
        //display node dates
 
93
        std::string strTxt;
 
94
        FormatTime(m_nCreated, strTxt);
 
95
        gtk_label_set_text(GTK_LABEL(label_created), strTxt.c_str());
 
96
        FormatTime(m_nModified, strTxt);
 
97
        gtk_label_set_text(GTK_LABEL(label_modified), strTxt.c_str());
 
98
        
 
99
        //set finished
 
100
        GtkWidget *chk_finished = lookup_widget(m_pDialog, "chk_finished");
 
101
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_finished), m_bFinished);
 
102
}
 
103
 
 
104
const char *NodePropertiesDlg::GetNodeTitle()
 
105
{
 
106
        GtkWidget *entry = lookup_widget(m_pDialog, "entry_node_title");
 
107
        return gtk_entry_get_text(GTK_ENTRY(entry));
 
108
}
 
109
 
 
110
void NodePropertiesDlg::RefreshKeywords()
 
111
{
 
112
        GtkWidget *cbo3 = lookup_widget(m_pDialog, "comboboxentry3");
 
113
        GtkTreeModel* model = gtk_combo_box_get_model (GTK_COMBO_BOX(cbo3));
 
114
 
 
115
        m_strKeywords = "";
 
116
        gint nSize = gtk_tree_model_iter_n_children  (model, NULL);
 
117
        for(int i=0; i<nSize; i++)
 
118
        {
 
119
                GtkTreeIter iter;
 
120
                gtk_tree_model_iter_nth_child (model, &iter, NULL, i);
 
121
 
 
122
                gchar *value = NULL;
 
123
                gtk_tree_model_get (model, &iter, 0, &value, -1);
 
124
 
 
125
                m_strKeywords += ";";
 
126
                m_strKeywords += value;
 
127
 
 
128
                g_free(value);
 
129
        }
 
130
        if(nSize > 0)
 
131
                m_strKeywords += ";";   //terminate list with delimiter
 
132
}
 
133
 
 
134
int NodePropertiesDlg::GetIconType()
 
135
{
 
136
        GtkWidget *radio_ico_none       = lookup_widget(m_pDialog, "radio_ico_none");
 
137
        GtkWidget *radio_ico_internal   = lookup_widget(m_pDialog, "radio_ico_internal");
 
138
 
 
139
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_none)))
 
140
                return ICON_NONE;
 
141
        else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_internal))) 
 
142
                return ICON_INTERNAL;
 
143
        return ICON_CUSTOM;
 
144
}
 
145
 
 
146
const char *NodePropertiesDlg::GetIconValue()
 
147
{
 
148
        GtkWidget *cbo2         = lookup_widget(m_pDialog, "comboboxentry2");
 
149
        GtkWidget *entry4       = lookup_widget(m_pDialog, "entry4");
 
150
 
 
151
        switch (GetIconType())
 
152
        {
 
153
                case ICON_INTERNAL:     return combo_get_text(cbo2);
 
154
                case ICON_CUSTOM:       return gtk_entry_get_text(GTK_ENTRY(entry4));
 
155
                default:                        return "";
 
156
        }
 
157
}
 
158
 
 
159
void NodePropertiesDlg::SetIconType(int nType)
 
160
{
 
161
        GtkWidget *radio_ico_none       = lookup_widget(m_pDialog, "radio_ico_none");
 
162
        GtkWidget *radio_ico_internal   = lookup_widget(m_pDialog, "radio_ico_internal");
 
163
        GtkWidget *radio_ico_custom     = lookup_widget(m_pDialog, "radio_ico_custom");
 
164
        GtkWidget *cbo2                 = lookup_widget(m_pDialog, "comboboxentry2");
 
165
 
 
166
        if(ICON_NONE == nType)
 
167
        {
 
168
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_ico_none), TRUE);
 
169
                on_icon_none_clicked(NULL, this);
 
170
        }
 
171
        else if(ICON_CUSTOM == nType) 
 
172
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_ico_custom), TRUE);
 
173
        else
 
174
        {
 
175
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_ico_internal), TRUE);
 
176
                gtk_combo_box_set_active(GTK_COMBO_BOX(cbo2), nType);
 
177
        }
 
178
 
 
179
        UpdatePreview();
 
180
}
 
181
 
 
182
void NodePropertiesDlg::SetIconValue(const char *szValue)
 
183
{
 
184
        GtkWidget *entry4 = lookup_widget(m_pDialog, "entry4");
 
185
        gtk_entry_set_text(GTK_ENTRY(entry4), szValue);
 
186
 
 
187
        UpdatePreview();
 
188
}
 
189
 
 
190
void NodePropertiesDlg::KeywordAdd()
 
191
{
 
192
        GtkWidget *cbo3 = lookup_widget(m_pDialog, "comboboxentry3");
 
193
        ASSERT(NULL != cbo3);
 
194
 
 
195
        std::string strWord = combo_get_text(cbo3);
 
196
        if(strWord.size() > 0)
 
197
        {
 
198
                TRACE("Add tag: %s\n", strWord.c_str());
 
199
 
 
200
                //check if valid keyword
 
201
                if(std::string::npos != strWord.find(';')){
 
202
                        gtkMessageBox(_("Keyword must not contain \";\" character!"));
 
203
                        return;
 
204
                }
 
205
 
 
206
                //check if keyword already exists
 
207
                GtkTreeModel* model = gtk_combo_box_get_model (GTK_COMBO_BOX(cbo3));
 
208
                gint nSize = gtk_tree_model_iter_n_children  (model, NULL);
 
209
                for(int i=0; i<nSize; i++)
 
210
                {
 
211
                        GtkTreeIter iter;
 
212
                        gtk_tree_model_iter_nth_child (model, &iter, NULL, i);
 
213
                        gchar *value = NULL;
 
214
                        gtk_tree_model_get (model, &iter, 0, &value, -1);
 
215
 
 
216
                        if(value && 0 == strcmp(strWord.c_str(), value))
 
217
                        {
 
218
                                gtkMessageBox(_("This keyword was already added for this node!"));
 
219
                                g_free(value);
 
220
                                return;
 
221
                        }
 
222
                        g_free(value);
 
223
                }
 
224
                
 
225
                TRACE("Append tag\n");
 
226
 
 
227
                //add the keyword
 
228
                gtk_combo_box_append_text(GTK_COMBO_BOX(cbo3), strWord.c_str());
 
229
        }
 
230
}
 
231
 
 
232
void NodePropertiesDlg::KeywordRemove()
 
233
{
 
234
        GtkWidget *cbo3 = lookup_widget(m_pDialog, "comboboxentry3");
 
235
 
 
236
        std::string strWord = combo_get_text(cbo3);
 
237
        if(strWord.size() > 0)
 
238
        {
 
239
                //search for the keyword in the combo
 
240
                GtkTreeModel* model = gtk_combo_box_get_model (GTK_COMBO_BOX(cbo3));
 
241
                gint nSize = gtk_tree_model_iter_n_children  (model, NULL);
 
242
                for(int i=0; i<nSize; i++)
 
243
                {
 
244
                        GtkTreeIter iter;
 
245
                        gtk_tree_model_iter_nth_child (model, &iter, NULL, i);
 
246
                        gchar *value = NULL;
 
247
                        gtk_tree_model_get (model, &iter, 0, &value, -1);
 
248
 
 
249
                        if(0 == strcmp(strWord.c_str(), value))
 
250
                        {
 
251
                                //remove the keyword
 
252
                                gtk_combo_box_remove_text(GTK_COMBO_BOX(cbo3), i);
 
253
                                g_free(value);
 
254
                                return;
 
255
                        }
 
256
                        g_free(value);
 
257
                }
 
258
        }
 
259
        
 
260
        //TOFIX how to clear entry part of the combo
 
261
        //gtk_combo_box_set_active(GTK_COMBO_BOX(cbo3), -1);
 
262
}
 
263
 
 
264
GtkWidget* NodePropertiesDlg::create_node_properties_dialog ()
 
265
{
 
266
        GtkWidget *node_properties_dialog;
 
267
        GtkWidget *dialog_vbox5;
 
268
        GtkWidget *table4;
 
269
        GtkWidget *label21;
 
270
        GtkWidget *entry_node_title;
 
271
        GtkWidget *label22;
 
272
        GtkWidget *vbox10;
 
273
        GtkWidget *hbox2;
 
274
        GtkWidget *table6;
 
275
        GtkWidget *radio_ico_none;
 
276
        GSList    *radio_ico_none_group = NULL;
 
277
        GtkWidget *radio_ico_internal;
 
278
        GtkWidget *radio_ico_custom;
 
279
        GtkWidget *entry4;
 
280
        GtkWidget *label23;
 
281
        GtkWidget *comboboxentry3;
 
282
        GtkWidget *hbox3;
 
283
        GtkWidget *label24;
 
284
        GtkWidget *image1;
 
285
        GtkWidget *addbtn;
 
286
        GtkWidget *removebtn;
 
287
        GtkWidget *button_xpm_select;
 
288
        GtkWidget *comboboxentry2;
 
289
        GtkWidget *dialog_action_area5;
 
290
        GtkWidget *cancelbutton5;
 
291
        GtkWidget *okbutton5;
 
292
        GtkWidget *label25;
 
293
        GtkWidget *label_created;
 
294
        GtkWidget *label26;
 
295
        GtkWidget *label_modified;
 
296
        GtkWidget *chk_finished;
 
297
        
 
298
        node_properties_dialog = gtk_dialog_new ();
 
299
        gtk_window_set_title (GTK_WINDOW (node_properties_dialog), _("Node Properties"));
 
300
        gtk_window_set_type_hint (GTK_WINDOW (node_properties_dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
 
301
 
 
302
        dialog_vbox5 = GTK_DIALOG (node_properties_dialog)->vbox;
 
303
        gtk_widget_show (dialog_vbox5);
 
304
        
 
305
        table4 = gtk_table_new (2, 2, FALSE);
 
306
        gtk_widget_show (table4);
 
307
        gtk_box_pack_start (GTK_BOX (dialog_vbox5), table4, TRUE, TRUE, 0);
 
308
 
 
309
        label21 = gtk_label_new (_("Title:"));
 
310
        gtk_widget_show (label21);
 
311
        gtk_table_attach (GTK_TABLE (table4), label21, 0, 1, 0, 1,
 
312
                (GtkAttachOptions) (GTK_FILL),
 
313
                (GtkAttachOptions) (0), 0, 0);
 
314
        gtk_misc_set_alignment (GTK_MISC (label21), 0, 0.5);
 
315
        
 
316
        entry_node_title = gtk_entry_new ();
 
317
        gtk_widget_show (entry_node_title);
 
318
        gtk_table_attach (GTK_TABLE (table4), entry_node_title, 1, 2, 0, 1,
 
319
                (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
 
320
                (GtkAttachOptions) (0), 0, 0);
 
321
 
 
322
        //attach accelerator
 
323
        GtkAccelGroup *accel_group = gtk_accel_group_new ();
 
324
        GClosure *closure = g_cclosure_new (G_CALLBACK (on_menu_insert_date_time), NULL, NULL);
 
325
        gtk_accel_group_connect (accel_group, 'T', (GdkModifierType)(GDK_CONTROL_MASK|GDK_SHIFT_MASK), GTK_ACCEL_VISIBLE, closure);
 
326
        g_closure_unref (closure);
 
327
        gtk_window_add_accel_group (GTK_WINDOW (node_properties_dialog), accel_group);
 
328
        
 
329
        label25 = gtk_label_new (_("Created:"));
 
330
        gtk_widget_show (label25);
 
331
        gtk_table_attach (GTK_TABLE (table4), label25, 0, 1, 1, 2,
 
332
                (GtkAttachOptions) (GTK_FILL),
 
333
                (GtkAttachOptions) (0), 0, 0);
 
334
        gtk_misc_set_alignment (GTK_MISC (label25), 0, 0.5);
 
335
 
 
336
        label_created = gtk_label_new (_("unknown"));
 
337
        gtk_widget_show (label_created);
 
338
        gtk_table_attach (GTK_TABLE (table4), label_created, 1, 2, 1, 2,
 
339
                (GtkAttachOptions) (GTK_FILL),
 
340
                (GtkAttachOptions) (0), 0, 0);
 
341
        gtk_misc_set_alignment (GTK_MISC (label_created), 0, 0.5);
 
342
 
 
343
        label26 = gtk_label_new (_("Modified:"));
 
344
        gtk_widget_show (label26);
 
345
        gtk_table_attach (GTK_TABLE (table4), label26, 0, 1, 2, 3,
 
346
                (GtkAttachOptions) (GTK_FILL),
 
347
                (GtkAttachOptions) (0), 0, 0);
 
348
        gtk_misc_set_alignment (GTK_MISC (label26), 0, 0.5);
 
349
 
 
350
        label_modified = gtk_label_new (_("unknown"));
 
351
        gtk_widget_show (label_modified);
 
352
        gtk_table_attach (GTK_TABLE (table4), label_modified, 1, 2, 2, 3,
 
353
                (GtkAttachOptions) (GTK_FILL),
 
354
                (GtkAttachOptions) (0), 0, 0);
 
355
        gtk_misc_set_alignment (GTK_MISC (label_modified), 0, 0.5);
 
356
 
 
357
        label22 = gtk_label_new (_("Icon:"));
 
358
        gtk_widget_show (label22);
 
359
        gtk_table_attach (GTK_TABLE (table4), label22, 0, 1, 3, 4,
 
360
                (GtkAttachOptions) (GTK_FILL),
 
361
                (GtkAttachOptions) (0), 0, 0);
 
362
        gtk_misc_set_alignment (GTK_MISC (label22), 0, 0);
 
363
 
 
364
        vbox10 = gtk_vbox_new (FALSE, 0);
 
365
        gtk_widget_show (vbox10);
 
366
        gtk_table_attach (GTK_TABLE (table4), vbox10, 1, 2, 3, 4,
 
367
                (GtkAttachOptions) (GTK_FILL),
 
368
                (GtkAttachOptions) (GTK_FILL), 0, 0);
 
369
        
 
370
        hbox2 = gtk_hbox_new (FALSE, 0);
 
371
        gtk_widget_show (hbox2);
 
372
        gtk_box_pack_start (GTK_BOX (vbox10), hbox2, FALSE, FALSE, 0);
 
373
        
 
374
        table6 = gtk_table_new (4, 3, FALSE);
 
375
        gtk_widget_show (table6);
 
376
        gtk_box_pack_start (GTK_BOX (hbox2), table6, TRUE, TRUE, 0);
 
377
 
 
378
        radio_ico_none = gtk_radio_button_new_with_mnemonic (NULL, _("None"));
 
379
        gtk_widget_show (radio_ico_none);
 
380
        gtk_table_attach (GTK_TABLE (table6), radio_ico_none, 0, 1, 0, 1,
 
381
                (GtkAttachOptions) (GTK_FILL),
 
382
                (GtkAttachOptions) (0), 0, 0);
 
383
        gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_ico_none), radio_ico_none_group);
 
384
        radio_ico_none_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_ico_none));
 
385
 
 
386
        radio_ico_internal = gtk_radio_button_new_with_mnemonic (NULL, _("Internal"));
 
387
        gtk_widget_show (radio_ico_internal);
 
388
        gtk_table_attach (GTK_TABLE (table6), radio_ico_internal, 0, 1, 1, 2,
 
389
                (GtkAttachOptions) (GTK_FILL),
 
390
                (GtkAttachOptions) (0), 0, 0);
 
391
        gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_ico_internal), radio_ico_none_group);
 
392
        radio_ico_none_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_ico_internal));
 
393
 
 
394
        radio_ico_custom = gtk_radio_button_new_with_mnemonic (NULL, _("Custom"));
 
395
        gtk_widget_show (radio_ico_custom);
 
396
        gtk_table_attach (GTK_TABLE (table6), radio_ico_custom, 0, 1, 2, 3,
 
397
                (GtkAttachOptions) (GTK_FILL),
 
398
                (GtkAttachOptions) (0), 0, 0);
 
399
        gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_ico_custom), radio_ico_none_group);
 
400
        radio_ico_none_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_ico_custom));
 
401
 
 
402
        comboboxentry2 = gtk_combo_box_new_text ();
 
403
        gtk_widget_show (comboboxentry2);
 
404
        gtk_table_attach (GTK_TABLE (table6), comboboxentry2, 1, 2, 1, 2,
 
405
                (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
 
406
                (GtkAttachOptions) (GTK_FILL), 0, 0);
 
407
        
 
408
        entry4 = gtk_entry_new ();
 
409
        gtk_entry_set_editable (GTK_ENTRY(entry4), FALSE);
 
410
        gtk_widget_show (entry4);
 
411
        gtk_table_attach (GTK_TABLE (table6), entry4, 1, 2, 2, 3,
 
412
                (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
 
413
                (GtkAttachOptions) (0), 0, 0);
 
414
 
 
415
        button_xpm_select = gtk_button_new_with_mnemonic ("...");
 
416
        gtk_widget_show (button_xpm_select);
 
417
        gtk_table_attach (GTK_TABLE (table6), button_xpm_select, 2, 3, 2, 3,
 
418
                (GtkAttachOptions) (GTK_FILL),
 
419
                (GtkAttachOptions) (0), 0, 0);
 
420
 
 
421
        label23 = gtk_label_new (_("Preview:"));
 
422
        gtk_widget_show (label23);
 
423
        gtk_table_attach (GTK_TABLE (table6), label23, 0, 1, 4, 5,
 
424
                (GtkAttachOptions) (GTK_FILL),
 
425
                (GtkAttachOptions) (0), 0, 0);
 
426
        gtk_misc_set_alignment (GTK_MISC (label23), 0, 0.5);
 
427
 
 
428
        image1 = gtk_image_new ();
 
429
        gtk_widget_show (image1);
 
430
        gtk_widget_set_size_request(image1, -1, 20);
 
431
        gtk_table_attach (GTK_TABLE (table6), image1, 1, 2, 4, 5,
 
432
                (GtkAttachOptions) (GTK_FILL),
 
433
                (GtkAttachOptions) (GTK_FILL), 0, 0);
 
434
        
 
435
        label24 = gtk_label_new (_("Tags:"));
 
436
        gtk_widget_show (label24);
 
437
        gtk_table_attach (GTK_TABLE (table4), label24, 0, 1, 5, 6,
 
438
                (GtkAttachOptions) (GTK_FILL),
 
439
                (GtkAttachOptions) (0), 0, 0);
 
440
        gtk_misc_set_alignment (GTK_MISC (label24), 0, 0.5);
 
441
 
 
442
        hbox3 = gtk_hbox_new (FALSE, 0);
 
443
        gtk_widget_show (hbox3);
 
444
        gtk_table_attach (GTK_TABLE (table4), hbox3, 1, 2, 5, 6,
 
445
                (GtkAttachOptions) (GTK_FILL),
 
446
                (GtkAttachOptions) (0), 0, 0);
 
447
 
 
448
        comboboxentry3 = gtk_combo_box_entry_new_text ();
 
449
        gtk_widget_show (comboboxentry3);
 
450
        gtk_box_pack_start (GTK_BOX (hbox3), comboboxentry3, TRUE, TRUE, 0);
 
451
 
 
452
        addbtn = gtk_button_new_with_mnemonic (_("Add"));
 
453
        gtk_widget_show (addbtn);
 
454
        gtk_box_pack_start (GTK_BOX (hbox3), addbtn, TRUE, TRUE, 0);
 
455
        
 
456
        removebtn = gtk_button_new_with_mnemonic (_("Remove"));
 
457
        gtk_widget_show (removebtn);
 
458
        gtk_box_pack_start (GTK_BOX (hbox3), removebtn, TRUE, TRUE, 0);
 
459
 
 
460
        chk_finished = gtk_check_button_new_with_mnemonic (_("Mark node as finished"));
 
461
        gtk_widget_show (chk_finished);
 
462
        gtk_table_attach (GTK_TABLE (table4), chk_finished, 0, 2, 6, 7,
 
463
                (GtkAttachOptions) (GTK_FILL),
 
464
                (GtkAttachOptions) (0), 0, 0);
 
465
 
 
466
        dialog_action_area5 = GTK_DIALOG (node_properties_dialog)->action_area;
 
467
        gtk_widget_show (dialog_action_area5);
 
468
        gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area5), GTK_BUTTONBOX_END);
 
469
        
 
470
        cancelbutton5 = gtk_button_new_from_stock ("gtk-cancel");
 
471
        gtk_widget_show (cancelbutton5);
 
472
        gtk_dialog_add_action_widget (GTK_DIALOG (node_properties_dialog), cancelbutton5, GTK_RESPONSE_CANCEL);
 
473
        GTK_WIDGET_SET_FLAGS (cancelbutton5, GTK_CAN_DEFAULT);
 
474
        
 
475
        okbutton5 = gtk_button_new_from_stock ("gtk-ok");
 
476
        gtk_widget_show (okbutton5);
 
477
        gtk_dialog_add_action_widget (GTK_DIALOG (node_properties_dialog), okbutton5, GTK_RESPONSE_OK);
 
478
        GTK_WIDGET_SET_FLAGS (okbutton5, GTK_CAN_DEFAULT);
 
479
 
 
480
        g_signal_connect (radio_ico_none,       "clicked", G_CALLBACK (on_icon_none_clicked), this);
 
481
        g_signal_connect (radio_ico_internal,   "clicked", G_CALLBACK (on_icon_internal_clicked), this);
 
482
        g_signal_connect (radio_ico_custom,     "clicked", G_CALLBACK (on_icon_custom_clicked), this);
 
483
        g_signal_connect (button_xpm_select,    "clicked", G_CALLBACK (on_xpm_select_clicked), this);
 
484
        g_signal_connect (comboboxentry2,       "changed", G_CALLBACK (on_internal_combo_selected), this);
 
485
        g_signal_connect (addbtn,               "clicked", G_CALLBACK (on_keyword_add_selected), this);
 
486
        g_signal_connect (removebtn,            "clicked", G_CALLBACK (on_keyword_remove_selected), this);
 
487
        g_signal_connect (chk_finished, "clicked",  G_CALLBACK (on_finished_checked), this);
 
488
 
 
489
        /* Store pointers to all widgets, for use by lookup_widget(). */
 
490
        GLADE_HOOKUP_OBJECT_NO_REF (node_properties_dialog, node_properties_dialog, "node_properties_dialog");
 
491
        GLADE_HOOKUP_OBJECT_NO_REF (node_properties_dialog, dialog_vbox5, "dialog_vbox5");
 
492
        GLADE_HOOKUP_OBJECT (node_properties_dialog, table4, "table4");
 
493
        GLADE_HOOKUP_OBJECT (node_properties_dialog, label21, "label21");
 
494
        GLADE_HOOKUP_OBJECT (node_properties_dialog, entry_node_title, "entry_node_title");
 
495
        GLADE_HOOKUP_OBJECT (node_properties_dialog, label22, "label22");
 
496
        GLADE_HOOKUP_OBJECT (node_properties_dialog, vbox10, "vbox10");
 
497
        GLADE_HOOKUP_OBJECT (node_properties_dialog, hbox2, "hbox2");
 
498
        GLADE_HOOKUP_OBJECT (node_properties_dialog, table6, "table6");
 
499
        GLADE_HOOKUP_OBJECT (node_properties_dialog, radio_ico_none, "radio_ico_none");
 
500
        GLADE_HOOKUP_OBJECT (node_properties_dialog, radio_ico_internal, "radio_ico_internal");
 
501
        GLADE_HOOKUP_OBJECT (node_properties_dialog, radio_ico_custom, "radio_ico_custom");
 
502
        GLADE_HOOKUP_OBJECT (node_properties_dialog, entry4, "entry4");
 
503
        GLADE_HOOKUP_OBJECT (node_properties_dialog, label23, "label23");
 
504
        GLADE_HOOKUP_OBJECT (node_properties_dialog, hbox3, "hbox3");
 
505
        GLADE_HOOKUP_OBJECT (node_properties_dialog, label24, "label24");
 
506
        GLADE_HOOKUP_OBJECT (node_properties_dialog, comboboxentry3, "comboboxentry3");
 
507
        GLADE_HOOKUP_OBJECT (node_properties_dialog, addbtn, "addbtn");
 
508
        GLADE_HOOKUP_OBJECT (node_properties_dialog, removebtn, "removebtn");
 
509
        GLADE_HOOKUP_OBJECT (node_properties_dialog, image1, "image1");
 
510
        GLADE_HOOKUP_OBJECT (node_properties_dialog, button_xpm_select, "button_xpm_select");
 
511
        GLADE_HOOKUP_OBJECT (node_properties_dialog, comboboxentry2, "comboboxentry2");
 
512
        GLADE_HOOKUP_OBJECT_NO_REF (node_properties_dialog, dialog_action_area5, "dialog_action_area5");
 
513
        GLADE_HOOKUP_OBJECT (node_properties_dialog, cancelbutton5, "cancelbutton5");
 
514
        GLADE_HOOKUP_OBJECT (node_properties_dialog, okbutton5, "okbutton5");
 
515
        GLADE_HOOKUP_OBJECT (node_properties_dialog, label_created, "label_created");
 
516
        GLADE_HOOKUP_OBJECT (node_properties_dialog, label_modified, "label_modified");
 
517
        GLADE_HOOKUP_OBJECT (node_properties_dialog, chk_finished, "chk_finished");
 
518
 
 
519
 
 
520
        return node_properties_dialog;
 
521
}
 
522
 
 
523
void on_icon_none_clicked(GtkMenuItem *menuitem, gpointer user_data)
 
524
{
 
525
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
 
526
 
 
527
        GtkWidget *radio_ico_none = lookup_widget(pDlg->m_pDialog, "radio_ico_none");
 
528
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_none)))
 
529
        {
 
530
                GtkWidget *cbo2                         = lookup_widget(pDlg->m_pDialog, "comboboxentry2");
 
531
                GtkWidget *entry4                       = lookup_widget(pDlg->m_pDialog, "entry4");
 
532
                GtkWidget *button                       = lookup_widget(pDlg->m_pDialog, "button_xpm_select");
 
533
 
 
534
                gtk_widget_set_sensitive(cbo2, FALSE);
 
535
                gtk_widget_set_sensitive(entry4, FALSE);
 
536
                gtk_widget_set_sensitive(button, FALSE);
 
537
 
 
538
                pDlg->UpdatePreview();
 
539
        }
 
540
}
 
541
 
 
542
void on_icon_internal_clicked(GtkMenuItem *menuitem, gpointer user_data)
 
543
{
 
544
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
 
545
 
 
546
        GtkWidget *radio_ico_internal = lookup_widget(pDlg->m_pDialog, "radio_ico_internal");
 
547
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_internal)))
 
548
        {
 
549
                GtkWidget *cbo2         = lookup_widget(pDlg->m_pDialog, "comboboxentry2");
 
550
                GtkWidget *entry4       = lookup_widget(pDlg->m_pDialog, "entry4");
 
551
                GtkWidget *button       = lookup_widget(pDlg->m_pDialog, "button_xpm_select");
 
552
                
 
553
                gtk_widget_set_sensitive(cbo2, TRUE);
 
554
                gtk_widget_set_sensitive(entry4, FALSE);
 
555
                gtk_widget_set_sensitive(button, FALSE);
 
556
 
 
557
                pDlg->UpdatePreview();
 
558
        }
 
559
}
 
560
 
 
561
void on_icon_custom_clicked(GtkMenuItem *menuitem, gpointer user_data)
 
562
{
 
563
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
 
564
        
 
565
        GtkWidget *radio_ico_custom = lookup_widget(pDlg->m_pDialog, "radio_ico_custom");
 
566
        if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ico_custom)))
 
567
        {
 
568
                GtkWidget *cbo2         = lookup_widget(pDlg->m_pDialog, "comboboxentry2");
 
569
                GtkWidget *entry4       = lookup_widget(pDlg->m_pDialog, "entry4");
 
570
                GtkWidget *button       = lookup_widget(pDlg->m_pDialog, "button_xpm_select");
 
571
 
 
572
                gtk_widget_set_sensitive(cbo2, FALSE);
 
573
                gtk_widget_set_sensitive(entry4, TRUE);
 
574
                gtk_widget_set_sensitive(button, TRUE);
 
575
 
 
576
                pDlg->UpdatePreview();
 
577
        }
 
578
}
 
579
 
 
580
void on_xpm_select_clicked(GtkMenuItem *menuitem, gpointer user_data)
 
581
{
 
582
        FileDialog dlg;
 
583
        dlg.AddFilter(_("XPM icon file (*.xpm)"), "*.xpm");
 
584
        if(dlg.DoModal())
 
585
        {
 
586
                NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
 
587
                GtkWidget *entry4       = lookup_widget(pDlg->m_pDialog, "entry4");
 
588
                gtk_entry_set_text(GTK_ENTRY(entry4), dlg.GetFilename());
 
589
 
 
590
                pDlg->UpdatePreview();
 
591
        }
 
592
}
 
593
 
 
594
void NodePropertiesDlg::UpdatePreview()
 
595
{
 
596
        GtkWidget *image1 = lookup_widget(m_pDialog, "image1");
 
597
 
 
598
        int nType = GetIconType();
 
599
        if(ICON_INTERNAL == nType)
 
600
        {
 
601
                int nIcoIdx = InternalIcon_Name2Index(GetIconValue());
 
602
                if(nIcoIdx >= 0)
 
603
                {
 
604
                        const char **szIconData = InternalIcon_GetFromIdx(nIcoIdx);
 
605
                        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (szIconData);
 
606
                        GdkPixbuf *destpix = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR);
 
607
                        g_object_unref (G_OBJECT (pixbuf));
 
608
                        gtk_image_set_from_pixbuf (GTK_IMAGE(image1), destpix);
 
609
                        g_object_unref (G_OBJECT (destpix));
 
610
                }
 
611
                else
 
612
                {
 
613
                        gtk_image_set_from_file(GTK_IMAGE(image1), NULL);       //clear image
 
614
                }
 
615
        }
 
616
        else if(ICON_CUSTOM == nType)
 
617
        {
 
618
                GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(GetIconValue(), 16, 16, NULL);
 
619
                if(pixbuf){
 
620
                        gtk_image_set_from_pixbuf (GTK_IMAGE(image1), pixbuf);
 
621
                        g_object_unref (G_OBJECT (pixbuf));
 
622
                }
 
623
                else
 
624
                {
 
625
                        gtk_image_set_from_file(GTK_IMAGE(image1), NULL);       //clear image
 
626
                }
 
627
        }
 
628
        else
 
629
                gtk_image_set_from_file(GTK_IMAGE(image1), NULL);       //clear image
 
630
}
 
631
 
 
632
void on_internal_combo_selected (GtkComboBox *widget, gpointer user_data)
 
633
{
 
634
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
 
635
        pDlg->UpdatePreview();
 
636
}
 
637
 
 
638
void on_keyword_add_selected (GtkMenuItem *menuitem, gpointer user_data)
 
639
{
 
640
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
 
641
        pDlg->KeywordAdd();
 
642
}
 
643
 
 
644
void on_keyword_remove_selected (GtkMenuItem *menuitem, gpointer user_data)
 
645
{
 
646
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
 
647
        pDlg->KeywordRemove();
 
648
}
 
649
 
 
650
void on_finished_checked (GtkMenuItem *menuitem, gpointer user_data)
 
651
{
 
652
        NodePropertiesDlg *pDlg = (NodePropertiesDlg *)user_data;
 
653
        GtkWidget *chk_finished = lookup_widget(pDlg->m_pDialog, "chk_finished");
 
654
        if(gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(chk_finished)))
 
655
                pDlg->m_bFinished = true;
 
656
        else
 
657
                pDlg->m_bFinished = false;
 
658
}
 
659
 
 
660
void FormatTime(time_t nTime, std::string& strTxt)
 
661
{
 
662
        struct tm *pTM = localtime(&nTime);
 
663
 
 
664
        char szTime[60];
 
665
        snprintf(szTime, sizeof(szTime), "%d.%02d.%02d %02d:%02d:%02d", pTM->tm_year+1900, pTM->tm_mon+1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, pTM->tm_sec);
 
666
 
 
667
        strTxt = szTime;
 
668
}
 
669
 
 
670
const char *combo_get_text(GtkWidget *cbo3)
 
671
{
 
672
        //FIX: gtk_combo_box_get_active_text API crashes on Zaurus
 
673
#ifdef _ZAURUS_BUILD
 
674
        return gtk_entry_get_text(GTK_ENTRY(GTK_BIN(cbo3)->child));     
 
675
#else
 
676
 #if GTK_CHECK_VERSION(2,6,0) //new API //TOFIX set proper version//
 
677
        return gtk_combo_box_get_active_text (GTK_COMBO_BOX(cbo3));
 
678
 #else
 
679
        int nPos = gtk_combo_box_get_active(GTK_COMBO_BOX(cbo3));
 
680
        if(nPos >= 0)
 
681
        {
 
682
                GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbo3));
 
683
                GtkTreeIter iter;
 
684
                char szPath[10];
 
685
                sprintf(szPath, "%d", nPos);
 
686
                GtkTreePath *path1 = gtk_tree_path_new_from_string (szPath);
 
687
                if(gtk_tree_model_get_iter(model, &iter, path1))
 
688
                {
 
689
                        gchar *value = NULL;
 
690
                        gtk_tree_model_get (model, &iter, 0, &value, -1);
 
691
                        return value;
 
692
                        //g_free(value);
 
693
                }
 
694
        }
 
695
        else //TOFIX get text from entry
 
696
                return "";
 
697
 #endif
 
698
#endif
 
699
}