Ejemplo n.º 1
0
Archivo: main.c Proyecto: rosedu/osmo
gboolean
check_if_app_is_running(void) {

FILE *fhandle;

    fhandle = fopen(prefs_get_config_filename (RUN_FLAG_FILE), "r");

    if (fhandle == NULL) {

        fhandle = fopen(prefs_get_config_filename (RUN_FLAG_FILE), "w");

        if (fhandle == NULL) {
            return TRUE;
        } else {
            fprintf(fhandle, "%d", getpid());
            fclose (fhandle);
            return FALSE;
        }

    } else {
        fclose (fhandle);
    }

    return TRUE;
}
Ejemplo n.º 2
0
void
cal_write_notes (GUI *appGUI)
{
xmlDocPtr doc;
xmlNodePtr main_node, node, note_node, dc_node;
xmlAttrPtr attr;
GtkTreeIter iter;
GSList *lnode;
struct note *a;
gchar *category, *color_str;
gint i;
xmlChar *escaped;

	if ((appGUI->save_status & WRT_CALENDAR_NOTES) != 0) return;

	appGUI->save_status |= WRT_CALENDAR_NOTES;

	doc = xmlNewDoc ((const xmlChar *) "1.0");
	attr = xmlNewDocProp (doc, (const xmlChar *) "encoding", (const xmlChar *) "utf-8");

	main_node = xmlNewNode (NULL, (const xmlChar *) CALENDAR_NOTES_NAME);
	xmlDocSetRootElement (doc, main_node);

	node = xmlNewChild (main_node, NULL, (const xmlChar *) CALENDAR_DAY_CATEGORIES_NAME, (xmlChar *) NULL);

	i = 0;

	while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (appGUI->opt->calendar_category_store), &iter, NULL, i++)) {
		gtk_tree_model_get (GTK_TREE_MODEL (appGUI->opt->calendar_category_store), &iter, 1, &color_str, 2, &category, -1);
		escaped = xmlEncodeEntitiesReentrant(doc, (const xmlChar *) category);
		dc_node = xmlNewChild (node, NULL, (const xmlChar *) "name", (xmlChar *) escaped);
		g_free (category);
        xmlFree (escaped);
		escaped = xmlEncodeEntitiesReentrant(doc, (const xmlChar *) color_str);
		xmlNewProp (dc_node, (const xmlChar *) "color", (xmlChar *) escaped);
		g_free (color_str);
        xmlFree (escaped);
	}

	for (i = 0, lnode = appGUI->cal->notes_list; lnode; lnode = lnode->next, i++) {
		a = g_slist_nth_data (appGUI->cal->notes_list, i);
		note_node = xmlNewChild (main_node, NULL, (const xmlChar *) "note", (xmlChar *) NULL);
		utl_xml_put_uint ("date", a->date, note_node);
		utl_xml_put_str ("color", a->color, note_node, doc);
		utl_xml_put_str ("message", a->note, note_node, doc);
	}

	xmlSaveFormatFileEnc (prefs_get_config_filename (CALENDAR_NOTES_FILENAME, appGUI), doc, "utf-8", 1);
	xmlFreeProp (attr);
	xmlFreeDoc (doc);

	appGUI->save_status &= ~WRT_CALENDAR_NOTES;
}
Ejemplo n.º 3
0
void
write_notes (GUI *appGUI) {

GSList *lnode;
struct note *a;
gint i;
xmlDocPtr doc;
xmlNodePtr main_node, node, note_node, dc_node;
xmlAttrPtr attr;
gchar *category, *color_str;
GtkTreeIter iter;
gchar temp[BUFFER_SIZE];


    doc = xmlNewDoc((const xmlChar *) "1.0");
    attr = xmlNewDocProp (doc, (const xmlChar *) "encoding", (const xmlChar *) "utf-8");

    main_node = xmlNewNode(NULL, (const xmlChar *) CALENDAR_NOTES_NAME);
    xmlDocSetRootElement(doc, main_node);

    node = xmlNewChild(main_node, NULL, (const xmlChar *) CALENDAR_DAY_CATEGORIES_NAME, (xmlChar *) NULL);

    i = 0;

    while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(appGUI->opt->calendar_category_store), &iter, NULL, i++)) {

        gtk_tree_model_get(GTK_TREE_MODEL(appGUI->opt->calendar_category_store), &iter, 1, &color_str, 2, &category, -1);
        dc_node = xmlNewChild(node, NULL, (const xmlChar *) "name", (xmlChar *) category);
        g_free(category);
        xmlNewProp(dc_node, (const xmlChar *) "color", (xmlChar *) color_str);
        g_free(color_str);
    }

    for (i = 0, lnode = appGUI->cal->notes_list; lnode; lnode = lnode->next, i++) {

        a = g_slist_nth_data (appGUI->cal->notes_list, i);
        note_node = xmlNewChild(main_node, NULL, (const xmlChar *) "note", (xmlChar *) NULL);
        sprintf(temp, "%d", a->day);
        xmlNewChild(note_node, NULL, (const xmlChar *) "day", (xmlChar *) temp);
        sprintf(temp, "%d", a->month);
        xmlNewChild(note_node, NULL, (const xmlChar *) "month", (xmlChar *) temp);
        sprintf(temp, "%d", a->year);
        xmlNewChild(note_node, NULL, (const xmlChar *) "year", (xmlChar *) temp);
        xmlNewChild(note_node, NULL, (const xmlChar *) "color", (xmlChar *) a->color);
        xmlNewChild(note_node, NULL, (const xmlChar *) "message", (xmlChar *) a->note);
    }

    xmlSaveFormatFileEnc(prefs_get_config_filename(CALENDAR_NOTES_FILENAME), doc, "utf-8", 1);
    xmlFreeDoc(doc);
}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: rosedu/osmo
int main(int argc, char **argv) {

GtkWidget *info_dialog;

    if (argc != 1) {
        if (argc == 2 && !strncmp(argv[1], "-cal", 4) && strlen(argv[1]) == 4) {
            calendar_only = TRUE;
        } else {
            fprintf(stderr, "OSMO v%s - %s\n", VERSION, _("a handy personal organizer"));
            fprintf(stderr, "Copyright (c) 2007 Tomasz Maka <*****@*****.**>\n\n");
            fprintf(stderr, "%s: %s [%s]\n\n", _("usage"), argv[0], _("options"));
            fprintf(stderr, "%s:\n", _("options"));
            fprintf(stderr, "    -cal : %s\n", _("show small calendar window"));
            exit (-1);
        }
    }

    prefs_read_config ();

    gtk_init (&argc, &argv);

    if(check_if_app_is_running() == FALSE) {

        gtk_set_locale();
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);

        gui_create_window ();

        gtk_main ();

        prefs_write_config ();
        unlink(prefs_get_config_filename (RUN_FLAG_FILE));

    } else {

        sprintf(tmpbuf, _("Another copy of OSMO is already running or it has been stopped uncleanly (in this case please remove '%s' file and try again)."), prefs_get_config_filename (RUN_FLAG_FILE));

        info_dialog = gtk_message_dialog_new (GTK_WINDOW_TOPLEVEL, GTK_DIALOG_MODAL,
                                              GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, tmpbuf);

        gtk_window_set_title(GTK_WINDOW(info_dialog), _("Error"));
        gtk_window_set_position(GTK_WINDOW(info_dialog), GTK_WIN_POS_CENTER);
        gtk_widget_show (info_dialog);
        gtk_dialog_run(GTK_DIALOG(info_dialog));
        gtk_widget_destroy(info_dialog);
    }

    return 0;
}
Ejemplo n.º 5
0
void
write_ical_entries (GUI *appGUI) {

xmlDocPtr doc;
xmlNodePtr main_node, entry_node;
xmlAttrPtr attr;
GtkTreeIter iter;
gint i;
gchar *ical_name, *ical_filename;
gboolean desc_flag, year_flag;
gchar tmpbuf[BUFFER_SIZE];

    doc = xmlNewDoc((const xmlChar *) "1.0");
    attr = xmlNewDocProp (doc, (const xmlChar *) "encoding", (const xmlChar *) "utf-8");

    main_node = xmlNewNode(NULL, (const xmlChar *) ICAL_NAME);
    xmlDocSetRootElement(doc, main_node);

    i = 0;

    while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(appGUI->opt->calendar_ical_files_store), &iter, NULL, i++)) {

        gtk_tree_model_get(GTK_TREE_MODEL(appGUI->opt->calendar_ical_files_store), &iter, 
                           ICAL_COLUMN_NAME, &ical_name, ICAL_COLUMN_FILENAME, &ical_filename, 
                           ICAL_COLUMN_ENABLE_DESC, &desc_flag, ICAL_COLUMN_USE_YEAR, &year_flag, -1);

        entry_node = xmlNewChild(main_node, NULL, (const xmlChar *) "entry", (xmlChar *) NULL);
        xmlNewChild(entry_node, NULL, (const xmlChar *) "name", (xmlChar *) ical_name);
        g_free(ical_name);
        xmlNewChild(entry_node, NULL, (const xmlChar *) "filename", (xmlChar *) ical_filename);
        g_free(ical_filename);
        sprintf(tmpbuf, "%d", desc_flag);
        xmlNewChild(entry_node, NULL, (const xmlChar *) "description", (xmlChar *) tmpbuf);
        sprintf(tmpbuf, "%d", year_flag);
        xmlNewChild(entry_node, NULL, (const xmlChar *) "use_year", (xmlChar *) tmpbuf);
    }

    xmlSaveFormatFileEnc(prefs_get_config_filename(ICAL_ENTRIES_FILENAME, appGUI), doc, "utf-8", 1);
    xmlFreeDoc(doc);

    ics_calendar_close (appGUI);
}
Ejemplo n.º 6
0
void
read_notes (GUI *appGUI) {

xmlDocPtr doc;
xmlChar *key, *prop;
xmlNodePtr node, cnode, category_node;
GtkTreeIter iter;
GdkPixbuf *image;
guint day, month, year;
gchar *color_str;

    appGUI->cal->notes_list = NULL;

    if (g_file_test (prefs_get_config_filename(CALENDAR_NOTES_FILENAME), G_FILE_TEST_IS_REGULAR) == FALSE) 
        return;

    if((doc = xmlParseFile(prefs_get_config_filename(CALENDAR_NOTES_FILENAME)))) {

        if(!(node = xmlDocGetRootElement(doc))) {
            return;
        }

        if(!xmlStrcmp(node->name, (xmlChar *) CALENDAR_NOTES_NAME)) {

            /* read note */
            node = node->xmlChildrenNode;

            while (node != NULL) {

                if(!xmlStrcmp(node->name, (xmlChar *) CALENDAR_DAY_CATEGORIES_NAME)) {

                    category_node = node->xmlChildrenNode;

                    while (category_node != NULL) {

                        if ((!xmlStrcmp(category_node->name, (const xmlChar *) "name"))) {
                            key = xmlNodeListGetString(doc, category_node->xmlChildrenNode, 1);
                            prop = xmlGetProp(category_node, (const xmlChar *) "color");
                            if (key != NULL) {
                                image = gui_create_color_swatch ((gchar *) prop);
                                gtk_list_store_append(appGUI->opt->calendar_category_store, &iter);
                                gtk_list_store_set(appGUI->opt->calendar_category_store, &iter, 0, image, 
                                                   1, prop, 2, (gchar *) key, -1);
                                g_object_unref (image);
                            }
                            xmlFree(key);
                        }
                        category_node = category_node->next;
                    }
                }

                if(!xmlStrcmp(node->name, (xmlChar *) "note")) {

                    cnode = node->xmlChildrenNode;

                    day = month = year = 0;
                    color_str = NULL;

                    while (cnode != NULL) {

                        if ((!xmlStrcmp(cnode->name, (const xmlChar *) "day"))) {
                            key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                            if (key != NULL)
                                    day = atoi ((gchar *) key);
                            xmlFree(key);
                        }
                        if ((!xmlStrcmp(cnode->name, (const xmlChar *) "month"))) {
                            key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                            if (key != NULL)
                                    month = atoi ((gchar *) key);
                            xmlFree(key);
                        }
                        if ((!xmlStrcmp(cnode->name, (const xmlChar *) "year"))) {
                            key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                            if (key != NULL)
                                    year = atoi ((gchar *) key);
                            xmlFree(key);
                        }
                        if ((!xmlStrcmp(cnode->name, (const xmlChar *) "color"))) {
                            key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                            if (key != NULL)
                                    color_str = g_strdup((gchar *) key);
                            xmlFree(key);
                        }
                        if ((!xmlStrcmp(cnode->name, (const xmlChar *) "message"))) {
                            key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                            if (key != NULL) {
                                add_note (day, month, year, color_str, (gchar *) key, appGUI);
                                if (color_str != NULL) {
                                    g_free(color_str);
                                }
                            }
                            xmlFree(key);
                        }

                        cnode = cnode->next;
                    }

                }

                node = node->next;
            }

        }

        xmlFree(node);
        xmlFreeDoc(doc);
    }

}
Ejemplo n.º 7
0
void
write_tasks_entries (GUI *appGUI) {

gint i;
xmlDocPtr doc;
xmlNodePtr main_node, node, note_node;
xmlAttrPtr attr;
gchar temp[BUFFER_SIZE];
GtkTreeIter iter;
gboolean *done;
gchar *priority, *category, *summary, *desc;
guint32 due_date_julian, start_date_julian;


    doc = xmlNewDoc((const xmlChar *) "1.0");
    attr = xmlNewDocProp (doc, (const xmlChar *) "encoding", (const xmlChar *) "utf-8");

    main_node = xmlNewNode(NULL, (const xmlChar *) TASKS_NAME);
    xmlDocSetRootElement(doc, main_node);

    node = xmlNewChild(main_node, NULL, (const xmlChar *) TASKS_CATEGORY_ENTRIES_NAME, (xmlChar *) NULL);

    i = 0;

    while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(appGUI->opt->tasks_category_store), &iter, NULL, i++)) {

        gtk_tree_model_get(GTK_TREE_MODEL(appGUI->opt->tasks_category_store), &iter, 0, &category, -1);
        xmlNewChild(node, NULL, (const xmlChar *) "name", (xmlChar *) category);
        g_free(category);
    }

    node = xmlNewChild(main_node, NULL, (const xmlChar *) TASKS_ENTRIES_NAME, (xmlChar *) NULL);

    i = 0;

    while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(appGUI->tsk->tasks_list_store), &iter, NULL, i++)) {

        gtk_tree_model_get(GTK_TREE_MODEL(appGUI->tsk->tasks_list_store), &iter, 
                           COLUMN_DONE, &done,
                           COLUMN_DUE_DATE_JULIAN, &due_date_julian,
                           COLUMN_START_DATE_JULIAN, &start_date_julian,
                           COLUMN_PRIORITY, &priority,
                           COLUMN_CATEGORY, &category,
                           COLUMN_SUMMARY, &summary,
                           COLUMN_DESCRIPTION, &desc, -1);

        note_node = xmlNewChild(node, NULL, (const xmlChar *) "entry", (xmlChar *) NULL);
        sprintf(temp, "%d", (gint) done);
        xmlNewChild(note_node, NULL, (const xmlChar *) "status", (xmlChar *) temp);
        sprintf(temp, "%d", (guint32) due_date_julian);
        xmlNewChild(note_node, NULL, (const xmlChar *) "due_date", (xmlChar *) temp);
        sprintf(temp, "%d", (guint32) start_date_julian);
        xmlNewChild(note_node, NULL, (const xmlChar *) "start_date", (xmlChar *) temp);
        sprintf(temp, "%d", get_priority_index(gettext(priority)));
        xmlNewChild(note_node, NULL, (const xmlChar *) "priority", (xmlChar *) temp);
        xmlNewChild(note_node, NULL, (const xmlChar *) "category", (xmlChar *) category);
        xmlNewChild(note_node, NULL, (const xmlChar *) "summary", (xmlChar *) summary);
        xmlNewChild(note_node, NULL, (const xmlChar *) "description", (xmlChar *) desc);
    }

    xmlSaveFormatFileEnc(prefs_get_config_filename(TASKS_ENTRIES_FILENAME), doc, "utf-8", 1);
    xmlFreeDoc(doc);
}
Ejemplo n.º 8
0
void
read_tasks_entries (GUI *appGUI) {

xmlDocPtr doc;
xmlChar *key;
xmlNodePtr node, cnode, category_node, main_node;
GtkTreeIter iter;
gboolean done;
gchar priority[BUFFER_SIZE], category[BUFFER_SIZE];
gchar summary[MAX_SUMMARY_SIZE];
guint32 due_date_julian, start_date_julian, priority_n;


    if (g_file_test (prefs_get_config_filename(TASKS_ENTRIES_FILENAME), G_FILE_TEST_IS_REGULAR) == FALSE) 
        return;

    if((doc = xmlParseFile(prefs_get_config_filename(TASKS_ENTRIES_FILENAME)))) {

        if(!(node = xmlDocGetRootElement(doc))) {
            xmlFreeDoc(doc);
            return;
        }

        if (xmlStrcmp(node->name, (const xmlChar *) TASKS_NAME)) {
            xmlFreeDoc(doc);
            return;
        }

        main_node = node->xmlChildrenNode;

        while (main_node != NULL) {

            if(!xmlStrcmp(main_node->name, (xmlChar *) TASKS_CATEGORY_ENTRIES_NAME)) {

                /* read note */
                category_node = main_node->xmlChildrenNode;

                while (category_node != NULL) {

                    if ((!xmlStrcmp(category_node->name, (const xmlChar *) "name"))) {
                        key = xmlNodeListGetString(doc, category_node->xmlChildrenNode, 1);
                        if (key != NULL) {
                            gtk_list_store_append(appGUI->opt->tasks_category_store, &iter);
                            gtk_list_store_set(appGUI->opt->tasks_category_store, &iter, 0, (gchar *) key, -1);
                        }
                        xmlFree(key);
                    }

                    category_node = category_node->next;
                }
            }

            /*---------------------------------------------------------------------------------------*/

            if(!xmlStrcmp(main_node->name, (xmlChar *) TASKS_ENTRIES_NAME)) {

                /* read note */
                node = main_node->xmlChildrenNode;

                while (node != NULL) {

                    if(!xmlStrcmp(node->name, (xmlChar *) "entry")) {

                        cnode = node->xmlChildrenNode;

                        done = FALSE;
                        due_date_julian = start_date_julian = 0;

                        while (cnode != NULL) {

                            if ((!xmlStrcmp(cnode->name, (const xmlChar *) "status"))) {
                                key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                                if (key != NULL) {
                                    sscanf((gchar *) key, "%d", &done);
                                    xmlFree(key);
                                }
                            }
                            if ((!xmlStrcmp(cnode->name, (const xmlChar *) "due_date"))) {
                                key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                                if (key != NULL) {
                                    sscanf((gchar *) key, "%d", &due_date_julian);
                                    xmlFree(key);
                                }
                            }
                            if ((!xmlStrcmp(cnode->name, (const xmlChar *) "start_date"))) {
                                key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                                if (key != NULL) {
                                    sscanf((gchar *) key, "%d", &start_date_julian);
                                    xmlFree(key);
                                }
                            }
                            if ((!xmlStrcmp(cnode->name, (const xmlChar *) "priority"))) {
                                key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                                if (key != NULL) {
                                    strncpy (priority, (gchar *) key, BUFFER_SIZE-1);
                                    if (get_priority_index(gettext(priority)) == -1) {
                                        sscanf((gchar *) key, "%d", &priority_n);
                                        strncpy (priority, get_priority_text(priority_n), BUFFER_SIZE-1);
                                    }
                                    xmlFree(key);
                                }
                            }
                            if ((!xmlStrcmp(cnode->name, (const xmlChar *) "category"))) {
                                key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                                if (key != NULL) {
                                    strncpy (category, (gchar *) key, BUFFER_SIZE-1);
                                    xmlFree(key);
                                }
                            }
                            if ((!xmlStrcmp(cnode->name, (const xmlChar *) "summary"))) {
                                key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);
                                if (key != NULL) {
                                    strncpy (summary, (gchar *) key, MAX_SUMMARY_SIZE-1);
                                    xmlFree(key);
                                }
                            }
                            if ((!xmlStrcmp(cnode->name, (const xmlChar *) "description"))) {
                                key = xmlNodeListGetString(doc, cnode->xmlChildrenNode, 1);

                                add_item_to_list(done, due_date_julian, start_date_julian, priority, 
                                                     category, summary, (gchar *) key, appGUI);
                                if (key != NULL) {
                                    xmlFree(key);
                                }
                            }

                            cnode = cnode->next;
                        }

                    }

                    node = node->next;
                }

            }



            /*---------------------------------------------------------------------------------------*/

            main_node = main_node->next;
        }

        xmlFree(node);
        xmlFreeDoc(doc);
    }

}
Ejemplo n.º 9
0
void
read_ical_entries (GUI *appGUI) {

xmlDocPtr doc;
xmlChar *key;
xmlNodePtr node, entry_node, main_node;
gboolean desc_flag;
gchar item_name[BUFFER_SIZE], item_filename[BUFFER_SIZE];
GtkTreeIter iter;

    if (g_file_test (prefs_get_config_filename(ICAL_ENTRIES_FILENAME, appGUI), G_FILE_TEST_IS_REGULAR) == FALSE) 
        return;

    if((doc = xmlParseFile(prefs_get_config_filename(ICAL_ENTRIES_FILENAME, appGUI)))) {

        if(!(node = xmlDocGetRootElement(doc))) {
            xmlFreeDoc(doc);
            return;
        }

        if (xmlStrcmp(node->name, (const xmlChar *) ICAL_NAME)) {
            xmlFreeDoc(doc);
            return;
        }

        main_node = node->xmlChildrenNode;

        while (main_node != NULL) {

            if(!xmlStrcmp(main_node->name, (xmlChar *) "entry")) {

                entry_node = main_node->xmlChildrenNode;

                while (entry_node != NULL) {

                    if ((!xmlStrcmp(entry_node->name, (const xmlChar *) "name"))) {
                        key = xmlNodeListGetString(doc, entry_node->xmlChildrenNode, 1);
                        if (key != NULL) {
                            strncpy (item_name, (gchar *) key, BUFFER_SIZE-1);
                            xmlFree(key);
                        }
                    }
                    if ((!xmlStrcmp(entry_node->name, (const xmlChar *) "filename"))) {
                        key = xmlNodeListGetString(doc, entry_node->xmlChildrenNode, 1);
                        if (key != NULL) {
                            strncpy (item_filename, (gchar *) key, BUFFER_SIZE-1);
                            xmlFree(key);
                        }
                    }
                    if ((!xmlStrcmp(entry_node->name, (const xmlChar *) "description"))) {
                        key = xmlNodeListGetString(doc, entry_node->xmlChildrenNode, 1);
                        if (key != NULL) {
                            desc_flag = atoi((gchar *) key);
                            xmlFree(key);
                        }
                    }
                    if ((!xmlStrcmp(entry_node->name, (const xmlChar *) "use_year"))) {
                        key = xmlNodeListGetString(doc, entry_node->xmlChildrenNode, 1);
                        if (key != NULL) {
                            gtk_list_store_append(appGUI->opt->calendar_ical_files_store, &iter);
                            gtk_list_store_set(appGUI->opt->calendar_ical_files_store, &iter, 
                                               ICAL_COLUMN_NAME, item_name, ICAL_COLUMN_FILENAME, item_filename, 
                                               ICAL_COLUMN_ENABLE_DESC, desc_flag, 
                                               ICAL_COLUMN_USE_YEAR, atoi((gchar *) key), -1); 
                            xmlFree(key);
                        }
                    }

                    entry_node = entry_node->next;
                }
            }
            main_node = main_node->next;
        }
    }

    ics_check_if_valid (appGUI);
    ics_calendar_init (appGUI);
}
Ejemplo n.º 10
0
void
cal_read_notes (GUI *appGUI)
{
xmlDocPtr doc;
xmlChar *key, *prop;
xmlNodePtr node, cnode, category_node;
GtkTreeIter iter;
GdkPixbuf *image;
guint32 julian;
gint day, month, year;
gchar *color_str, *note;
GDate *date;

	appGUI->cal->notes_list = NULL;

	date = g_date_new ();
	g_return_if_fail (date != NULL);

	if (g_file_test (prefs_get_config_filename (CALENDAR_NOTES_FILENAME, appGUI), G_FILE_TEST_IS_REGULAR) == FALSE)
		return;

	if ((doc = xmlParseFile (prefs_get_config_filename (CALENDAR_NOTES_FILENAME, appGUI)))) {

		if (!(node = xmlDocGetRootElement (doc))) return;

		if (!xmlStrcmp (node->name, (xmlChar *) CALENDAR_NOTES_NAME)) {

			/* read note */
			node = node->xmlChildrenNode;

			while (node != NULL) {

				if (!xmlStrcmp (node->name, (xmlChar *) CALENDAR_DAY_CATEGORIES_NAME)) {
					category_node = node->xmlChildrenNode;

					while (category_node != NULL) {

						if ((!xmlStrcmp (category_node->name, (const xmlChar *) "name"))) {
							key = xmlNodeListGetString (doc, category_node->xmlChildrenNode, 1);
							prop = xmlGetProp (category_node, (const xmlChar *) "color");
							if (key != NULL) {
								image = gui_create_color_swatch ((gchar *) prop);
								gtk_list_store_append (appGUI->opt->calendar_category_store, &iter);
								gtk_list_store_set (appGUI->opt->calendar_category_store, &iter, 0, image,
								                    1, prop, 2, (gchar *) key, -1);
								g_object_unref (image);
								xmlFree (key);
							}
						}

						category_node = category_node->next;
					}

				}

				if (!xmlStrcmp (node->name, (xmlChar *) "note")) {
					cnode = node->xmlChildrenNode;
					julian = 0;
					day = month = year = 0;
					color_str = NULL;
					note = NULL;

					while (cnode != NULL) {
						utl_xml_get_int ("day", &day, cnode, doc);
						utl_xml_get_int ("month", &month, cnode, doc);
						utl_xml_get_int ("year", &year, cnode, doc);
						utl_xml_get_uint ("date", &julian, cnode, doc);
						utl_xml_get_str ("color", &color_str, cnode, doc);
						utl_xml_get_str ("message", &note, cnode, doc);
						cnode = cnode->next;
					}

					if (note != NULL && (g_date_valid_dmy (day, month, year) || g_date_valid_julian (julian))) {
						if (g_date_valid_julian (julian)) g_date_set_julian (date, julian);
						else g_date_set_dmy (date, day, month, year);

						cal_add_note (date, color_str, note, appGUI);
						if (color_str != NULL) g_free (color_str);
						g_free (note);
					}
				}

				node = node->next;
			}

		}

		xmlFree (node);
		xmlFreeDoc (doc);
	}

	g_date_free (date);
}
Ejemplo n.º 11
0
void
prefs_write_config (GUI *appGUI)
{
xmlDocPtr doc;
xmlNodePtr node, general_node, calendar_node, tasks_node, contacts_node, notes_node;

	doc = xmlNewDoc ((const xmlChar *) "1.0");
	node = xmlNewNode (NULL, (const xmlChar *) CONFIG_NAME);
	xmlDocSetRootElement (doc, node);

	/*---------------------------------------------------------------------------------------*/
	/* general */

	general_node = xmlNewNode (NULL, (const xmlChar *) "general");
	xmlAddChild (node, general_node);

	utl_xml_put_int ("window_x", config.window_x, general_node);
	utl_xml_put_int ("window_y", config.window_y, general_node);
	utl_xml_put_int ("window_size_x", config.window_size_x, general_node);
	utl_xml_put_int ("window_size_y", config.window_size_y, general_node);
	utl_xml_put_int ("enable_tooltips", config.enable_tooltips, general_node);
	utl_xml_put_int ("latest_tab", config.latest_tab, general_node);
	utl_xml_put_int ("tabs_position", config.tabs_position, general_node);
	utl_xml_put_int ("remember_latest_tab", config.remember_latest_tab, general_node);
	utl_xml_put_int ("save_data_after_modification", config.save_data_after_modification, general_node);
	utl_xml_put_int ("default_stock_icons", config.default_stock_icons, general_node);
	utl_xml_put_int ("disable_underline_links", config.disable_underline_links, general_node);
	utl_xml_put_int ("date_format", config.date_format, general_node);
	utl_xml_put_int ("time_format", config.time_format, general_node);
	utl_xml_put_int ("enable_systray", config.enable_systray, general_node);
	utl_xml_put_int ("start_minimised_in_systray", config.start_minimised_in_systray, general_node);
	utl_xml_put_int ("blink_on_events", config.blink_on_events, general_node);
	utl_xml_put_int ("ignore_day_note_events", config.ignore_day_note_events, general_node);
	utl_xml_put_int ("run_counter", config.run_counter, general_node);
	utl_xml_put_int ("lastrun_date", config.lastrun_date, general_node);
	utl_xml_put_int ("lastrun_time", config.lastrun_time, general_node);
	utl_xml_put_int ("hide_calendar", config.hide_calendar, general_node);
	utl_xml_put_int ("hide_tasks", config.hide_tasks, general_node);
	utl_xml_put_int ("hide_contacts", config.hide_contacts, general_node);
	utl_xml_put_int ("hide_notes", config.hide_notes, general_node);
	utl_xml_put_strn ("spell_lang", config.spell_lang, MAXNAME, general_node, doc);
	utl_xml_put_strn ("web_browser", config.web_browser, MAXHELPERCMD, general_node, doc);
	utl_xml_put_strn ("email_client", config.email_client, MAXHELPERCMD, general_node, doc);

	/*---------------------------------------------------------------------------------------*/
	/* calendar */

	calendar_node = xmlNewNode (NULL, (const xmlChar *) "calendar");
	xmlAddChild (node, calendar_node);

	utl_xml_put_int ("fy_window_size_x", config.fy_window_size_x, calendar_node);
	utl_xml_put_int ("fy_window_size_y", config.fy_window_size_y, calendar_node);
	utl_xml_put_int ("fy_simple_view", config.fy_simple_view, calendar_node);
	utl_xml_put_int ("fy_alternative_view", config.fy_alternative_view, calendar_node);
	utl_xml_put_int ("cb_window_size_x", config.cb_window_size_x, calendar_node);
	utl_xml_put_int ("cb_window_size_y", config.cb_window_size_y, calendar_node);
	utl_xml_put_int ("ib_window_size_x", config.ib_window_size_x, calendar_node);
	utl_xml_put_int ("ib_window_size_y", config.ib_window_size_y, calendar_node);
	utl_xml_put_int ("display_options", config.display_options, calendar_node);
	utl_xml_put_int ("day_notes_visible", config.day_notes_visible, calendar_node);
	utl_xml_put_int ("timeline_start", config.timeline_start, calendar_node);
	utl_xml_put_int ("timeline_end", config.timeline_end, calendar_node);
	utl_xml_put_int ("timeline_step", config.timeline_step, calendar_node);
	utl_xml_put_int ("di_show_current_time", config.di_show_current_time, calendar_node);
	utl_xml_put_int ("di_show_day_number", config.di_show_day_number, calendar_node);
	utl_xml_put_int ("di_show_current_day_distance", config.di_show_current_day_distance, calendar_node);
	utl_xml_put_int ("di_show_marked_days", config.di_show_marked_days, calendar_node);
	utl_xml_put_int ("di_show_week_number", config.di_show_week_number, calendar_node);
	utl_xml_put_int ("di_show_weekend_days", config.di_show_weekend_days, calendar_node);
	utl_xml_put_int ("di_show_day_category", config.di_show_day_category, calendar_node);
	utl_xml_put_int ("di_show_moon_phase", config.di_show_moon_phase, calendar_node);
	utl_xml_put_int ("di_show_notes", config.di_show_notes, calendar_node);
	utl_xml_put_int ("di_show_zodiac_sign", config.di_show_zodiac_sign, calendar_node);
	utl_xml_put_int ("cursor_type", config.cursor_type, calendar_node);
	utl_xml_put_int ("frame_cursor_thickness", config.frame_cursor_thickness, calendar_node);
	utl_xml_put_int ("enable_auxilary_calendars", config.enable_auxilary_calendars, calendar_node);
	utl_xml_put_int ("enable_day_mark", config.enable_day_mark, calendar_node);
	utl_xml_put_int ("strikethrough_past_notes", config.strikethrough_past_notes, calendar_node);
	utl_xml_put_int ("ascending_sorting_in_day_notes_browser", config.ascending_sorting_in_day_notes_browser, calendar_node);
	utl_xml_put_int ("auxilary_calendars_state", config.auxilary_calendars_state, calendar_node);
	utl_xml_put_int ("day_note_spell_checker", config.day_note_spell_checker, calendar_node);
	utl_xml_put_char ("day_note_marker", config.day_note_marker, calendar_node, doc);
	utl_xml_put_int ("event_marker_type", config.event_marker_type, calendar_node);
	utl_xml_put_int ("today_marker_type", config.today_marker_type, calendar_node);
	utl_xml_put_int ("day_notes_browser_filter", config.day_notes_browser_filter, calendar_node);
	utl_xml_put_int ("ical_export_pane_pos", config.ical_export_pane_pos, calendar_node);
	utl_xml_put_strn ("header_color", config.header_color, MAXCOLORNAME, calendar_node, doc);
	utl_xml_put_strn ("weekend_color", config.weekend_color, MAXCOLORNAME, calendar_node, doc);
	utl_xml_put_strn ("selection_color", config.selection_color, MAXCOLORNAME, calendar_node, doc);
	utl_xml_put_strn ("mark_color", config.mark_color, MAXCOLORNAME, calendar_node, doc);
	utl_xml_put_strn ("mark_current_day_color", config.mark_current_day_color, MAXCOLORNAME, calendar_node, doc);
	utl_xml_put_int ("mark_current_day_alpha", config.mark_current_day_alpha, calendar_node);
	utl_xml_put_int ("selector_alpha", config.selector_alpha, calendar_node);
	utl_xml_put_strn ("day_name_font", config.day_name_font, MAXFONTNAME, calendar_node, doc);
	utl_xml_put_strn ("calendar_font", config.calendar_font, MAXFONTNAME, calendar_node, doc);
	utl_xml_put_strn ("notes_font", config.notes_font, MAXFONTNAME, calendar_node, doc);
	utl_xml_put_strn ("cal_print_month_name_font", config.cal_print_month_name_font, MAXFONTNAME, calendar_node, doc);
	utl_xml_put_strn ("cal_print_day_name_font", config.cal_print_day_name_font, MAXFONTNAME, calendar_node, doc);
	utl_xml_put_strn ("cal_print_day_num_font", config.cal_print_day_num_font, MAXFONTNAME, calendar_node, doc);
	utl_xml_put_strn ("cal_print_event_font", config.cal_print_event_font, MAXFONTNAME, calendar_node, doc);
	utl_xml_put_int ("cal_print_event_length", config.cal_print_event_length, calendar_node);
	utl_xml_put_int ("cal_print_padding", config.cal_print_padding, calendar_node);
	utl_xml_put_int ("cal_print_page_orientation", config.cal_print_page_orientation, calendar_node);
	utl_xml_put_int ("cal_print_tasks", config.cal_print_tasks, calendar_node);
	utl_xml_put_int ("cal_print_birthdays", config.cal_print_birthdays, calendar_node);
	utl_xml_put_int ("cal_print_namedays", config.cal_print_namedays, calendar_node);
	utl_xml_put_int ("cal_print_day_notes", config.cal_print_day_notes, calendar_node);
	utl_xml_put_int ("cal_print_ical", config.cal_print_ical, calendar_node);

	/*---------------------------------------------------------------------------------------*/
	/* tasks */

	tasks_node = xmlNewNode (NULL, (const xmlChar *) "tasks");
	xmlAddChild (node, tasks_node);

	utl_xml_put_int ("rules_hint", config.tasks_rules_hint, tasks_node);
	utl_xml_put_int ("high_priority_in_bold", config.tasks_high_in_bold, tasks_node);
	utl_xml_put_int ("hide_completed", config.hide_completed, tasks_node);
	utl_xml_put_int ("delete_completed", config.delete_completed, tasks_node);
	utl_xml_put_int ("add_edit", config.add_edit, tasks_node);
	utl_xml_put_int ("remember_category", config.remember_category_in_tasks, tasks_node);
	utl_xml_put_int ("current_category", config.current_category_in_tasks, tasks_node);
	utl_xml_put_int ("pane_pos", config.tasks_pane_pos, tasks_node);
	utl_xml_put_int ("tasks_sorting_order", config.tasks_sorting_order, tasks_node);
	utl_xml_put_int ("tasks_sorting_mode", config.tasks_sorting_mode, tasks_node);
	utl_xml_put_int ("visible_due_date_column", config.tsk_visible_due_date_column, tasks_node);
	utl_xml_put_int ("visible_type_column", config.tsk_visible_type_column, tasks_node);
	utl_xml_put_int ("visible_priority_column", config.tsk_visible_priority_column, tasks_node);
	utl_xml_put_int ("visible_category_column", config.tsk_visible_category_column, tasks_node);
	utl_xml_put_int ("tasks_addedit_win_x", config.tasks_addedit_win_x, tasks_node);
	utl_xml_put_int ("tasks_addedit_win_y", config.tasks_addedit_win_y, tasks_node);
	utl_xml_put_int ("tasks_addedit_win_w", config.tasks_addedit_win_w, tasks_node);
	utl_xml_put_int ("tasks_addedit_win_h", config.tasks_addedit_win_h, tasks_node);
	utl_xml_put_int ("postpone_time", config.postpone_time, tasks_node);
	utl_xml_put_int ("column_idx_0", config.tasks_column_idx_0, tasks_node);
	utl_xml_put_int ("column_idx_0_width", config.tasks_column_idx_0_width, tasks_node);
	utl_xml_put_int ("column_idx_1", config.tasks_column_idx_1, tasks_node);
	utl_xml_put_int ("column_idx_1_width", config.tasks_column_idx_1_width, tasks_node);
	utl_xml_put_int ("column_idx_2", config.tasks_column_idx_2, tasks_node);
	utl_xml_put_int ("column_idx_2_width", config.tasks_column_idx_2_width, tasks_node);
	utl_xml_put_int ("column_idx_3", config.tasks_column_idx_3, tasks_node);
	utl_xml_put_int ("column_idx_3_width", config.tasks_column_idx_3_width, tasks_node);
	utl_xml_put_int ("column_idx_4", config.tasks_column_idx_4, tasks_node);
	utl_xml_put_int ("column_idx_4_width", config.tasks_column_idx_4_width, tasks_node);
	utl_xml_put_int ("column_idx_5", config.tasks_column_idx_5, tasks_node);
	utl_xml_put_int ("column_idx_5_width", config.tasks_column_idx_5_width, tasks_node);
	utl_xml_put_strn ("due_today_color", config.due_today_color, MAXCOLORNAME, tasks_node, doc);
	utl_xml_put_strn ("due_7days_color", config.due_7days_color, MAXCOLORNAME, tasks_node, doc);
	utl_xml_put_strn ("past_due_color", config.past_due_color, MAXCOLORNAME, tasks_node, doc);
	utl_xml_put_strn ("task_info_font", config.task_info_font, MAXFONTNAME, tasks_node, doc);
	utl_xml_put_strn ("global_notification_command", config.global_notification_command, MAXHELPERCMD, tasks_node, doc);

	/*---------------------------------------------------------------------------------------*/
	/* contacts */

	contacts_node = xmlNewNode (NULL, (const xmlChar *) "contacts");
	xmlAddChild (node, contacts_node);

	utl_xml_put_int ("find_mode", config.find_mode, contacts_node);
	utl_xml_put_int ("show_after_search", config.show_after_search, contacts_node);
	utl_xml_put_int ("hide_group_column", config.hide_group_column, contacts_node);
	utl_xml_put_int ("pane_pos", config.contacts_pane_pos, contacts_node);
	utl_xml_put_int ("rules_hint", config.contacts_rules_hint, contacts_node);
	utl_xml_put_int ("photo_width", config.photo_width, contacts_node);
	utl_xml_put_int ("visible_age_column", config.cnt_visible_age_column, contacts_node);
	utl_xml_put_int ("visible_birthday_date_column", config.cnt_visible_birthday_date_column, contacts_node);
	utl_xml_put_int ("visible_zodiac_sign_column", config.cnt_visible_zodiac_sign_column, contacts_node);
	utl_xml_put_strn ("contact_tag_color", config.contact_tag_color, MAXCOLORNAME, contacts_node, doc);
	utl_xml_put_strn ("contact_link_color", config.contact_link_color, MAXCOLORNAME, contacts_node, doc);
	utl_xml_put_strn ("contact_name_font", config.contact_name_font, MAXFONTNAME, contacts_node, doc);
	utl_xml_put_strn ("contact_item_font", config.contact_item_font, MAXFONTNAME, contacts_node, doc);
	utl_xml_put_int ("export_format", config.export_format, contacts_node);
	utl_xml_put_strn ("export_fields", config.export_fields, MAXCONTACTFIELDS, contacts_node, doc);
	utl_xml_put_int ("contacts_sorting_order", config.contacts_sorting_order, contacts_node);
	utl_xml_put_int ("contacts_sorting_mode", config.contacts_sorting_mode, contacts_node);
	utl_xml_put_int ("contacts_addedit_win_x", config.contacts_addedit_win_x, contacts_node);
	utl_xml_put_int ("contacts_addedit_win_y", config.contacts_addedit_win_y, contacts_node);
	utl_xml_put_int ("contacts_addedit_win_w", config.contacts_addedit_win_w, contacts_node);
	utl_xml_put_int ("contacts_addedit_win_h", config.contacts_addedit_win_h, contacts_node);
	utl_xml_put_int ("contacts_export_win_x", config.contacts_export_win_x, contacts_node);
	utl_xml_put_int ("contacts_export_win_y", config.contacts_export_win_y, contacts_node);
	utl_xml_put_int ("contacts_export_win_w", config.contacts_export_win_w, contacts_node);
	utl_xml_put_int ("contacts_export_win_h", config.contacts_export_win_h, contacts_node);
	utl_xml_put_int ("contacts_import_sel_win_x", config.contacts_import_sel_win_x, contacts_node);
	utl_xml_put_int ("contacts_import_sel_win_y", config.contacts_import_sel_win_y, contacts_node);
	utl_xml_put_int ("contacts_import_win_x", config.contacts_import_win_x, contacts_node);
	utl_xml_put_int ("contacts_import_win_y", config.contacts_import_win_y, contacts_node);
	utl_xml_put_int ("contacts_import_win_w", config.contacts_import_win_w, contacts_node);
	utl_xml_put_int ("contacts_import_win_h", config.contacts_import_win_h, contacts_node);
	utl_xml_put_int ("contacts_birthdays_win_w", config.contacts_birthdays_win_w, contacts_node);
	utl_xml_put_int ("contacts_birthdays_win_h", config.contacts_birthdays_win_h, contacts_node);
	utl_xml_put_int ("column_idx_0", config.contacts_column_idx_0, contacts_node);
	utl_xml_put_int ("column_idx_0_width", config.contacts_column_idx_0_width, contacts_node);
	utl_xml_put_int ("column_idx_1", config.contacts_column_idx_1, contacts_node);
	utl_xml_put_int ("column_idx_1_width", config.contacts_column_idx_1_width, contacts_node);
	utl_xml_put_int ("column_idx_2", config.contacts_column_idx_2, contacts_node);
	utl_xml_put_int ("column_idx_2_width", config.contacts_column_idx_2_width, contacts_node);
	utl_xml_put_int ("import_type", config.import_type, contacts_node);
	utl_xml_put_int ("import_interface_type", config.import_interface_type, contacts_node);
	utl_xml_put_int ("import_bluetooth_channel", config.import_bluetooth_channel, contacts_node);
	utl_xml_put_int ("import_usb_interface", config.import_usb_interface, contacts_node);
	utl_xml_put_int ("import_binary_xml", config.import_binary_xml, contacts_node);
	utl_xml_put_strn ("import_bluetooth_address", config.import_bluetooth_address, MAXADDRESS, contacts_node, doc);

	/*---------------------------------------------------------------------------------------*/
	/* notes */

	notes_node = xmlNewNode (NULL, (const xmlChar *) "notes");
	xmlAddChild (node, notes_node);

	utl_xml_put_int ("rules_hint", config.notes_rules_hint, notes_node);
	utl_xml_put_int ("enc_algorithm", config.notes_enc_algorithm, notes_node);
	utl_xml_put_int ("enc_hashing", config.notes_enc_hashing, notes_node);
	utl_xml_put_int ("comp_algorithm", config.notes_comp_algorithm, notes_node);
	utl_xml_put_int ("comp_ratio", config.notes_comp_ratio, notes_node);
	utl_xml_put_int ("sorting_order", config.notes_sorting_order, notes_node);
	utl_xml_put_int ("sorting_mode", config.notes_sorting_mode, notes_node);
	utl_xml_put_int ("visible_type_column", config.nte_visible_type_column, notes_node);
	utl_xml_put_int ("visible_category_column", config.nte_visible_category_column, notes_node);
	utl_xml_put_int ("visible_last_changes_column", config.nte_visible_last_changes_column, notes_node);
	utl_xml_put_int ("column_idx_0", config.notes_column_idx_0, notes_node);
	utl_xml_put_int ("column_idx_0_width", config.notes_column_idx_0_width, notes_node);
	utl_xml_put_int ("column_idx_1", config.notes_column_idx_1, notes_node);
	utl_xml_put_int ("column_idx_1_width", config.notes_column_idx_1_width, notes_node);
	utl_xml_put_int ("column_idx_2", config.notes_column_idx_2, notes_node);
	utl_xml_put_int ("column_idx_2_width", config.notes_column_idx_2_width, notes_node);
	utl_xml_put_int ("column_idx_3", config.notes_column_idx_3, notes_node);
	utl_xml_put_int ("column_idx_3_width", config.notes_column_idx_3_width, notes_node);
	utl_xml_put_int ("remember_category", config.remember_category_in_notes, notes_node);
	utl_xml_put_int ("current_category", config.current_category_in_notes, notes_node);
	utl_xml_put_int ("use_system_date", config.use_system_date_in_notes, notes_node);
	utl_xml_put_char ("text_separator", config.text_separator, notes_node, doc);
	utl_xml_put_strn ("editor_font", config.notes_editor_font, MAXFONTNAME, notes_node, doc);

	/*---------------------------------------------------------------------------------------*/

	xmlSaveFormatFile (prefs_get_config_filename (CONFIG_FILENAME, appGUI), doc, 1);
	xmlFreeDoc (doc);
}
Ejemplo n.º 12
0
Archivo: main.c Proyecto: rosedu/osmo
int main(int argc, char **argv) {

GUI *appGUI = NULL;
CALENDAR *cal = NULL;
TASKS *tsk = NULL;
CONTACTS *cnt = NULL;
NOTES *nte = NULL;
OPTIONS *opt = NULL;
GtkWidget *info_dialog;
gchar tmpbuf[BUFFER_SIZE];
gint response = -1;
struct flock *s_lock = NULL;
int fhandle;

GOptionContext *cmd_context;
gboolean cmd_calendar = FALSE;
gboolean cmd_check_events = FALSE;
gint cmd_check_ndays_events = 0;
gchar *cmd_cfg_path = NULL;
gboolean cmd_tiny_gui = FALSE;

GOptionEntry cmd_options[] = {
    { "calendar",   'c', 0, G_OPTION_ARG_NONE, &cmd_calendar, N_("Show small calendar window"), NULL  },
    { "check",      'e', 0, G_OPTION_ARG_NONE, &cmd_check_events, N_("Check for events since last run"), NULL  },
    { "days",       'd', 0, G_OPTION_ARG_INT, &cmd_check_ndays_events, N_("Number of days to check forward for events (default: 0)"), NULL  },
    { "config",     's', 0, G_OPTION_ARG_STRING, &cmd_cfg_path, N_("Set absolute path for settings and data files"), "PATH"  },
    { "tinygui",    't', 0, G_OPTION_ARG_NONE, &cmd_tiny_gui, N_("Modify GUI to use Osmo on low resolutions"), NULL  },
    { NULL }
};

    appGUI = g_new0 (GUI, 1);
    g_return_val_if_fail (appGUI != NULL, -1);

    cal = g_new0 (CALENDAR, 1);
    g_return_val_if_fail (cal != NULL, -1);
    tsk = g_new0 (TASKS, 1);
    g_return_val_if_fail (tsk != NULL, -1);
    cnt = g_new0 (CONTACTS, 1);
    g_return_val_if_fail (cnt != NULL, -1);
    nte = g_new0 (NOTES, 1);
    g_return_val_if_fail (nte != NULL, -1);

    opt = g_new0 (OPTIONS, 1);
    g_return_val_if_fail (opt != NULL, -1);

    /* register modules */
    appGUI->cal = cal;
    appGUI->tsk = tsk;
    appGUI->cnt = cnt;
    appGUI->nte = nte;
    appGUI->opt = opt;

    appGUI->run_date = utl_get_current_julian ();
    appGUI->run_time = get_seconds_for_today ();
    appGUI->key_counter = 0;

    /* default values */
    appGUI->hovering_over_link = FALSE;
    appGUI->hand_cursor = NULL;
    appGUI->regular_cursor = NULL;
    appGUI->gui_url_tag = NULL;
    appGUI->trayicon_popup_menu = NULL;

    appGUI->calendar_only = FALSE;
    appGUI->check_events = FALSE;
    appGUI->tiny_gui = FALSE;
    appGUI->save_status = 0;
    appGUI->print_font_size = 10;

	appGUI->cal->date = g_date_new ();
	g_return_val_if_fail (appGUI->cal->date != NULL, -1);
	g_date_set_time_t (appGUI->cal->date, time (NULL));

    appGUI->tsk->id_counter = 0;
    appGUI->tsk->tasks_panel_status = FALSE;
    appGUI->tsk->tasks_filter_disabled = FALSE;
    appGUI->tsk->tasks_list_store = NULL;
    appGUI->tsk->notifications = NULL;

    appGUI->cnt->photo_image = NULL;
    appGUI->cnt->contacts_uim_widget = NULL;
    appGUI->cnt->contacts_panel_status = FALSE;
    appGUI->cnt->contacts_filter_disabled = TRUE;
    appGUI->cnt->export_button = NULL;
    appGUI->cnt->output_file_entry = NULL;

    appGUI->opt->options_counter = 0;

    setlocale (LC_ALL, "");
    bindtextdomain (PACKAGE, LOCALEDIR);
    bind_textdomain_codeset (PACKAGE, "UTF-8");
    textdomain (PACKAGE);

    if (argc == 2 && (!strncmp(argv[1], "--help", 6) || (argv[1][0] == '-' && argv[1][1] == '?'))) {
        fprintf(stderr, "\nOSMO v%s - %s\n", VERSION, _("a handy personal organizer"));
        fprintf(stderr, "Copyright (c) 2007-2008 Tomasz Maka <*****@*****.**>\n\n");
    }

    cmd_context = g_option_context_new(NULL);
    g_option_context_add_main_entries(cmd_context, cmd_options, TRANSLATION_DOMAIN);
    g_option_context_parse(cmd_context, &argc, &argv, NULL);
    g_option_context_free(cmd_context);

    appGUI->calendar_only = cmd_calendar;
    appGUI->check_events = cmd_check_events;
    appGUI->check_ndays_events = cmd_check_ndays_events;
    appGUI->config_path = cmd_cfg_path;
    appGUI->tiny_gui = cmd_tiny_gui;

    if (prefs_get_config_filename (CONFIG_FILENAME, appGUI) == NULL) {
        fprintf(stderr, "%s\n", _("ERROR: Cannot create config files"));
        goto finish;
    }

    s_lock = g_new0 (struct flock, 1);
	s_lock->l_type = F_WRLCK;
	s_lock->l_whence = SEEK_SET;
	s_lock->l_start = 0;
	s_lock->l_len = 0;

    prefs_read_config (appGUI);

    close(creat(prefs_get_config_filename (RUN_FLAG_FILE, appGUI), S_IRUSR | S_IWUSR));     /* create lock file */

    gtk_init (&argc, &argv);

    fhandle = open(prefs_get_config_filename (RUN_FLAG_FILE, appGUI), O_RDWR);

    if (fhandle) {
		if (fcntl(fhandle, F_SETLK, s_lock) == -1) {
            close (fhandle);

            g_snprintf (tmpbuf, BUFFER_SIZE, "%s %s\n\n%s",
                        _("Another copy of OSMO is already running."),
                        _("Simultaneously use two or more copies of OSMO can be a cause of data loss."),
                        _("Do you really want to continue?"));

            info_dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW_TOPLEVEL, GTK_DIALOG_MODAL,
                                                  GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, tmpbuf);

            gtk_window_set_title(GTK_WINDOW(info_dialog), _("Warning"));
            gtk_window_set_position(GTK_WINDOW(info_dialog), GTK_WIN_POS_CENTER);
            gtk_widget_show (info_dialog);

            response = gtk_dialog_run(GTK_DIALOG(info_dialog));
            gtk_widget_destroy(info_dialog);

            if (response == GTK_RESPONSE_NO || response == GTK_RESPONSE_DELETE_EVENT) {
                goto finish;
            }
        }
    }

	notify_init("Osmo notification");

    if (appGUI->calendar_only != TRUE) {

        /* setup timer at 1000ms (1s) interval */
		g_timeout_add (1000, (GtkFunction) time_handler, appGUI);

    }

    config.run_counter++;

    if (gui_create_window (appGUI) == TRUE) {
        gtk_main ();
    }

    if (appGUI->calendar_only == FALSE) {
        config.lastrun_date = utl_get_current_julian ();
        config.lastrun_time = get_seconds_for_today();
    }

    if (appGUI->check_events == FALSE) {
        prefs_write_config (appGUI);
    }

    if (fhandle) {
    	s_lock->l_type = F_UNLCK;
    	fcntl(fhandle, F_SETLK, s_lock);
        close (fhandle);
    }

