talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

claws.c (3326B)


      1 /*
      2  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
      3  * Copyright (C) 1999-2012  the Claws Mail team
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation; either version 3 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
     17  *
     18  */
     19 
     20 #include "defs.h"
     21 #include <stdlib.h>
     22 #include <locale.h>
     23 #include <glib.h>
     24 #ifdef ENABLE_NLS
     25 #include <glib/gi18n.h>
     26 #else
     27 #define _(a) (a)
     28 #define N_(a) (a)
     29 #endif
     30 
     31 
     32 #include "claws.h"
     33 #include "utils.h"
     34 #include "ssl.h"
     35 #include "version.h"
     36 
     37 static gboolean claws_initialized = FALSE;
     38 static gchar *startup_dir;
     39 static void (*claws_idle_function)(void) = NULL;
     40 
     41 /**
     42  * Parse program parameters and remove all parameters
     43  * that have been processed. Arguments are pointers to
     44  * original passed programm arguments and these will
     45  * be modified leaving only unknown parameters for
     46  * further processing
     47  *
     48  * \param argc pointer to number of parameters
     49  * \param argv pointer to array of parameter strings
     50  */
     51 static void parse_parameter(int *argc, char ***argv)
     52 {
     53 	gint i, j, k;
     54 
     55 	cm_return_if_fail(argc != NULL);
     56 	cm_return_if_fail(argv != NULL);
     57 
     58 	for (i = 1; i < *argc;) {
     59 		if ((strcmp("--debug", (*argv)[i]) == 0) || (strcmp("-d", (*argv)[i]) == 0)) {
     60 			debug_set_mode(TRUE);
     61 
     62 			(*argv)[i] = NULL;
     63 		}
     64 
     65 		i += 1;
     66 	}
     67 
     68 	/* Remove NULL args from argv[] for further processing */
     69 	for (i = 1; i < *argc; i++) {
     70 		for (k = i; k < *argc; k++)
     71 			if ((*argv)[k] != NULL)
     72 				break;
     73 
     74 		if (k > i) {
     75 			k -= i;
     76 			for (j = i + k; j < *argc; j++)
     77 				(*argv)[j - k] = (*argv)[j];
     78 			*argc -= k;
     79 		}
     80 	}
     81 }
     82 
     83 gboolean claws_init(int *argc, char ***argv)
     84 {
     85 	if (claws_initialized)
     86 		return TRUE;
     87 
     88 	ssl_init();
     89 
     90 	startup_dir = g_get_current_dir();
     91 
     92 	parse_parameter(argc, argv);
     93 
     94 	debug_print("Starting Claws Mail version %s\n", VERSION);
     95 
     96 	setlocale(LC_ALL, "");
     97 #ifdef ENABLE_NLS
     98 	bindtextdomain(PACKAGE, get_locale_dir () );
     99 	bind_textdomain_codeset (PACKAGE, "UTF-8");
    100 	textdomain(PACKAGE);
    101 #endif /*ENABLE_NLS*/
    102 	putenv("G_BROKEN_FILENAMES=1");
    103 	putenv("LIBOVERLAY_SCROLLBAR=0");
    104 
    105 	/* Disable GTK's overlay scrollbar feature, unless user has
    106 	 * this environment variable already set. */
    107 	if (!g_getenv("GTK_OVERLAY_SCROLLING"))
    108 		putenv("GTK_OVERLAY_SCROLLING=0");
    109 
    110 	/* backup if old rc file exists */
    111 	if (is_file_exist(RC_DIR)) {
    112 		if (g_rename(RC_DIR, RC_DIR ".bak") < 0) {
    113 			FILE_OP_ERROR(RC_DIR, "rename");
    114 			return FALSE;
    115 		}
    116 	}
    117 
    118 	srand((gint) time(NULL));
    119 
    120 	claws_initialized = TRUE;
    121 
    122 	return TRUE;
    123 }
    124 
    125 void claws_done(void)
    126 {
    127 	ssl_done();
    128 }
    129 
    130 const gchar *claws_get_startup_dir(void)
    131 {
    132 	return startup_dir;
    133 }
    134 
    135 guint claws_get_version(void)
    136 {
    137 	return 1234;
    138 }
    139 
    140 void claws_register_idle_function	(void (*idle_func)(void))
    141 {
    142 	claws_idle_function = idle_func;
    143 }
    144 
    145 void claws_do_idle(void)
    146 {
    147 	if (claws_idle_function != NULL)
    148 		claws_idle_function();
    149 }