finish:
	g_date_free (appGUI->cal->date);
	g_free (opt);
	g_free (nte);
	g_free (cnt);
	g_free (tsk);
	g_free (cal);
	g_free (appGUI);
	g_free (s_lock);
	return 0;
}
Ejemplo n.º 13
0
int main (int argc, char **argv)
{
struct timeval timer;
gchar buffer[PATH_MAX];

GUI *appGUI = NULL;
CHART *chr = NULL;
STATISTICS *sts = NULL;
TEST *tst = NULL;
OPTIONS *opt = NULL;
#ifdef MAEMO
osso_context_t *osso_context = NULL;

    /* initialize maemo application */
    osso_context = osso_initialize(APP_NAME, APP_VER, TRUE, NULL);
    
    if (osso_context == NULL) {
        fprintf (stderr, "osso_initialize failed.\n");
        exit (1);
    }
#endif

    appGUI = g_new0 (GUI, 1);
    g_return_val_if_fail (appGUI != NULL, -1);

    chr = g_new0 (CHART, 1);
    g_return_val_if_fail (chr != NULL, -1);
    sts = g_new0 (STATISTICS, 1);
    g_return_val_if_fail (sts != NULL, -1);
    tst = g_new0 (TEST, 1);
    g_return_val_if_fail (tst != NULL, -1);

    opt = g_new0 (OPTIONS, 1);
    g_return_val_if_fail (opt != NULL, -1);

    /* register modules */
    appGUI->chr = chr;
    appGUI->sts = sts;
    appGUI->tst = tst;
    appGUI->opt = opt;

    /* default values */
    appGUI->old_kana_type = -1;
    appGUI->chr->chart_window = NULL;
    appGUI->tst->any_key = FALSE;
    appGUI->tst->test_state = FALSE;
    appGUI->sts->active_tab = -1;
    appGUI->opt->active_tab = -1;

    /* preferences update */

    g_snprintf (buffer, PATH_MAX, "%s%c%s", g_get_home_dir(), G_DIR_SEPARATOR, CONFIG_DIRNAME);

    if (g_file_test(buffer, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) != TRUE) {
        prefs_read_config (CONFIG_FILENAME_OLD, CONFIG_DIRNAME_OLD);
        prefs_write_config (CONFIG_FILENAME, CONFIG_DIRNAME);
        if (g_file_test(prefs_get_config_filename (STATS_FILENAME_OLD, CONFIG_DIRNAME_OLD), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) == TRUE) {
            stats_read_list (STATS_FILENAME_OLD, CONFIG_DIRNAME_OLD, appGUI);
        }
        stats_write_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI);
    }

    prefs_read_config (CONFIG_FILENAME, CONFIG_DIRNAME);
    stats_read_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI);

    /* init */
#ifdef MAEMO
    hildon_gtk_init (&argc, &argv);
#else
    gtk_init (&argc, &argv);
#endif
    setlocale (LC_ALL, "");

#if defined(WIN32) || defined(WIN64)
    /* Set the locale directory as subdirectory of application path */
    char WINLOCALEDIR[MAX_PATH];
    strcpy(WINLOCALEDIR, g_path_get_dirname(argv[0]));
    strcat(WINLOCALEDIR, "\\share\\locale");

    bindtextdomain (PACKAGE, WINLOCALEDIR);
#else
    bindtextdomain (PACKAGE, LOCALEDIR);
#endif
    bind_textdomain_codeset (PACKAGE, "UTF-8");
    textdomain (PACKAGE);

    /* set seed */
    gettimeofday(&timer, NULL);

#if defined(WIN32) || defined(WIN64)
    srand((long)time(NULL));
#else
    srand48(timer.tv_usec + getpid());
#endif

#ifdef MAEMO
    show_splash_screen ();
#endif
    gui_create_window (appGUI);
    gtk_main ();

    stats_write_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI);
    stats_free_list (appGUI);

    prefs_write_config (CONFIG_FILENAME, CONFIG_DIRNAME);

    g_free (opt);
    g_free (tst);
    g_free (sts);
    g_free (chr);
    g_free (appGUI);
#ifdef MAEMO
    /* deinitialize OSSO */
    osso_deinitialize (osso_context);
#endif
    return 0;
}