예제 #1
0
void
nemo_action_constructed (GObject *object)
{
    G_OBJECT_CLASS (parent_class)->constructed (object);

    NemoAction *action = NEMO_ACTION (object);

    GKeyFile *key_file = g_key_file_new();

    g_key_file_load_from_file (key_file, action->key_file_path, G_KEY_FILE_NONE, NULL);

    gchar *orig_label = g_key_file_get_locale_string (key_file,
                                                      ACTION_FILE_GROUP,
                                                      KEY_NAME,
                                                      NULL,
                                                      NULL);

    gchar *orig_tt = g_key_file_get_locale_string (key_file,
                                                   ACTION_FILE_GROUP,
                                                   KEY_COMMENT,
                                                   NULL,
                                                   NULL);

    gchar *icon_name = g_key_file_get_string (key_file,
                                              ACTION_FILE_GROUP,
                                              KEY_ICON_NAME,
                                              NULL);

    gchar *stock_id = g_key_file_get_string (key_file,
                                             ACTION_FILE_GROUP,
                                             KEY_STOCK_ID,
                                             NULL);


    gchar *exec_raw = g_key_file_get_string (key_file,
                                             ACTION_FILE_GROUP,
                                             KEY_EXEC,
                                             NULL);

    gchar *selection_string_raw = g_key_file_get_string (key_file,
                                                         ACTION_FILE_GROUP,
                                                         KEY_SELECTION,
                                                         NULL);

    gchar *selection_string = g_ascii_strdown (selection_string_raw, -1);

    g_free (selection_string_raw);

    gchar *separator = g_key_file_get_string (key_file,
                                              ACTION_FILE_GROUP,
                                              KEY_SEPARATOR,
                                              NULL);

    gchar *quote_type_string = g_key_file_get_string (key_file,
                                                      ACTION_FILE_GROUP,
                                                      KEY_QUOTE_TYPE,
                                                      NULL);

    QuoteType quote_type = QUOTE_TYPE_NONE;

    if (quote_type_string != NULL) {
        if (g_strcmp0 (quote_type_string, "single") == 0)
            quote_type = QUOTE_TYPE_SINGLE;
        else if (g_strcmp0 (quote_type_string, "double") == 0)
            quote_type = QUOTE_TYPE_DOUBLE;
        else if (g_strcmp0 (quote_type_string, "backtick") == 0)
            quote_type = QUOTE_TYPE_BACKTICK;
    }

    SelectionType type;

    if (g_strcmp0 (selection_string, SELECTION_SINGLE_KEY) == 0)
        type = SELECTION_SINGLE;
    else if (g_strcmp0 (selection_string, SELECTION_MULTIPLE_KEY) == 0)
        type = SELECTION_MULTIPLE;
    else if (g_strcmp0 (selection_string, SELECTION_ANY_KEY) == 0)
        type = SELECTION_ANY;
    else if (g_strcmp0 (selection_string, SELECTION_NONE_KEY) == 0)
        type = SELECTION_NONE;
    else if (g_strcmp0 (selection_string, SELECTION_NOT_NONE_KEY) == 0)
        type = SELECTION_NOT_NONE;
    else {
        gint val = (int) g_ascii_strtoll (selection_string, NULL, 10);
        type = val > 0 ? val : SELECTION_SINGLE;
    }

    g_free (selection_string);

    gsize count;

    gchar **ext = g_key_file_get_string_list (key_file,
                                              ACTION_FILE_GROUP,
                                              KEY_EXTENSIONS,
                                              &count,
                                              NULL);

    gsize mime_count;

    gchar **mimes = g_key_file_get_string_list (key_file,
                                                ACTION_FILE_GROUP,
                                                KEY_MIME_TYPES,
                                                &mime_count,
                                                NULL);

    gsize condition_count;

    gchar **conditions = g_key_file_get_string_list (key_file,
                                                     ACTION_FILE_GROUP,
                                                     KEY_CONDITIONS,
                                                     &condition_count,
                                                     NULL);

    gboolean escape_space;

    escape_space = g_key_file_get_boolean (key_file,
                                           ACTION_FILE_GROUP,
                                           KEY_WHITESPACE,
                                           NULL);

    if (conditions && condition_count > 0) {
        int j;
        gchar *condition;
        for (j = 0; j < condition_count; j++) {
            condition = conditions[j];
            if (g_str_has_prefix (condition, "dbus")) {
                setup_dbus_condition (action, condition);
            }
        }
    }

    gchar *exec = NULL;
    gboolean use_parent_dir = FALSE;

    strip_custom_modifier (exec_raw, &use_parent_dir, &exec);
    g_free (exec_raw);

    GFile *file = g_file_new_for_path (action->key_file_path);
    GFile *parent = g_file_get_parent (file);

    gchar *parent_dir = g_file_get_path (parent);

    g_object_unref (file);
    g_object_unref (parent);

    g_object_set  (action,
                   "label", orig_label,
                   "tooltip", orig_tt,
                   "icon-name", icon_name,
                   "stock-id", stock_id,
                   "exec", exec,
                   "selection-type", type,
                   "extensions", ext,
                   "mimetypes", mimes,
                   "parent-dir", parent_dir,
                   "use-parent-dir", use_parent_dir,
                   "orig-label", orig_label,
                   "orig-tooltip", orig_tt,
                   "quote-type", quote_type,
                   "separator", separator,
                   "conditions", conditions,
                   "escape-space", escape_space,
                    NULL);

    g_free (orig_label);
    g_free (orig_tt);
    g_free (icon_name);
    g_free (stock_id);
    g_free (exec);
    g_strfreev (ext);
    g_free (parent_dir);
    g_free (quote_type_string);
    g_free (separator);
    g_strfreev (conditions);
    g_key_file_free (key_file);
}
예제 #2
0
static void
file_ptr_array_foreach_write_meta_handler (gpointer data, gpointer user_data)
{
	GFile *file = G_FILE (data), *meta_file = NULL;
	GObject *scgi_task = G_OBJECT (user_data);
	GObject *request = NULL;
	GHashTable *req_htb = NULL;
	gchar *duration = NULL, *one_off = NULL, *rand_pass = NULL;
	GKeyFile *meta = NULL;
	GDateTime *crt_time = NULL, *exp_time = NULL;
	GFileOutputStream *file_ostream = NULL;
	guint64 dur = 0;

	g_debug ("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	request = hev_scgi_task_get_request (HEV_SCGI_TASK (scgi_task));
	req_htb = hev_scgi_request_get_header_hash_table (HEV_SCGI_REQUEST (request));

	duration = g_object_get_data (scgi_task, "duration");
	one_off = g_object_get_data (scgi_task, "one-off");
	rand_pass = g_object_get_data (scgi_task, "rand-pass");

	meta_file = g_object_get_data (G_OBJECT (file), "meta");
	g_file_delete (meta_file, NULL, NULL);
	meta = g_key_file_new ();

	/* set meta contents */
	crt_time = g_date_time_new_now_utc ();
	g_key_file_set_int64 (meta, "Meta", "CrtDate",
				g_date_time_to_unix (crt_time));
	if (duration) {
		dur = g_ascii_strtoull (duration, NULL, 10);
		if ((0 >= dur) || (7 < dur))
		  dur = 1;
	} else {
		dur = 1;
	}
	exp_time = g_date_time_add_days (crt_time, dur);
	g_key_file_set_int64 (meta, "Meta", "ExpDate",
				g_date_time_to_unix (exp_time));
	g_date_time_unref (exp_time);
	g_date_time_unref (crt_time);
	g_key_file_set_boolean (meta, "Meta", "OneOff", one_off ? TRUE : FALSE);
	g_key_file_set_string (meta, "Meta", "IP",
				g_hash_table_lookup (req_htb, "REMOTE_ADDR"));
	g_key_file_set_string (meta, "Meta", "RandPass", rand_pass);

	/* create and write to meta file */
	file_ostream = g_file_create (meta_file, G_FILE_CREATE_PRIVATE, NULL, NULL);
	if (file_ostream) {
		gchar *data = NULL;
		gsize length = 0;
		data = g_key_file_to_data (meta, &length, NULL);
		g_output_stream_write_all (G_OUTPUT_STREAM (file_ostream),
					data, length, NULL, NULL, NULL);
		g_free (data);
		g_object_unref (file_ostream);
	}

	g_key_file_unref (meta);
}
예제 #3
0
파일: tlm-seatconf.c 프로젝트: juimonen/tlm
int main (int argc, char *argv[])
{
    int retval = -1;
    int lockfd;
    int autologin = -1;
    int pause = -1;
    int setupterm = -1;
    int active = -1;
    int nwatch = -1;
    int vtnr = -1;
    int rtimedir = -1;
    gint nseats;
    gint seatx;
    gchar *cf = NULL;
    gchar *sname = NULL;
    gchar *username = NULL;
    gchar *session_type = NULL;
    gchar *pam_defserv = NULL;
    gchar *pam_serv = NULL;
    gchar *watchx = NULL;
    gchar *rtimemode = NULL;
    GKeyFile *kf;
    GError *error = NULL;
    GOptionContext *opts;
    GOptionEntry main_entries[] = {
        { "config-file", 'c',
          0, G_OPTION_ARG_FILENAME, &cf,
          "configuration file name",
          NULL },
        { "seat", 's',
          0, G_OPTION_ARG_STRING, &sname,
          "seat id",
          NULL },
        { "username", 'u',
          0, G_OPTION_ARG_STRING, &username,
          "default user name",
          NULL },
        { "autologin", 'a',
          0, G_OPTION_ARG_INT, &autologin,
          "autologin enable/disable",
          NULL },
        { "pause", 'p',
          0, G_OPTION_ARG_INT, &pause,
          "pause session enable/disable",
          NULL },
        { "setupterm", 't',
          0, G_OPTION_ARG_INT, &setupterm,
          "setup terminal enable/disable",
          NULL },
        { "sessiontype", 'd',
          0, G_OPTION_ARG_STRING, &session_type,
          "session type: can be one of 'unspecified', 'tty', 'x11', 'wayland' \
          or 'mir'",
          NULL },
        { "active", 'e',
          0, G_OPTION_ARG_INT, &active,
          "seat activation enable/disable",
          NULL },
        { "pamdefserv", 'f',
          0, G_OPTION_ARG_STRING, &pam_defserv,
          "pam service file for default user",
          NULL },
        { "pamserv", 'g',
          0, G_OPTION_ARG_STRING, &pam_serv,
          "pam service",
          NULL },
        { "nwatch", 'h',
          0, G_OPTION_ARG_INT, &nwatch,
          "number of seat-ready watch items",
          NULL },
        { "watchx", 'i',
          0, G_OPTION_ARG_STRING, &watchx,
          "seat-ready watch item",
          NULL },
        { "vtnr", 'j',
          0, G_OPTION_ARG_INT, &vtnr,
          "virtual terminal number for seat",
          NULL },
        { "rtimedir", 'k',
          0, G_OPTION_ARG_INT, &rtimedir,
          "setup XDG_RUNTIME_DIR for the user - enable/disable",
          NULL },
        { "rtimemode", 'm',
          0, G_OPTION_ARG_STRING, &rtimemode,
          "access mode for the XDG_RUNTIME_DIR",
          NULL },
        { NULL }
    };

    opts = g_option_context_new ("<add|change|remove> [command]");
    g_option_context_add_main_entries (opts, main_entries, NULL);
    g_option_context_parse (opts, &argc, &argv, NULL);
    g_option_context_free (opts);
    if (argc < 2) {
        printf ("%s [options] <add|change|remove> [command]\n", argv[0]);
        return -1;
    }
    if (!cf)
        cf = g_build_filename (TLM_SYSCONF_DIR, "tlm.conf", NULL);
    lockfd = open (cf, O_RDWR);
    if (lockfd < 0)
        g_critical ("open(%s): %s", cf, strerror (errno));
    if (lockf (lockfd, F_LOCK, 0))
        g_critical ("lockf(): %s", strerror (errno));
    kf = g_key_file_new ();
    if (!g_key_file_load_from_file (kf, cf,
                                    G_KEY_FILE_KEEP_COMMENTS, &error)) {
        g_warning ("failed to load config file: %s", error->message);
        goto err_exit;
    }
    nseats = g_key_file_get_integer (kf,
                                     TLM_CONFIG_GENERAL,
                                     TLM_CONFIG_GENERAL_NSEATS,
                                     NULL);

    if (g_strcmp0 (argv[1], "add") == 0) {
        seatx = nseats;
        nseats++;
        sname = g_strdup_printf ("seat%d", seatx);
        puts (sname);
    }
    else if (g_strcmp0 (argv[1], "change") == 0) {
        if (!sname) {
            g_warning ("no seat specified");
            goto err_exit;
        }
        if (!g_key_file_has_group (kf, sname)) {
            g_warning ("given seat doesn't exist");
            goto err_exit;
        }
    }
    else if (g_strcmp0 (argv[1], "remove") == 0) {
        if (!sname) {
            g_warning ("no seat specified");
            goto err_exit;
        }
        if (!g_key_file_has_group (kf, sname)) {
            g_warning ("given seat doesn't exist");
            goto err_exit;
        }
        g_key_file_remove_key (kf,
                               sname,
                               TLM_CONFIG_GENERAL_SESSION_CMD,
                               NULL);
        autologin = 0;
        pause = 1;
    }

    if (argc >= 3) {
        g_key_file_set_string (kf,
                               sname,
                               TLM_CONFIG_GENERAL_SESSION_CMD,
                               argv[2]);
    }
    if (username) {
        g_key_file_set_string (kf,
                               sname,
                               TLM_CONFIG_GENERAL_DEFAULT_USER,
                               username);
    }
    if (autologin >= 0) {
        g_key_file_set_integer (kf,
                                sname,
                                TLM_CONFIG_GENERAL_AUTO_LOGIN,
                                autologin);
    }
    if (pause >= 0) {
        g_key_file_set_integer (kf,
                                sname,
                                TLM_CONFIG_GENERAL_PAUSE_SESSION,
                                pause);
    }
    if (setupterm >= 0) {
        g_key_file_set_integer (kf,
                                sname,
                                TLM_CONFIG_GENERAL_SETUP_TERMINAL,
                                setupterm);
    }
    if (pam_serv) {
        g_key_file_set_string (kf,
                               sname,
                               TLM_CONFIG_GENERAL_PAM_SERVICE,
                               pam_serv);
    }
    if (pam_defserv) {
        g_key_file_set_string (kf,
                               sname,
                               TLM_CONFIG_GENERAL_DEFAULT_PAM_SERVICE,
                               pam_defserv);
    }
    if (active >= 0) {
        g_key_file_set_integer (kf,
                                sname,
                                TLM_CONFIG_SEAT_ACTIVE,
                                active);
    }
    if (session_type) {
        g_key_file_set_string (kf,
                               sname,
                               TLM_CONFIG_GENERAL_SESSION_TYPE,
                               session_type);
    }
    if (nwatch >= 0) {
        g_key_file_set_integer (kf,
                                sname,
                                TLM_CONFIG_SEAT_NWATCH,
                                nwatch);
    }
    if (watchx) {
        g_key_file_set_string (kf,
                               sname,
                               TLM_CONFIG_SEAT_WATCHX,
                               watchx);
    }
    if (vtnr >= 0) {
        g_key_file_set_integer (kf,
                                sname,
                                TLM_CONFIG_SEAT_VTNR,
                                vtnr);
    }
    if (rtimedir >= 0) {
        g_key_file_set_integer (kf,
                                sname,
                                TLM_CONFIG_GENERAL_SETUP_RUNTIME_DIR,
                                rtimedir);
    }
    if (rtimemode) {
        g_key_file_set_string (kf,
                               sname,
                               TLM_CONFIG_GENERAL_RUNTIME_MODE,
                               rtimemode);
    }
    g_key_file_set_integer (kf,
                            TLM_CONFIG_GENERAL,
                            TLM_CONFIG_GENERAL_NSEATS,
                            nseats);
    if (!g_key_file_save_to_file (kf, cf, &error))
        g_warning ("failed to save config file: %s", error->message);
    retval = 0;

err_exit:
    g_free (sname);
    g_free (cf);
    g_free (session_type);
    g_free (pam_defserv);
    g_free (pam_serv);
    g_free (watchx);
    g_free (rtimemode);
    g_key_file_free (kf);
    if (!lockf (lockfd, F_ULOCK, 0)) {}
    close (lockfd);

    return retval;
}
예제 #4
0
int main (int argc, char **argv)
{

    char sql[256];
    gboolean verbose = FALSE;
    gboolean use_mysql = FALSE;
    int ret;

    if (argc == 1)
        usage(1);

    int c;
    while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != EOF) {
        switch (c) {
        case 'h':
            usage(0);
            break;
        case 'v':
            verbose = TRUE;
            break;
        case 'm':
            use_mysql = TRUE;
            break;
        case 's':
            config.mysql_host = strdup(optarg);
            break;
        case 't':
            config.mysql_socket = strdup(optarg);
            break;
        case 'r':
            config.mysql_root_passwd = strdup(optarg);
            break;
        case 'd':
            config.seafile_dir = strdup(optarg);
            break;
        case 'p':
            config.port = strdup(optarg);
            break;
        case 'P':
            config.httpserver_port = strdup(optarg);
            break;
        default:
            usage(1);
        }
    }

    if (use_mysql && !config.mysql_root_passwd) {
        fprintf (stderr, "You choose to use mysql database. "
                 "Mysql Root Password must be specified.\n");
        exit(1);
    }

    if (!config.seafile_dir) {
        fprintf (stderr, "You must specify seafile data dir\n");
        usage(1);
    }

    /* Create database for mysql */
    if (use_mysql) {
        SeafDB *db_root = seaf_db_new_mysql (config.mysql_host, "root",
                                             config.mysql_root_passwd,
                                             NULL, config.mysql_socket);
        if (!db_root) {
        fprintf (stderr, "Out of memory!\n");
        return 1;
        }

        /* Create database for Seafile server. */
        snprintf (sql, sizeof(sql), "CREATE DATABASE IF NOT EXISTS `%s`",
              config.mysql_db_name);
        ret = seaf_db_query (db_root, sql);
        if (ret < 0) {
            fprintf (stderr, "Failed to create database %s.\n", config.mysql_db_name);
        return 1;
        }
        
        if (verbose)
            printf ("Successfully created database:     %s\n",
                    config.mysql_db_name);
        
        /* Create database for Seahub. */
        snprintf (sql, sizeof(sql), "CREATE DATABASE IF NOT EXISTS `%s` character set utf8",
                  config.mysql_seahub_db_name);
        ret = seaf_db_query (db_root, sql);
        if (ret < 0) {
            fprintf (stderr, "Failed to create database %s.\n",
                     config.mysql_seahub_db_name);
            return 1;
        }

        if (verbose)
            printf ("Successfully created database:     %s\n",
                    config.mysql_seahub_db_name);
    }
        
    /* Generate config file. */
    GKeyFile *key_file = g_key_file_new ();

    g_key_file_set_string (key_file, "database", "type",
                           use_mysql ? "mysql" : "sqlite");
    if (use_mysql) {
        g_key_file_set_string (key_file, "database", "host", config.mysql_host);
        g_key_file_set_string (key_file, "database", "user", "root");
        g_key_file_set_string (key_file, "database", "password", config.mysql_root_passwd);
        g_key_file_set_string (key_file, "database", "db_name", config.mysql_db_name);
        if (config.mysql_socket)
            g_key_file_set_string (key_file, "database", "unix_socket", config.mysql_socket);
    }

    g_key_file_set_string (key_file, "network", "port", config.port);
    if (config.httpserver_port) {
        g_key_file_set_string (key_file, "httpserver", "port", config.httpserver_port);
    } else {
        /* httpserver port defaults to 8082 */
        g_key_file_set_string (key_file, "httpserver", "port", "8082");
    }

    struct stat st;
    if (lstat (config.seafile_dir, &st) < 0) {
        if (mkdir (config.seafile_dir, 0777) < 0) {
            fprintf (stderr, "Directory %s cannot be created.\n", config.seafile_dir);
            return 1;
        }
    }

    char *seafile_conf = g_build_filename (config.seafile_dir, "seafile.conf", NULL);

    if (verbose)
        printf ("Generating config files:           %s\n", seafile_conf);

    if (save_config_file (key_file, seafile_conf) < 0)
        return 1;

    printf ("Done.\n");

    return 0;
}
예제 #5
0
void
remmina_pref_save (void)
{
    GKeyFile *gkeyfile;
    gchar *content;
    gsize length;

    gkeyfile = g_key_file_new ();

    g_key_file_load_from_file (gkeyfile, remmina_pref_file, G_KEY_FILE_NONE, NULL);

    g_key_file_set_boolean (gkeyfile, "remmina_pref", "save_view_mode", remmina_pref.save_view_mode);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "save_when_connect", remmina_pref.save_when_connect);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "invisible_toolbar", remmina_pref.invisible_toolbar);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "always_show_tab", remmina_pref.always_show_tab);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "hide_connection_toolbar", remmina_pref.hide_connection_toolbar);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "default_action", remmina_pref.default_action);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "scale_quality", remmina_pref.scale_quality);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "hide_toolbar", remmina_pref.hide_toolbar);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "hide_statusbar", remmina_pref.hide_statusbar);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "show_quick_search", remmina_pref.show_quick_search);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "small_toolbutton", remmina_pref.small_toolbutton);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "view_file_mode", remmina_pref.view_file_mode);
    g_key_file_set_string (gkeyfile, "remmina_pref", "resolutions", remmina_pref.resolutions);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "main_width", remmina_pref.main_width);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "main_height", remmina_pref.main_height);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "main_maximize", remmina_pref.main_maximize);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "main_sort_column_id", remmina_pref.main_sort_column_id);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "main_sort_order", remmina_pref.main_sort_order);
    g_key_file_set_string (gkeyfile, "remmina_pref", "expanded_group", remmina_pref.expanded_group);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "toolbar_pin_down", remmina_pref.toolbar_pin_down);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "sshtunnel_port", remmina_pref.sshtunnel_port);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "applet_new_ontop", remmina_pref.applet_new_ontop);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "applet_hide_count", remmina_pref.applet_hide_count);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "applet_enable_avahi", remmina_pref.applet_enable_avahi);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "disable_tray_icon", remmina_pref.disable_tray_icon);
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "minimize_to_tray", remmina_pref.minimize_to_tray);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "recent_maximum", remmina_pref.recent_maximum);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "default_mode", remmina_pref.default_mode);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "tab_mode", remmina_pref.tab_mode);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "auto_scroll_step", remmina_pref.auto_scroll_step);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "hostkey", remmina_pref.hostkey);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "shortcutkey_fullscreen", remmina_pref.shortcutkey_fullscreen);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "shortcutkey_autofit", remmina_pref.shortcutkey_autofit);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "shortcutkey_nexttab", remmina_pref.shortcutkey_nexttab);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "shortcutkey_prevtab", remmina_pref.shortcutkey_prevtab);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "shortcutkey_scale", remmina_pref.shortcutkey_scale);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "shortcutkey_grab", remmina_pref.shortcutkey_grab);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "shortcutkey_minimize", remmina_pref.shortcutkey_minimize);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "shortcutkey_disconnect", remmina_pref.shortcutkey_disconnect);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "shortcutkey_toolbar", remmina_pref.shortcutkey_toolbar);
    g_key_file_set_string (gkeyfile, "remmina_pref", "vte_font", remmina_pref.vte_font ? remmina_pref.vte_font : "");
    g_key_file_set_boolean (gkeyfile, "remmina_pref", "vte_allow_bold_text", remmina_pref.vte_allow_bold_text);
    g_key_file_set_integer (gkeyfile, "remmina_pref", "vte_lines", remmina_pref.vte_lines);

    content = g_key_file_to_data (gkeyfile, &length, NULL);
    g_file_set_contents (remmina_pref_file, content, length, NULL);

    g_key_file_free (gkeyfile);
    g_free (content);
}
예제 #6
0
void load_option_rcfile(const gchar *rcname)
{
  SYLPF_OPTION.rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, rcname, NULL);
  SYLPF_OPTION.rcfile = g_key_file_new();
  g_key_file_load_from_file(SYLPF_OPTION.rcfile, SYLPF_OPTION.rcpath, G_KEY_FILE_KEEP_COMMENTS, NULL);
}
예제 #7
0
static GKeyFile *
get_config_from_opts (FlatpakDir *dir, const char *remote_name, gboolean *changed)
{
  OstreeRepo *repo;
  GKeyFile *config;
  g_autofree char *group = g_strdup_printf ("remote \"%s\"", remote_name);

  repo = flatpak_dir_get_repo (dir);
  if (repo == NULL)
    config = g_key_file_new ();
  else
    config = ostree_repo_copy_config (repo);

  if (opt_no_gpg_verify)
    {
      g_key_file_set_boolean (config, group, "gpg-verify", FALSE);
      g_key_file_set_boolean (config, group, "gpg-verify-summary", FALSE);
      *changed = TRUE;
    }

  if (opt_do_gpg_verify)
    {
      g_key_file_set_boolean (config, group, "gpg-verify", TRUE);
      g_key_file_set_boolean (config, group, "gpg-verify-summary", TRUE);
      *changed = TRUE;
    }

  if (opt_url)
    {
      if (g_str_has_prefix (opt_url, "metalink="))
        g_key_file_set_string (config, group, "metalink", opt_url + strlen ("metalink="));
      else
        g_key_file_set_string (config, group, "url", opt_url);
      *changed = TRUE;
    }

  if (opt_collection_id)
    {
      g_key_file_set_string (config, group, "collection-id", opt_collection_id);
      g_key_file_set_boolean (config, group, "gpg-verify-summary", FALSE);
      *changed = TRUE;
    }

  if (opt_title)
    {
      g_key_file_set_string (config, group, "xa.title", opt_title);
      g_key_file_set_boolean (config, group, "xa.title-is-set", TRUE);
      *changed = TRUE;
    }

  if (opt_comment)
    {
      g_key_file_set_string (config, group, "xa.comment", opt_comment);
      g_key_file_set_boolean (config, group, "xa.comment-is-set", TRUE);
      *changed = TRUE;
    }

  if (opt_description)
    {
      g_key_file_set_string (config, group, "xa.description", opt_description);
      g_key_file_set_boolean (config, group, "xa.description-is-set", TRUE);
      *changed = TRUE;
    }

  if (opt_homepage)
    {
      g_key_file_set_string (config, group, "xa.homepage", opt_homepage);
      g_key_file_set_boolean (config, group, "xa.homepage-is-set", TRUE);
      *changed = TRUE;
    }

  if (opt_icon)
    {
      g_key_file_set_string (config, group, "xa.icon", opt_icon);
      g_key_file_set_boolean (config, group, "xa.icon-is-set", TRUE);
      *changed = TRUE;
    }

  if (opt_default_branch)
    {
      g_key_file_set_string (config, group, "xa.default-branch", opt_default_branch);
      g_key_file_set_boolean (config, group, "xa.default-branch-is-set", TRUE);
      *changed = TRUE;
    }

  if (opt_no_enumerate)
    {
      g_key_file_set_boolean (config, group, "xa.noenumerate", TRUE);
      *changed = TRUE;
    }

  if (opt_do_enumerate)
    {
      g_key_file_set_boolean (config, group, "xa.noenumerate", FALSE);
      *changed = TRUE;
    }

  if (opt_no_deps)
    {
      g_key_file_set_boolean (config, group, "xa.nodeps", TRUE);
      *changed = TRUE;
    }

  if (opt_do_deps)
    {
      g_key_file_set_boolean (config, group, "xa.nodeps", FALSE);
      *changed = TRUE;
    }

  if (opt_disable)
    {
      g_key_file_set_boolean (config, group, "xa.disable", TRUE);
      *changed = TRUE;
    }

  if (opt_prio != -1)
    {
      g_autofree char *prio_as_string = g_strdup_printf ("%d", opt_prio);
      g_key_file_set_string (config, group, "xa.prio", prio_as_string);
      *changed = TRUE;
    }

  if (comment)
    {
      g_key_file_set_string (config, group, "xa.comment", comment);
      g_key_file_set_boolean (config, group, "xa.comment-is-set", TRUE);
      *changed = TRUE;
    }

  if (description)
    {
      g_key_file_set_string (config, group, "xa.description", description);
      g_key_file_set_boolean (config, group, "xa.description-is-set", TRUE);
      *changed = TRUE;
    }

  if (icon)
    {
      g_key_file_set_string (config, group, "xa.icon", icon);
      g_key_file_set_boolean (config, group, "xa.icon-is-set", TRUE);
      *changed = TRUE;
    }

  if (homepage)
    {
      g_key_file_set_string (config, group, "xa.homepage", homepage);
      g_key_file_set_boolean (config, group, "xa.homepage-is-set", TRUE);
      *changed = TRUE;
    }

  return config;
}
예제 #8
0
static gboolean
on_account_handle_remove (GoaAccount            *account,
                          GDBusMethodInvocation *invocation,
                          gpointer               user_data)
{
  GoaDaemon *daemon = GOA_DAEMON (user_data);
  GKeyFile *key_file;
  gchar *path;
  gchar *group;
  gchar *data;
  gsize length;
  GError *error;

  path = NULL;
  group = NULL;
  key_file = NULL;
  data = NULL;

  /* update key-file - right now we only support removing the account
   * if the entry is in ~/.config/goa-1.0/accounts.conf
   */

  key_file = g_key_file_new ();
  path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ());

  error = NULL;
  if (!g_key_file_load_from_file (key_file,
                                  path,
                                  G_KEY_FILE_KEEP_COMMENTS,
                                  &error))
    {
      g_dbus_method_invocation_return_gerror (invocation, error);
      g_error_free (error);
      goto out;
    }

  group = g_strdup_printf ("Account %s", goa_account_get_id (account));

  error = NULL;
  if (!g_key_file_remove_group (key_file, group, &error))
    {
      g_dbus_method_invocation_return_gerror (invocation, error);
      g_error_free (error);
      goto out;
    }

  error = NULL;
  data = g_key_file_to_data (key_file,
                             &length,
                             &error);
  if (data == NULL)
    {
      g_prefix_error (&error, "Error generating key-value-file: ");
      g_dbus_method_invocation_return_gerror (invocation, error);
      goto out;
    }

  error = NULL;
  if (!g_file_set_contents (path,
                            data,
                            length,
                            &error))
    {
      g_prefix_error (&error, "Error writing key-value-file %s: ", path);
      g_dbus_method_invocation_return_gerror (invocation, error);
      goto out;
    }

  goa_daemon_reload_configuration (daemon);

  goa_account_complete_remove (account, invocation);

 out:
  g_free (data);
  if (key_file != NULL)
    g_key_file_free (key_file);
  g_free (group);
  g_free (path);
  return TRUE; /* invocation was handled */
}
예제 #9
0
파일: fu-sign.c 프로젝트: phomes/fwupd
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	FuSignPrivate *priv = NULL;
	GOptionContext *context;
	GMainLoop *loop = NULL;
	gboolean ret;
	gboolean one_shot = FALSE;
	guint retval = 1;
	_cleanup_error_free_ GError *error = NULL;
	_cleanup_free_ gchar *config_file = NULL;
	_cleanup_free_ gchar *destination = NULL;
	_cleanup_free_ gchar *key_id = NULL;
	_cleanup_free_ gchar *source = NULL;
	_cleanup_keyfile_unref_ GKeyFile *config = NULL;
	const GOptionEntry options[] = {
		{ "one-shot", '\0', 0, G_OPTION_ARG_NONE, &one_shot,
		  /* TRANSLATORS: exit after we've started up, used for user profiling */
		  _("Exit after signing queue"), NULL },
		{ "source", 's', 0, G_OPTION_ARG_FILENAME, &source,
		  /* TRANSLATORS: input location to watch  */
		  _("Source path for files"), NULL },
		{ "destination", 'd', 0, G_OPTION_ARG_FILENAME, &destination,
		  /* TRANSLATORS: output location to put files  */
		  _("Destination path for files"), NULL },
		{ "key-id", 'd', 0, G_OPTION_ARG_STRING, &key_id,
		  /* TRANSLATORS: output location to put files  */
		  _("GPG key used to sign the firmware"), NULL },
		{ NULL}
	};

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	/* TRANSLATORS: program name */
	g_set_application_name (_("fwsignd"));
	context = g_option_context_new (NULL);
	g_option_context_add_main_entries (context, options, NULL);
	g_option_context_add_group (context, fu_debug_get_option_group ());
	/* TRANSLATORS: program summary */
	g_option_context_set_summary (context, _("Firmware signing server"));
	ret = g_option_context_parse (context, &argc, &argv, &error);
	if (!ret) {
		g_print ("failed to parse command line arguments: %s\n",
			  error->message);
		retval = EXIT_FAILURE;
		goto out;
	}

	/* fall back to keyfile */
	config = g_key_file_new ();
	config_file = g_build_filename (SYSCONFDIR, "fwsignd.conf", NULL);
	g_debug ("Loading fallback values from %s", config_file);
	if (!g_key_file_load_from_file (config, config_file,
					G_KEY_FILE_NONE, &error)) {
		g_print ("failed to load config file %s: %s\n",
			  config_file, error->message);
		retval = EXIT_FAILURE;
		goto out;
	}
	if (source == NULL)
		source = g_key_file_get_string (config, "fwupd", "SourceDirectory", NULL);
	if (destination == NULL)
		destination = g_key_file_get_string (config, "fwupd", "DestinationDirectory", NULL);
	if (key_id == NULL)
		key_id = g_key_file_get_string (config, "fwupd", "KeyID", NULL);
	if (source == NULL || destination == NULL) {
		g_print ("source and destination required\n");
		retval = EXIT_FAILURE;
		goto out;
	}
	priv = g_new0 (FuSignPrivate, 1);
	priv->source = g_strdup (source);
	priv->destination = g_strdup (destination);
	priv->key_id = g_strdup (key_id);
	priv->keyring = fu_keyring_new ();
	priv->pending_files = g_ptr_array_new_with_free_func (g_free);
	priv->set_owner = g_key_file_get_boolean (config, "fwupd", "SetDestinationOwner", NULL);
	if (priv->key_id != NULL &&
	    !fu_keyring_set_signing_key (priv->keyring, priv->key_id, &error)) {
		g_print ("valid GPG key required: %s\n", error->message);
		retval = EXIT_FAILURE;
		goto out;
	}

	/* process */
	g_debug ("clearing queue");
	if (!fu_sign_coldplug (priv, &error)) {
		g_print ("failed to clear queue: %s\n", error->message);
		retval = EXIT_FAILURE;
		goto out;
	}
	if (!one_shot) {
		_cleanup_object_unref_ GFileMonitor *monitor = NULL;
		_cleanup_object_unref_ GFile *src = NULL;
		g_debug ("waiting for files to appear in %s", source);
		src = g_file_new_for_path (source);
		monitor = g_file_monitor (src, G_FILE_MONITOR_NONE, NULL, &error);
		if (monitor == NULL) {
			g_print ("failed to watch %s: %s\n", source, error->message);
			retval = EXIT_FAILURE;
			goto out;
		}
		g_signal_connect (monitor, "changed",
				  G_CALLBACK (fu_sign_monitor_changed_cb), priv);
		loop = g_main_loop_new (NULL, FALSE);
		g_main_loop_run (loop);
	}

	/* success */
	retval = 0;
out:
	if (priv != NULL) {
		g_object_unref (priv->keyring);
		g_ptr_array_unref (priv->pending_files);
		g_free (priv->source);
		g_free (priv->destination);
		g_free (priv->key_id);
		g_free (priv);
	}
	g_option_context_free (context);
	if (loop != NULL)
		g_main_loop_unref (loop);
	return retval;
}
예제 #10
0
/* Called by Geany to initialize the plugin */
void
plugin_init(G_GNUC_UNUSED GeanyData *data)
{
	GtkWidget *menu_lipsum = NULL;
	GKeyFile *config = g_key_file_new();
	gchar *config_file = NULL;
	gchar *config_file_old = NULL;
	gchar *config_dir = NULL;
	gchar *config_dir_old = NULL;
	GeanyKeyGroup *key_group;


	config_file = g_strconcat(geany->app->configdir,
		G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S,
		"geanylipsum", G_DIR_SEPARATOR_S, "lipsum.conf", NULL);

	#ifndef G_OS_WIN32
	/* We try only to move if we are on not Windows platform */
	config_dir_old = g_build_filename(geany->app->configdir,
		"plugins", "geanylipsum", NULL);
	config_file_old = g_build_filename(config_dir_old,
		"lipsum.conf", NULL);
	config_dir = g_build_filename(geany->app->configdir,
		"plugins", "lipsum", NULL);
	if (g_file_test(config_file_old, G_FILE_TEST_EXISTS))
	{
		if (dialogs_show_question(
			_("Renamed plugin detected!\n"
			  "\n"
			  "As you may have already noticed, GeanyLipsum has been "
			  "renamed to just Lipsum. \n"
			  "Geany is able to migrate your old plugin configuration by "
			  "moving the old configuration file to new location.\n"
			  "Warning: This will not include your keybindings.\n"
			  "Move now?")))
		{
			if (g_rename(config_dir_old, config_dir) == 0)
			{
				dialogs_show_msgbox(GTK_MESSAGE_INFO,
					_("Your configuration directory has been "
					  "successfully moved from \"%s\" to \"%s\"."),
					config_dir_old, config_dir);
			}
			else
			{
				/* If there was an error on migrating we need
				 * to load from original one.
				 * When saving new configuration it will go to
				 * new folder so migration should
				 * be implicit. */
				g_free(config_file);
				config_file = g_strdup(config_file_old);
				dialogs_show_msgbox(
					GTK_MESSAGE_WARNING,
					_("Your old configuration directory \"%s\" could "
					  "not be moved to \"%s\" (%s). "
					  "Please manually move the directory to the new location."),
					config_dir_old,
					config_dir,
					g_strerror(errno));
			}
		}
	}

	g_free(config_dir_old);
	g_free(config_dir);
	g_free(config_file_old);
	#endif

	/* Initialising options from config file  if there is any*/
	g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
	lipsum = utils_get_setting_string(config, "snippets", "lipsumtext", default_loremipsum);

	g_key_file_free(config);
	g_free(config_file);

	/* Building menu entry */
	menu_lipsum = gtk_image_menu_item_new_with_mnemonic(_("_Lipsum..."));
	gtk_widget_set_tooltip_text(menu_lipsum, _("Include Pseudotext to your code"));
	gtk_widget_show(menu_lipsum);
	g_signal_connect((gpointer) menu_lipsum, "activate",
			 G_CALLBACK(lipsum_activated), NULL);
	gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), menu_lipsum);


	ui_add_document_sensitive(menu_lipsum);

	main_menu_item = menu_lipsum;

	/* init keybindings */
	key_group = plugin_set_key_group(geany_plugin, "lipsum", COUNT_KB, NULL);
	keybindings_set_item(key_group, LIPSUM_KB_INSERT, kblipsum_insert,
		0, 0, "insert_lipsum", _("Insert Lipsum text"), menu_lipsum);
}
예제 #11
0
static gboolean
on_manager_handle_add_account (GoaManager             *manager,
                               GDBusMethodInvocation  *invocation,
                               const gchar            *provider,
                               const gchar            *identity,
                               const gchar            *presentation_identity,
                               GVariant               *details,
                               gpointer                user_data)
{
  GoaDaemon *daemon = GOA_DAEMON (user_data);
  GKeyFile *key_file;
  GError *error;
  gchar *path;
  gchar *id;
  gchar *group;
  gchar *data;
  gsize length;
  gchar *object_path;
  GVariantIter iter;
  const gchar *key;
  const gchar *value;

  /* TODO: could check for @type */

  key_file = NULL;
  path = NULL;
  id = NULL;
  group = NULL;
  data = NULL;
  object_path = NULL;

  key_file = g_key_file_new ();
  path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ());
  error = NULL;
  if (!g_file_get_contents (path,
                            &data,
                            &length,
                            &error))
    {
      if (error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT)
        {
          g_error_free (error);
        }
      else
        {
          g_prefix_error (&error, "Error loading file %s: ", path);
          g_dbus_method_invocation_return_gerror (invocation, error);
          goto out;
        }
    }
  else
    {
      if (length > 0)
        {
          error = NULL;
          if (!g_key_file_load_from_data (key_file, data, length, G_KEY_FILE_KEEP_COMMENTS, &error))
            {
              g_prefix_error (&error, "Error parsing key-value-file %s: ", path);
              g_dbus_method_invocation_return_gerror (invocation, error);
              goto out;
            }
        }
    }

  id = generate_new_id (daemon);
  group = g_strdup_printf ("Account %s", id);
  g_key_file_set_string (key_file, group, "Provider", provider);
  g_key_file_set_string (key_file, group, "Identity", identity);
  g_key_file_set_string (key_file, group, "PresentationIdentity", presentation_identity);

  g_variant_iter_init (&iter, details);
  while (g_variant_iter_next (&iter, "{&s&s}", &key, &value))
    {
      g_key_file_set_string (key_file, group, key, value);
    }

  g_free (data);
  error = NULL;
  data = g_key_file_to_data (key_file,
                             &length,
                             &error);
  if (data == NULL)
    {
      g_prefix_error (&error, "Error generating key-value-file: ");
      g_dbus_method_invocation_return_gerror (invocation, error);
      goto out;
    }

  error = NULL;
  if (!g_file_set_contents (path,
                            data,
                            length,
                            &error))
    {
      g_prefix_error (&error, "Error writing key-value-file %s: ", path);
      g_dbus_method_invocation_return_gerror (invocation, error);
      goto out;
    }

  goa_daemon_reload_configuration (daemon);

  object_path = g_strdup_printf ("/org/gnome/OnlineAccounts/Accounts/%s", id);
  goa_manager_complete_add_account (manager, invocation, object_path);

 out:
  g_free (object_path);
  g_free (data);
  g_free (group);
  g_free (id);
  g_free (path);
  if (key_file != NULL)
    g_key_file_free (key_file);

  return TRUE; /* invocation was handled */
}
예제 #12
0
static gboolean
reload_database (NMSessionMonitor *self, GError **error)
{
	struct stat statbuf;
	char **groups = NULL;
	gsize len = 0, i;
	Session *s;

	free_database (self);

	errno = 0;
	if (stat (CKDB_PATH, &statbuf) != 0) {
		g_set_error (error,
		             NM_SESSION_MONITOR_ERROR,
		             errno == ENOENT ? NM_SESSION_MONITOR_ERROR_NO_DATABASE : NM_SESSION_MONITOR_ERROR_IO_ERROR,
		             "Error statting file " CKDB_PATH ": %s",
		             strerror (errno));
		goto error;
	}
	self->database_mtime = statbuf.st_mtime;

	self->database = g_key_file_new ();
	if (!g_key_file_load_from_file (self->database, CKDB_PATH, G_KEY_FILE_NONE, error))
		goto error;

	groups = g_key_file_get_groups (self->database, &len);
	if (!groups) {
		g_set_error_literal (error,
		                     NM_SESSION_MONITOR_ERROR,
		                     NM_SESSION_MONITOR_ERROR_IO_ERROR,
		                     "Could not load groups from " CKDB_PATH "");
		goto error;
	}

	for (i = 0; i < len; i++) {
		Session *found;

		if (!g_str_has_prefix (groups[i], "Session "))
			continue;

		s = session_new (self->database, groups[i], error);
		if (!s)
			goto error;

		found = g_hash_table_lookup (self->sessions_by_user, (gpointer) s->user);
		if (found) {
			session_merge (s, found);
			session_free (s);
		} else {
			/* Entirely new user */
			g_hash_table_insert (self->sessions_by_user, (gpointer) s->user, s);
			g_hash_table_insert (self->sessions_by_uid, GUINT_TO_POINTER (s->uid), s);
		}
	}

	g_strfreev (groups);
	return TRUE;

error:
	if (groups)
		g_strfreev (groups);
	free_database (self);
	return FALSE;
}
예제 #13
0
파일: main.c 프로젝트: simbits/ClaudeGlass
int main (int argc, char *argv[])
{
    GCContext    gc_context;
    GMainLoop   *mainLoop;
    GKeyFile    *keyFile;
    GThread     *displayThread;
    GThread     *inputControllerThread;
    GThread     *x11EventThread;
    int          i;

    
    GCConfig config = {
        .movie_path          = DEFAULT_MOVIE_PATH,
        .mask_path           = DEFAULT_MASK_PATH,
        .controller_path     = DEFAULT_CONTROLLER_PATH,
        .seconds_per_frame   = DEFAULT_SECONDS_PER_FRAME,
        .easing_factor       = DEFAULT_EASING_FACTOR,
        .frames_per_tick     = 0,
        .diameter_controller = 0,
        .diameter_rim        = 0,
        .ctr                 = 0,
        .fpr                 = 0,
        .number_of_frames    = 0,
        .fullscreen          = TRUE,
        .timeZone            = NULL,
    };

    Movie movie = {
        .planes             = NULL,
        .frame_offset       = 0,
        .fd_movie           = -1,
        .frame              = { .pitches = { FRAME_PITCH, 0, 0 } },
        .fd_mask            = -1,
        .mask               = { .pitches = { MASK_PITCH, 0, 0 } },
        .pre_load_surface   = VDP_INVALID_HANDLE,
        .play_direction     = DIRECTION_FORWARD,
        .ticks              = 0,
        .new_frame          = FALSE,
        .ease_to            = TRUE,
    };

    keyFile = g_key_file_new();
    if (argc > 1 && g_key_file_load_from_file(keyFile, argv[1], G_KEY_FILE_NONE, NULL)) {
        if (g_key_file_has_group(keyFile, "MAIN")) {
            if (g_key_file_has_key(keyFile, "MAIN", "utc_offset", NULL))
                config.timeZone = g_time_zone_new(g_key_file_get_string(keyFile, "MAIN", "utc_offset", NULL));
            if (g_key_file_has_key(keyFile, "MAIN", "ease_to_time", NULL))
                movie.ease_to = g_key_file_get_boolean(keyFile, "MAIN", "ease_to_time", NULL);
        }
 
        if (g_key_file_has_group(keyFile, "MOVIE")) {
           if (g_key_file_has_key(keyFile, "MOVIE", "file", NULL))
              config.movie_path = g_key_file_get_string(keyFile, "MOVIE", "file", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "mask", NULL))
              config.mask_path = g_key_file_get_string(keyFile, "MOVIE", "mask", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "seconds_per_frame", NULL))
              config.seconds_per_frame = (float)g_key_file_get_double(keyFile, "MOVIE", "seconds_per_frame", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "easing_factor", NULL))
              config.easing_factor = (float)g_key_file_get_integer(keyFile, "MOVIE", "easing_factor", NULL);
        }
        
        if (g_key_file_has_group(keyFile, "CONTROLLER")) {
           if (g_key_file_has_key(keyFile, "CONTROLLER", "path", NULL))
              config.controller_path = g_key_file_get_string(keyFile, "CONTROLLER", "path", NULL);

           if (g_key_file_has_key(keyFile, "CONTROLLER", "diameter_controller", NULL))
              config.diameter_controller = (float)g_key_file_get_double(keyFile, "CONTROLLER", "diameter_controller", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "diameter_rim", NULL))
              config.diameter_rim = (float)g_key_file_get_double(keyFile, "CONTROLLER", "diameter_rim", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "ctr", NULL))
              config.ctr = (float)g_key_file_get_double(keyFile, "CONTROLLER", "ctr", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "fpr", NULL))
              config.fpr = (float)g_key_file_get_double(keyFile, "CONTROLLER", "fpr", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "frames_per_tick", NULL))
              config.frames_per_tick = (float)g_key_file_get_double(keyFile, "CONTROLLER", "frames_per_tick", NULL);
        }

        if (g_key_file_has_group(keyFile, "SCREEN")) {
           if (g_key_file_has_key(keyFile, "SCREEN", "fullscreen", NULL))
              config.fullscreen = g_key_file_get_boolean(keyFile, "SCREEN", "fullscreen", NULL);
        }
        g_key_file_free(keyFile);
    }

    if (!config.timeZone)
        config.timeZone = g_time_zone_new_local();

    if (!config.frames_per_tick && 
        !(config.frames_per_tick = frames_per_tick(config.diameter_controller,
                                                   config.diameter_rim,
                                                   config.ctr,
                                                   config.fpr)))
    {
        g_warning("No valid tick settings, using default frames per tick: %f", DEFAULT_FRAMES_PER_TICK);
        config.frames_per_tick = DEFAULT_FRAMES_PER_TICK;
    }

    config.movie_size = get_file_size(config.movie_path);
    config.number_of_frames = config.movie_size / FRAME_SIZE;
    
    mainLoop = g_main_loop_new(NULL, FALSE);

    gc_context.g_main_loop        = mainLoop;
    gc_context.g_main_context     = g_main_loop_get_context(mainLoop);
    gc_context.window_size.width  = MOVIE_WIDTH;
    gc_context.window_size.height = MOVIE_HEIGHT;
    gc_context.exit               = FALSE;
    gc_context.movie_context      = &movie;
    gc_context.config             = &config;


    g_message("movie file: %s",                           config.movie_path);
    g_message("movie size: %lu",                          config.movie_size);
    g_message("movie frames: %lu",                        config.number_of_frames);
    g_message("movie mask file: %s",                      config.mask_path);
    g_message("frames per minute: %f",                    get_frames_per_minute(&gc_context));
    g_message("frames per day:    %lu",                   get_frames_per_day(&gc_context));
    g_message("frames per tick:   %f",                    config.frames_per_tick);
    g_message("number of days:    %d",                    get_number_of_days(&gc_context));
    g_message("current day:       %d",                    get_current_day(&gc_context));

    if (movie.ease_to) {
        movie.ease_to_frame = get_frame_offset(&gc_context, GO_TO_RAND_DAY, DAY_OFFSET_NOW);
        g_message("ease to frame:    %lu", movie.ease_to_frame);
    }

    x11_init(&gc_context);
    vdpau_init(&gc_context);

    load_movie(&gc_context);
    load_mask(&gc_context);

    g_cond_init(&movie.tick_cond);
    g_mutex_init(&movie.tick_lock);
    g_mutex_init(&movie.frame_lock);

    displayThread = g_thread_new("Display thread", display_thread, (gpointer)&gc_context);
    inputControllerThread = g_thread_new("Input controller thread", input_controller_thread, (gpointer)&gc_context);
    x11EventThread = g_thread_new("X11 Event thread", x11_event_thread, (gpointer)&gc_context);

    g_main_loop_run(mainLoop);

    gc_context.exit = TRUE;
    g_thread_join(displayThread); 
    g_thread_join(inputControllerThread); 
    g_thread_join(x11EventThread); 
    g_cond_clear(&movie.tick_cond);
    g_mutex_clear(&movie.tick_lock);
    g_mutex_clear(&movie.frame_lock);
    g_time_zone_unref(config.timeZone);
}
예제 #14
0
NemoAction *
nemo_action_new (const gchar *name, 
                 const gchar *path)
{
    GKeyFile *key_file = g_key_file_new();

    g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, NULL);

    if (!g_key_file_has_group (key_file, ACTION_FILE_GROUP)) {
        g_key_file_free (key_file);
        return NULL;
    }

    if (g_key_file_has_key (key_file, ACTION_FILE_GROUP, KEY_ACTIVE, NULL)) {
        if (!g_key_file_get_boolean (key_file, ACTION_FILE_GROUP, KEY_ACTIVE, NULL)) {
            g_key_file_free (key_file);
            return NULL;
        }
    }

    gchar *orig_label = g_key_file_get_locale_string (key_file,
                                                      ACTION_FILE_GROUP,
                                                      KEY_NAME,
                                                      NULL,
                                                      NULL);

    gchar *exec_raw = g_key_file_get_string (key_file,
                                             ACTION_FILE_GROUP,
                                             KEY_EXEC,
                                             NULL);

    gchar **ext = g_key_file_get_string_list (key_file,
                                              ACTION_FILE_GROUP,
                                              KEY_EXTENSIONS,
                                              NULL,
                                              NULL);

    gchar **mimes = g_key_file_get_string_list (key_file,
                                                ACTION_FILE_GROUP,
                                                KEY_MIME_TYPES,
                                                NULL,
                                                NULL);

    gchar **deps  = g_key_file_get_string_list (key_file,
                                                ACTION_FILE_GROUP,
                                                KEY_DEPENDENCIES,
                                                NULL,
                                                NULL);

    gchar *selection_string = g_key_file_get_string (key_file,
                                                     ACTION_FILE_GROUP,
                                                     KEY_SELECTION,
                                                     NULL);

    gboolean finish = TRUE;

    if (deps != NULL) {
        gint i = 0;
        for (i = 0; i < g_strv_length (deps); i++) {
            if (g_path_is_absolute (deps[i])) {
                GFile *f = g_file_new_for_path (deps[i]);
                if (!g_file_query_exists (f, NULL)) {
                    finish = FALSE;
                    DEBUG ("Missing action dependency: %s", deps[i]);
                }
                g_object_unref (f);
            } else {
                gchar *p = g_find_program_in_path (deps[i]);
                if (p == NULL) {
                    finish = FALSE;
                    DEBUG ("Missing action dependency: %s", deps[i]);
                    g_free (p);
                    break;
                }
                g_free (p);
            }
        }
    }

    if (orig_label == NULL || exec_raw == NULL || (ext == NULL && mimes == NULL) || selection_string == NULL) {
        g_printerr ("An action definition requires, at minimum, "
                    "a Label field, an Exec field, a Selection field, and an either an Extensions or Mimetypes field.\n"
                    "Check the %s file for missing fields.\n", path);
        finish = FALSE;
    }

    g_free (orig_label);
    g_free (exec_raw);
    g_free (selection_string);
    g_strfreev (ext);
    g_strfreev (mimes);
    g_strfreev (deps);
    g_key_file_free (key_file);

    return finish ? g_object_new (NEMO_TYPE_ACTION,
                                  "name", name,
                                  "key-file-path", path,
                                  NULL): NULL;
}
예제 #15
0
/**
 * gs_plugin_app_install:
 */
gboolean
gs_plugin_app_install (GsPlugin *plugin, GsApp *app,
		       GCancellable *cancellable, GError **error)
{
	AsIcon *icon;
	gboolean ret = TRUE;
	gsize kf_length;
	g_autoptr(GError) error_local = NULL;
	g_autofree gchar *app_desktop = NULL;
	g_autofree gchar *epi_desktop = NULL;
	g_autofree gchar *epi_dir = NULL;
	g_autofree gchar *epi_icon = NULL;
	g_autofree gchar *exec = NULL;
	g_autofree gchar *hash = NULL;
	g_autofree gchar *id_nonfull = NULL;
	g_autofree gchar *kf_data = NULL;
	g_autofree gchar *wmclass = NULL;
	g_autoptr(GKeyFile) kf = NULL;
	g_autoptr(GFile) symlink_desktop = NULL;
	g_autoptr(GFile) symlink_icon = NULL;

	/* only process web apps */
	if (gs_app_get_id_kind (app) != AS_ID_KIND_WEB_APP)
		return TRUE;

	/* create the correct directory */
	id_nonfull = _gs_app_get_id_nonfull (app);
	hash = g_compute_checksum_for_string (G_CHECKSUM_SHA1, gs_app_get_name (app), -1);
	epi_dir = g_strdup_printf ("%s/epiphany/app-%s-%s",
				   g_get_user_config_dir (),
				   id_nonfull,
				   hash);
	g_mkdir_with_parents (epi_dir, 0755);

	/* symlink icon */
	epi_icon = g_build_filename (epi_dir, "app-icon.png", NULL);
	symlink_icon = g_file_new_for_path (epi_icon);
	icon = gs_app_get_icon (app);
	ret = g_file_make_symbolic_link (symlink_icon,
					 as_icon_get_filename (icon),
					 NULL,
					 &error_local);
	if (!ret) {
		if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
			g_debug ("ignoring icon symlink failure: %s",
				 error_local->message);
		} else {
			g_set_error (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_FAILED,
				     "Can't symlink icon: %s",
				     error_local->message);
			return FALSE;
		}
	}

	/* add desktop file */
	wmclass = g_strdup_printf ("%s-%s", id_nonfull, hash);
	kf = g_key_file_new ();
	g_key_file_set_string (kf,
			       G_KEY_FILE_DESKTOP_GROUP,
			       G_KEY_FILE_DESKTOP_KEY_NAME,
			       gs_app_get_name (app));
	g_key_file_set_string (kf,
			       G_KEY_FILE_DESKTOP_GROUP,
			       G_KEY_FILE_DESKTOP_KEY_COMMENT,
			       gs_app_get_summary (app));
	exec = g_strdup_printf ("epiphany --application-mode --profile=\"%s\" %s",
				epi_dir,
				gs_app_get_url (app, AS_URL_KIND_HOMEPAGE));
	g_key_file_set_string (kf,
			       G_KEY_FILE_DESKTOP_GROUP,
			       G_KEY_FILE_DESKTOP_KEY_EXEC,
			       exec);
	g_key_file_set_boolean (kf,
				G_KEY_FILE_DESKTOP_GROUP,
				G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY,
				TRUE);
	g_key_file_set_boolean (kf,
				G_KEY_FILE_DESKTOP_GROUP,
				G_KEY_FILE_DESKTOP_KEY_TERMINAL,
				FALSE);
	g_key_file_set_boolean (kf,
				G_KEY_FILE_DESKTOP_GROUP,
				G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,
				FALSE);
	g_key_file_set_string (kf,
			       G_KEY_FILE_DESKTOP_GROUP,
			       G_KEY_FILE_DESKTOP_KEY_TYPE,
			       G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
	g_key_file_set_string (kf,
			       G_KEY_FILE_DESKTOP_GROUP,
			       G_KEY_FILE_DESKTOP_KEY_ICON,
			       epi_icon);
	g_key_file_set_string (kf,
			       G_KEY_FILE_DESKTOP_GROUP,
			       G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS,
			       wmclass);

	/* save keyfile */
	kf_data = g_key_file_to_data (kf, &kf_length, error);
	if (kf_data == NULL)
		return FALSE;
	epi_desktop = g_strdup_printf ("%s/%s.desktop", epi_dir, wmclass);
	if (!g_file_set_contents (epi_desktop, kf_data, kf_length, error))
		return FALSE;

	/* symlink it to somewhere the shell will notice */
	app_desktop = g_build_filename (g_get_user_data_dir (),
	                                "applications",
	                                gs_app_get_id (app),
	                                NULL);
	symlink_desktop = g_file_new_for_path (app_desktop);
	ret = g_file_make_symbolic_link (symlink_desktop,
					 epi_desktop,
					 NULL,
					 error);
	if (!ret)
		return FALSE;

	/* update state */
	gs_app_set_state (app, AS_APP_STATE_INSTALLING);
	gs_app_set_state (app, AS_APP_STATE_INSTALLED);
	return TRUE;
}
예제 #16
0
static gboolean
get_common_rdf_types (void)
{
	const gchar *extractors_dir, *name;
	GList *files = NULL, *l;
	GError *error = NULL;
	GDir *dir;

	if (common_rdf_types) {
		return TRUE;
	}

	extractors_dir = g_getenv ("TRACKER_EXTRACTOR_RULES_DIR");
	if (G_LIKELY (extractors_dir == NULL)) {
		extractors_dir = TRACKER_EXTRACTOR_RULES_DIR;
	}

	dir = g_dir_open (extractors_dir, 0, &error);

	if (!dir) {
		g_error ("Error opening extractor rules directory: %s", error->message);
		g_error_free (error);
		return FALSE;
	}

	common_rdf_types = g_hash_table_new_full (g_str_hash,
	                                          g_str_equal,
	                                          g_free,
	                                          NULL);

	while ((name = g_dir_read_name (dir)) != NULL) {
		files = g_list_insert_sorted (files, (gpointer) name, (GCompareFunc) g_strcmp0);
	}

	for (l = files; l; l = l->next) {
		GKeyFile *key_file;
		const gchar *name;
		gchar *path;

		name = l->data;

		if (!g_str_has_suffix (l->data, ".rule")) {
			continue;
		}

		path = g_build_filename (extractors_dir, name, NULL);
		key_file = g_key_file_new ();

		g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error);

		if (G_UNLIKELY (error)) {
			g_clear_error (&error);
		} else {
			gchar **rdf_types;
			gsize n_rdf_types;

			rdf_types = g_key_file_get_string_list (key_file, "ExtractorRule", "FallbackRdfTypes", &n_rdf_types, &error);

			if (G_UNLIKELY (error)) {
				g_clear_error (&error);
			} else if (rdf_types != NULL) {
				gint i;

				for (i = 0; i < n_rdf_types; i++) {
					const gchar *rdf_type = rdf_types[i];

					g_hash_table_insert (common_rdf_types, g_strdup (rdf_type), GINT_TO_POINTER(TRUE));
				}
			}

			g_strfreev (rdf_types);
		}

		g_key_file_free (key_file);
		g_free (path);
	}

	g_list_free (files);
	g_dir_close (dir);

	/* Make sure some additional RDF types are shown which are not
	 * fall backs.
	 */
	g_hash_table_insert (common_rdf_types, g_strdup ("rdfs:Resource"), GINT_TO_POINTER(TRUE));
	g_hash_table_insert (common_rdf_types, g_strdup ("rdfs:Class"), GINT_TO_POINTER(TRUE));
	g_hash_table_insert (common_rdf_types, g_strdup ("nfo:FileDataObject"), GINT_TO_POINTER(TRUE));
	g_hash_table_insert (common_rdf_types, g_strdup ("nfo:Folder"), GINT_TO_POINTER(TRUE));
	g_hash_table_insert (common_rdf_types, g_strdup ("nfo:Executable"), GINT_TO_POINTER(TRUE));
	g_hash_table_insert (common_rdf_types, g_strdup ("nco:Contact"), GINT_TO_POINTER(TRUE));
	g_hash_table_insert (common_rdf_types, g_strdup ("nao:Tag"), GINT_TO_POINTER(TRUE));
	g_hash_table_insert (common_rdf_types, g_strdup ("tracker:Volume"), GINT_TO_POINTER(TRUE));

	return TRUE;
}
예제 #17
0
static gboolean
dlg_add_folder_load_options (DialogData *data,
			     const char *name)
{
	GFile     *options_dir;
	GFile     *options_file;
	char      *file_path;
	GKeyFile  *key_file;
	GError    *error = NULL;
	char      *base_dir = NULL;
	char      *filename = NULL;
	char      *include_files = NULL;
	char      *exclude_files = NULL;
	char      *exclude_folders = NULL;
	gboolean   update;
	gboolean   recursive;
	gboolean   no_symlinks;

	options_dir = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, TRUE);
	options_file = g_file_get_child (options_dir, name);
	file_path = g_file_get_path (options_file);
	key_file = g_key_file_new ();
	if (! g_key_file_load_from_file (key_file, file_path, G_KEY_FILE_KEEP_COMMENTS, &error)) {
		if (error->code != G_IO_ERROR_NOT_FOUND)
			g_warning ("Could not load options file: %s\n", error->message);
		g_clear_error (&error);
		g_object_unref (options_file);
		g_object_unref (options_dir);
		g_key_file_free (key_file);
		return FALSE;
	}

	base_dir = g_key_file_get_string (key_file, "Options", "base_dir", NULL);
	filename = g_key_file_get_string (key_file, "Options", "filename", NULL);
	include_files = g_key_file_get_string (key_file, "Options", "include_files", NULL);
	exclude_files = g_key_file_get_string (key_file, "Options", "exclude_files", NULL);
	exclude_folders = g_key_file_get_string (key_file, "Options", "exclude_folders", NULL);
	update = g_key_file_get_boolean (key_file, "Options", "update", NULL);
	recursive = g_key_file_get_boolean (key_file, "Options", "recursive", NULL);
	no_symlinks = g_key_file_get_boolean (key_file, "Options", "no_symlinks", NULL);

	sync_widgets_with_options (data,
			   	   base_dir,
			   	   filename,
			   	   include_files,
			   	   exclude_files,
			   	   exclude_folders,
			   	   update,
			   	   recursive,
			   	   no_symlinks);

	dlg_add_folder_save_last_used_options (data, file_path);

	g_free (base_dir);
	g_free (filename);
	g_free (include_files);
	g_free (exclude_files);
	g_free (exclude_folders);
	g_key_file_free (key_file);
	g_free (file_path);
	g_object_unref (options_file);
	g_object_unref (options_dir);

	return TRUE;
}
예제 #18
0
void
VMTools_ConfigLogging(const gchar *defaultDomain,
                      GKeyFile *cfg,
                      gboolean force,
                      gboolean reset)
{
   gboolean allocDict = (cfg == NULL);
   gchar **list;
   gchar **curr;
   GPtrArray *oldDomains = NULL;
   LogHandler *oldDefault = NULL;

   g_return_if_fail(defaultDomain != NULL);

   if (allocDict) {
      cfg = g_key_file_new();
   }

   /*
    * If not resetting the logging system, keep the old domains around. After
    * we're done loading the new configuration, we'll go through the old domains
    * and restore any data that needs restoring, and clean up anything else.
    */
   VMToolsResetLogging(reset);
   if (!reset) {
      oldDefault = gDefaultData;
      oldDomains = gDomains;
      gDomains = NULL;
      gDefaultData = NULL;
   }

   gLogDomain = g_strdup(defaultDomain);
   gErrorData = VMToolsGetLogHandler(SAFE_HANDLER,
                                     gLogDomain,
                                     G_LOG_LEVEL_MASK,
                                     cfg);

   /*
    * Configure the default domain first. See function documentation for
    * VMToolsConfigLogDomain() for the reason.
    */
   VMToolsConfigLogDomain(gLogDomain, cfg, oldDefault, oldDomains);

   list = g_key_file_get_keys(cfg, LOGGING_GROUP, NULL, NULL);

   for (curr = list; curr != NULL && *curr != NULL; curr++) {
      gchar *domain = *curr;

      /* Check whether it's a domain "declaration". */
      if (!g_str_has_suffix(domain, ".level")) {
         continue;
      }

      /* Trims ".level" from the key to get the domain name. */
      domain[strlen(domain) - 6] = '\0';

      /* Skip the default domain. */
      if (strcmp(domain, gLogDomain) == 0) {
         continue;
      }

      VMToolsConfigLogDomain(domain, cfg, oldDefault, oldDomains);
   }

   g_strfreev(list);

   gLogEnabled = g_key_file_get_boolean(cfg, LOGGING_GROUP, "log", NULL);
   if (g_key_file_has_key(cfg, LOGGING_GROUP, "enableCoreDump", NULL)) {
      gEnableCoreDump = g_key_file_get_boolean(cfg, LOGGING_GROUP,
                                               "enableCoreDump", NULL);
   }

   /* If needed, restore the old configuration. */
   if (!reset) {
      if (oldDomains != NULL) {
         g_ptr_array_free(oldDomains, TRUE);
      }
   }

   /*
    * If core dumps are enabled (default: TRUE), then set up the exception
    * filter on Win32. On POSIX systems, try to modify the resource limit
    * to allow core dumps, but don't complain if it fails. Core dumps may
    * still fail, e.g., if the current directory is not writable by the
    * user running the process.
    *
    * On POSIX systems, if the process is itself requesting a core dump (e.g.,
    * by calling Panic() or g_error()), the core dump routine will try to find
    * a location where it can successfully create the core file. Applications
    * can try to set up core dump filters (e.g., a signal handler for SIGSEGV)
    * that can then call any of the core dumping functions handled by this
    * library.
    *
    * On POSIX systems, the maximum size of a core dump can be controlled by
    * the "maxCoreSize" config option, where "0" means "no limit". By default,
    * it's set to 5MB.
    */
   if (gEnableCoreDump) {
      GError *err = NULL;
#if defined(_WIN32)
      if (g_key_file_has_key(cfg, LOGGING_GROUP, "coreDumpFlags", NULL)) {
         guint coreDumpFlags;
         coreDumpFlags = g_key_file_get_integer(cfg, LOGGING_GROUP, "coreDumpFlags", &err);
         if (err != NULL) {
            coreDumpFlags = 0;
            g_clear_error(&err);
         }
         /*
          * For flag values and information on their meanings see:
          * http://msdn.microsoft.com/en-us/library/windows/desktop/ms680519(v=vs.85).aspx
          */
         coreDumpFlags &= MiniDumpValidTypeFlags;
         g_message("Core dump flags set to %u", coreDumpFlags);
         Panic_SetCoreDumpFlags(coreDumpFlags);
      }
      CoreDump_SetUnhandledExceptionFilter();
#else
      struct rlimit limit = { 0, 0 };

      getrlimit(RLIMIT_CORE, &limit);
      if (limit.rlim_max != 0) {
         limit.rlim_cur = (rlim_t) g_key_file_get_integer(cfg,
                                                          LOGGING_GROUP,
                                                          "maxCoreSize",
                                                          &err);
         if (err != NULL) {
            limit.rlim_cur = 5 * 1024 * 1024;
            g_clear_error(&err);
         } else if (limit.rlim_cur == 0) {
            limit.rlim_cur = RLIM_INFINITY;
         }

         limit.rlim_cur = MAX(limit.rlim_cur, limit.rlim_max);
         if (setrlimit(RLIMIT_CORE, &limit) == -1) {
            g_message("Failed to set core dump size limit, error %d (%s)\n",
                      errno, g_strerror(errno));
         } else {
            g_message("Core dump limit set to %d", (int) limit.rlim_cur);
         }
      }
#endif
   }

   gLogEnabled |= force;
   gLogInitialized = TRUE;

   if (allocDict) {
      g_key_file_free(cfg);
   }
}
예제 #19
0
static void
load_options (const char *filename,
              GBytes    **gpg_data)
{
  g_autoptr(GError) error = NULL;
  g_autoptr(GKeyFile) keyfile = g_key_file_new ();
  char *str;
  gboolean nodeps;
  g_autoptr(GBytes) bytes = NULL;
  g_autofree char *version = NULL;

  if (g_str_has_prefix (filename, "http:") ||
      g_str_has_prefix (filename, "https:"))
    {
      const char *options_data;
      gsize options_size;
      g_autoptr(SoupSession) soup_session = NULL;

      soup_session = flatpak_create_soup_session (PACKAGE_STRING);
      bytes = flatpak_load_http_uri (soup_session, filename, 0, NULL, NULL, NULL, &error);

      if (bytes == NULL)
        {
          g_printerr (_("Can't load uri %s: %s\n"), filename, error->message);
          exit (1);
        }

      options_data = g_bytes_get_data (bytes, &options_size);
      if (!g_key_file_load_from_data (keyfile, options_data, options_size, 0, &error))
        {
          g_printerr (_("Can't load uri %s: %s\n"), filename, error->message);
          exit (1);
        }
    }
  else
    {
      if (!g_key_file_load_from_file (keyfile, filename, 0, &error))
        {
          g_printerr (_("Can't load file %s: %s\n"), filename, error->message);
          exit (1);
        }
    }


  if (!g_key_file_has_group (keyfile, FLATPAK_REPO_GROUP))
    {
      g_printerr (_("Invalid file format"));
      exit (1);
    }

  version = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
                                   FLATPAK_REPO_VERSION_KEY, NULL);
  if (version != NULL && strcmp (version, "1") != 0)
    {
      g_printerr (_("Invalid version %s, only 1 supported"), version);
      exit (1);
    }

  str = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
                               FLATPAK_REPO_URL_KEY, NULL);
  if (str != NULL)
    opt_url = str;

  str = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP, FLATPAK_REPO_DEPLOY_COLLECTION_ID_KEY, NULL);
  if (str != NULL && *str != '\0')
    opt_collection_id = str;
  else
    {
      str = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP, FLATPAK_REPO_COLLECTION_ID_KEY, NULL);
      if (str != NULL && *str != '\0')
        opt_collection_id = str;
    }

  str = g_key_file_get_locale_string (keyfile, FLATPAK_REPO_GROUP,
                                      FLATPAK_REPO_TITLE_KEY, NULL, NULL);
  if (str != NULL)
    opt_title = str;

  str = g_key_file_get_locale_string (keyfile, FLATPAK_REPO_GROUP,
                                      FLATPAK_REPO_DEFAULT_BRANCH_KEY, NULL, NULL);
  if (str != NULL)
    opt_default_branch = str;

  nodeps = g_key_file_get_boolean (keyfile, FLATPAK_REPO_GROUP,
                                   FLATPAK_REPO_NODEPS_KEY, NULL);
  if (nodeps)
    {
      opt_no_deps = TRUE;
      opt_do_deps = FALSE;
    }

  str = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
                               FLATPAK_REPO_GPGKEY_KEY, NULL);
  if (str != NULL)
    {
      guchar *decoded;
      gsize decoded_len;

      str = g_strstrip (str);
      decoded = g_base64_decode (str, &decoded_len);
      if (decoded_len < 10) /* Check some minimal size so we don't get crap */
        {
          g_printerr (_("Invalid gpg key"));
          exit (1);
        }

      *gpg_data = g_bytes_new_take (decoded, decoded_len);
      if (!opt_no_gpg_verify)
        opt_do_gpg_verify = TRUE;
    }

  comment = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
                                   FLATPAK_REPO_COMMENT_KEY, NULL);

  description = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
                                       FLATPAK_REPO_DESCRIPTION_KEY, NULL);

  icon = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
                                FLATPAK_REPO_ICON_KEY, NULL);

  homepage  = g_key_file_get_string (keyfile, FLATPAK_REPO_GROUP,
                                     FLATPAK_REPO_HOMEPAGE_KEY, NULL);
}
예제 #20
0
/**
 * fwupd_remote_load_from_filename:
 * @self: A #FwupdRemote
 * @filename: A filename
 * @cancellable: the #GCancellable, or %NULL
 * @error: the #GError, or %NULL
 *
 * Sets up the remote ready for use. Most other methods call this
 * for you, and do you only need to call this if you are just watching
 * the self.
 *
 * Returns: %TRUE for success
 *
 * Since: 0.9.3
 **/
gboolean
fwupd_remote_load_from_filename (FwupdRemote *self,
				 const gchar *filename,
				 GCancellable *cancellable,
				 GError **error)
{
	FwupdRemotePrivate *priv = GET_PRIVATE (self);
	const gchar *group = "fwupd Remote";
	g_autofree gchar *firmware_base_uri = NULL;
	g_autofree gchar *id = NULL;
	g_autofree gchar *keyring_kind = NULL;
	g_autofree gchar *metadata_uri = NULL;
	g_autofree gchar *order_after = NULL;
	g_autofree gchar *order_before = NULL;
	g_autofree gchar *report_uri = NULL;
	g_autoptr(GKeyFile) kf = NULL;

	g_return_val_if_fail (FWUPD_IS_REMOTE (self), FALSE);
	g_return_val_if_fail (filename != NULL, FALSE);
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	/* set ID */
	id = g_path_get_basename (filename);
	fwupd_remote_set_id (self, id);

	/* load file */
	kf = g_key_file_new ();
	if (!g_key_file_load_from_file (kf, filename, G_KEY_FILE_NONE, error))
		return FALSE;

	/* get verification type, falling back to GPG */
	keyring_kind = g_key_file_get_string (kf, group, "Keyring", NULL);
	if (keyring_kind == NULL) {
		priv->keyring_kind = FWUPD_KEYRING_KIND_GPG;
	} else {
		priv->keyring_kind = fwupd_keyring_kind_from_string (keyring_kind);
		if (priv->keyring_kind == FWUPD_KEYRING_KIND_UNKNOWN) {
			g_set_error (error,
				     FWUPD_ERROR,
				     FWUPD_ERROR_INVALID_FILE,
				     "Failed to parse type '%s'",
				     keyring_kind);
			return FALSE;
		}
	}

	/* all remotes need a URI, even if it's file:// to the cache */
	metadata_uri = g_key_file_get_string (kf, group, "MetadataURI", error);
	if (metadata_uri == NULL)
		return FALSE;
	if (g_str_has_prefix (metadata_uri, "file://")) {
		const gchar *filename_cache = metadata_uri;
		if (g_str_has_prefix (filename_cache, "file://"))
			filename_cache += 7;
		fwupd_remote_set_filename_cache (self, filename_cache);
		if (g_file_test (filename_cache, G_FILE_TEST_IS_DIR))
			priv->kind = FWUPD_REMOTE_KIND_DIRECTORY;
		else
			priv->kind = FWUPD_REMOTE_KIND_LOCAL;
	} else if (g_str_has_prefix (metadata_uri, "http://") ||
		   g_str_has_prefix (metadata_uri, "https://")) {
		priv->kind = FWUPD_REMOTE_KIND_DOWNLOAD;
	} else {
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_INVALID_FILE,
			     "Failed to parse MetadataURI type '%s'",
			     metadata_uri);
		return FALSE;
	}

	/* extract data */
	priv->enabled = g_key_file_get_boolean (kf, group, "Enabled", NULL);
	priv->approval_required = g_key_file_get_boolean (kf, group, "ApprovalRequired", NULL);
	priv->title = g_key_file_get_string (kf, group, "Title", NULL);

	/* reporting is optional */
	report_uri = g_key_file_get_string (kf, group, "ReportURI", NULL);
	if (report_uri != NULL && report_uri[0] != '\0')
		fwupd_remote_set_report_uri (self, report_uri);

	/* DOWNLOAD-type remotes */
	if (priv->kind == FWUPD_REMOTE_KIND_DOWNLOAD) {
		g_autofree gchar *filename_cache = NULL;
		g_autofree gchar *username = NULL;
		g_autofree gchar *password = NULL;

		/* the client has to download this and the signature */
		fwupd_remote_set_metadata_uri (self, metadata_uri);

		/* check the URI was valid */
		if (priv->metadata_uri == NULL) {
			g_set_error (error,
				     FWUPD_ERROR,
				     FWUPD_ERROR_INVALID_FILE,
				     "Failed to parse URI '%s' in %s",
				     metadata_uri, filename);
			return FALSE;
		}

		/* username and password are optional */
		username = g_key_file_get_string (kf, group, "Username", NULL);
		if (username != NULL)
			fwupd_remote_set_username (self, username);
		password = g_key_file_get_string (kf, group, "Password", NULL);
		if (password != NULL)
			fwupd_remote_set_password (self, password);

		/* set cache to /var/lib... */
		filename_cache = g_build_filename (LOCALSTATEDIR,
						   "lib",
						   "fwupd",
						   "remotes.d",
						   priv->id,
						   "metadata.xml.gz",
						   NULL);
		fwupd_remote_set_filename_cache (self, filename_cache);
	}

	/* load the checksum */
	if (priv->filename_cache_sig != NULL &&
	    g_file_test (priv->filename_cache_sig, G_FILE_TEST_EXISTS)) {
		gsize sz = 0;
		g_autofree gchar *buf = NULL;
		g_autoptr(GChecksum) checksum = g_checksum_new (G_CHECKSUM_SHA256);
		if (!g_file_get_contents (priv->filename_cache_sig, &buf, &sz, error)) {
			g_prefix_error (error, "failed to get checksum: ");
			return FALSE;
		}
		g_checksum_update (checksum, (guchar *) buf, (gssize) sz);
		fwupd_remote_set_checksum (self, g_checksum_get_string (checksum));
	} else {
		fwupd_remote_set_checksum (self, NULL);
	}

	/* the base URI is optional */
	firmware_base_uri = g_key_file_get_string (kf, group, "FirmwareBaseURI", NULL);
	if (firmware_base_uri != NULL)
		fwupd_remote_set_firmware_base_uri (self, firmware_base_uri);

	/* some validation around DIRECTORY types */
	if (priv->kind == FWUPD_REMOTE_KIND_DIRECTORY) {
		if (priv->keyring_kind != FWUPD_KEYRING_KIND_NONE) {
			g_set_error (error,
				     FWUPD_ERROR,
				     FWUPD_ERROR_INVALID_FILE,
				     "Keyring kind %s is not supported with directory remote",
				     fwupd_keyring_kind_to_string (priv->keyring_kind));
			return FALSE;
		}
		if (firmware_base_uri != NULL) {
			g_set_error_literal (error,
					     FWUPD_ERROR,
					     FWUPD_ERROR_INVALID_FILE,
					     "Directory remotes don't support firmware base URI");
			return FALSE;
		}
	}

	/* dep logic */
	order_before = g_key_file_get_string (kf, group, "OrderBefore", NULL);
	if (order_before != NULL)
		priv->order_before = g_strsplit_set (order_before, ",:;", -1);
	order_after = g_key_file_get_string (kf, group, "OrderAfter", NULL);
	if (order_after != NULL)
		priv->order_after = g_strsplit_set (order_after, ",:;", -1);

	/* success */
	fwupd_remote_set_filename_source (self, filename);
	return TRUE;
}
예제 #21
0
static gboolean
lr_fastestmirrorcache_load(LrFastestMirrorCache **cache,
                           gchar *path,
                           LrFastestMirrorCb cb,
                           void *cbdata,
                           GError **err)
{
    assert(cache);
    assert(!err || *err == NULL);

    if (!path) {
        // No cache file specified
        *cache = NULL;
        return TRUE;
    }

    cb(cbdata, LR_FMSTAGE_CACHELOADING, path);

    GKeyFile *keyfile = g_key_file_new();

    *cache = lr_malloc0(sizeof(LrFastestMirrorCache));
    (*cache)->path = g_strdup(path);
    (*cache)->keyfile = keyfile;

    if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
        // Cache file doesn't exist
        cb(cbdata, LR_FMSTAGE_CACHELOADINGSTATUS,
           "Cache doesn't exist");
    } else {
        // Cache exists, try to load it

        gboolean something_wrong = FALSE;
        GError *tmp_err = NULL;
        gboolean ret = g_key_file_load_from_file(keyfile,
                                                 path,
                                                 G_KEY_FILE_NONE,
                                                 &tmp_err);
        if (!ret) {
            // Cannot parse cache file
            char *msg = g_strdup_printf("Cannot parse fastestmirror "
                                        "cache %s: %s", path, tmp_err->message);
            g_debug("%s: %s", __func__, msg);
            cb(cbdata, LR_FMSTAGE_CACHELOADINGSTATUS, msg);
            something_wrong = TRUE;
            g_free(msg);
            g_error_free(tmp_err);
        } else {
            // File parsed successfully
            if (!g_key_file_has_group(keyfile, CACHE_GROUP_METADATA)) {
                // Not a fastestmirror cache
                g_debug("%s: File %s is not a fastestmirror cache file",
                          __func__, path);
                cb(cbdata, LR_FMSTAGE_CACHELOADINGSTATUS,
                   "File is not a fastestmirror cache");
                something_wrong = TRUE;
            } else {
                int version = (int) g_key_file_get_integer(keyfile,
                                                           CACHE_GROUP_METADATA,
                                                           CACHE_KEY_VERSION,
                                                           NULL);
                if (version != CACHE_VERSION) {
                    g_debug("%s: Old cache version %d vs %d",
                            __func__, version, CACHE_VERSION);
                    cb(cbdata, LR_FMSTAGE_CACHELOADINGSTATUS,
                       "Old version of cache format");
                    something_wrong = TRUE;
                }
            }
        }

        if (something_wrong) {
            // Reinit keyfile
            g_key_file_free(keyfile);
            keyfile = g_key_file_new();
            (*cache)->keyfile = keyfile;
        } else {
            gsize len;
            gchar **array = g_key_file_get_groups(keyfile, &len);
            g_debug("%s: Loaded: %"G_GSIZE_FORMAT" records", __func__, len);

            // Remove really outdated records
            gint64 current_time = g_get_real_time() / 1000000;
            char **group, *groupname;
            for (group=array; groupname=*group, groupname; group++) {
                if (g_str_has_prefix(groupname, ":_"))
                    continue;

                gint64 ts = g_key_file_get_int64(keyfile,
                                                 groupname,
                                                 CACHE_KEY_TS,
                                                 NULL);
                if (ts < (current_time - CACHE_RECORD_MAX_AGE)) {
                    // Record is too old, remove it
                    g_debug("%s: Removing too old record from cache: %s "
                            "(ts: %"G_GINT64_FORMAT")",
                            __func__, groupname, ts);
                    g_key_file_remove_group(keyfile, groupname, NULL);
                }
            }
            g_strfreev(array);

            cb(cbdata, LR_FMSTAGE_CACHELOADINGSTATUS, NULL);
        }
    }

    // Set version of cache format
    g_key_file_set_integer(keyfile,
                           CACHE_GROUP_METADATA,
                           CACHE_KEY_VERSION,
                           CACHE_VERSION);

    return TRUE;
}
예제 #22
0
static gboolean
net_usershare_run (int argc, char **argv, GKeyFile **ret_key_file, GError **error)
{
	int real_argc;
	int i;
	char **real_argv;
	gboolean retval;
	char *stdout_contents;
	char *stderr_contents;
	int exit_status;
	int exit_code;
	GKeyFile *key_file;
	GError *real_error;

	g_assert (argc > 0);
	g_assert (argv != NULL);
	g_assert (error == NULL || *error == NULL);

	if (ret_key_file)
		*ret_key_file = NULL;

	/* Build command line */

	real_argc = 2 + argc + 1; /* "net" "usershare" [argv] NULL */
	real_argv = g_new (char *, real_argc);

	real_argv[0] = NET_USERSHARE_ARGV0;
	real_argv[1] = "usershare";

	for (i = 0; i < argc; i++) {
		g_assert (argv[i] != NULL);
		real_argv[i + 2] = argv[i];
	}

	real_argv[real_argc - 1] = NULL;

	/* Launch */

	stdout_contents = NULL;
	stderr_contents = NULL;
	/*
	{
		char **p;

		g_message ("------------------------------------------");

		for (p = real_argv; *p; p++)
			g_message ("spawn arg \"%s\"", *p);

		g_message ("end of spawn args; SPAWNING\n");
	}
	*/
	real_error = NULL;
	retval = g_spawn_sync (NULL,			/* cwd */
			       real_argv,
			       NULL, 			/* envp */
			       G_SPAWN_SEARCH_PATH,
			       NULL, 			/* GSpawnChildSetupFunc */
			       NULL,			/* user_data */
			       &stdout_contents,
			       &stderr_contents,
			       &exit_status,
			       &real_error);

	/* g_message ("returned from spawn: %s: %s", retval ? "SUCCESS" : "FAIL", retval ? "" : real_error->message); */

	if (!retval) {
		g_propagate_error (error, real_error);
		goto out;
	}

	if (!WIFEXITED (exit_status)) {
		g_message ("WIFEXITED(%d) was false!", exit_status);
		retval = FALSE;

		if (WIFSIGNALED (exit_status)) {
			int signal_num;

			signal_num = WTERMSIG (exit_status);
			g_message ("Child got signal %d", signal_num);

			g_set_error (error,
				     SHARES_ERROR,
				     SHARES_ERROR_FAILED,
				     _("%s %s %s returned with signal %d"),
				     real_argv[0],
				     real_argv[1],
				     real_argv[2],
				     signal_num);
		} else
			g_set_error (error,
				     SHARES_ERROR,
				     SHARES_ERROR_FAILED,
				     _("%s %s %s failed for an unknown reason"),
				     real_argv[0],
				     real_argv[1],
				     real_argv[2]);

		goto out;
	}

	exit_code = WEXITSTATUS (exit_status);

	/* g_message ("exit code %d", exit_code); */
	if (exit_code != 0) {
		char *str;
		char *message;

		/* stderr_contents is in the system locale encoding, not UTF-8 */

		str = g_locale_to_utf8 (stderr_contents, -1, NULL, NULL, NULL);

		if (str && str[0])
			message = g_strdup_printf (_("'net usershare' returned error %d: %s"), exit_code, str);
		else
			message = g_strdup_printf (_("'net usershare' returned error %d"), exit_code);

		g_free (str);

		g_set_error (error,
			     G_SPAWN_ERROR,
			     G_SPAWN_ERROR_FAILED,
			     "%s",
			     message);

		g_free (message);

		retval = FALSE;
		goto out;
	}

	if (ret_key_file) {
	  /* g_message ("caller wants GKeyFile"); */

		*ret_key_file = NULL;

		/* FIXME: [email protected] says the output of "net usershare" is nearly always
		 * in UTF-8, but that it can be configured in the master smb.conf.  We assume
		 * UTF-8 for now.
		 */

		if (!g_utf8_validate (stdout_contents, -1, NULL)) {
			g_message ("stdout of net usershare was not in valid UTF-8");
			g_set_error (error,
				     G_SPAWN_ERROR,
				     G_SPAWN_ERROR_FAILED,
				     _("the output of 'net usershare' is not in valid UTF-8 encoding"));
			retval = FALSE;
			goto out;
		}

		key_file = g_key_file_new ();

		real_error = NULL;
		if (!g_key_file_load_from_data (key_file, stdout_contents, -1, 0, &real_error)) {
			g_message ("Error when parsing key file {\n%s\n}: %s", stdout_contents, real_error->message);
			g_propagate_error (error, real_error);
			g_key_file_free (key_file);
			retval = FALSE;
			goto out;
		}

		retval = TRUE;
		*ret_key_file = key_file;
	} else
		retval = TRUE;

	/* g_message ("success from calling net usershare and parsing its output"); */

 out:
	g_free (real_argv);
	g_free (stdout_contents);
	g_free (stderr_contents);

	/* g_message ("------------------------------------------"); */

	return retval;
}
예제 #23
0
void
remmina_pref_init (void)
{
    GKeyFile *gkeyfile;

    remmina_pref_file = g_strdup_printf ("%s/.remmina/remmina.pref", g_get_home_dir ());
    remmina_keymap_file = g_strdup_printf ("%s/.remmina/remmina.keymap", g_get_home_dir ());

    gkeyfile = g_key_file_new ();
    g_key_file_load_from_file (gkeyfile, remmina_pref_file, G_KEY_FILE_NONE, NULL);

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "save_view_mode", NULL))
        remmina_pref.save_view_mode = g_key_file_get_boolean (gkeyfile, "remmina_pref", "save_view_mode", NULL);
    else
        remmina_pref.save_view_mode = TRUE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "save_when_connect", NULL))
        remmina_pref.save_when_connect = g_key_file_get_boolean (gkeyfile, "remmina_pref", "save_when_connect", NULL);
    else
        remmina_pref.save_when_connect = TRUE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "invisible_toolbar", NULL))
        remmina_pref.invisible_toolbar = g_key_file_get_boolean (gkeyfile, "remmina_pref", "invisible_toolbar", NULL);
    else
        remmina_pref.invisible_toolbar = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "always_show_tab", NULL))
        remmina_pref.always_show_tab = g_key_file_get_boolean (gkeyfile, "remmina_pref", "always_show_tab", NULL);
    else
        remmina_pref.always_show_tab = TRUE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "hide_connection_toolbar", NULL))
        remmina_pref.hide_connection_toolbar = g_key_file_get_boolean (gkeyfile, "remmina_pref", "hide_connection_toolbar", NULL);
    else
        remmina_pref.hide_connection_toolbar = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "default_action", NULL))
        remmina_pref.default_action = g_key_file_get_integer (gkeyfile, "remmina_pref", "default_action", NULL);
    else
        remmina_pref.default_action = REMMINA_ACTION_CONNECT;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "scale_quality", NULL))
        remmina_pref.scale_quality = g_key_file_get_integer (gkeyfile, "remmina_pref", "scale_quality", NULL);
    else
        remmina_pref.scale_quality = GDK_INTERP_HYPER;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "hide_toolbar", NULL))
        remmina_pref.hide_toolbar = g_key_file_get_boolean (gkeyfile, "remmina_pref", "hide_toolbar", NULL);
    else
        remmina_pref.hide_toolbar = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "hide_statusbar", NULL))
        remmina_pref.hide_statusbar = g_key_file_get_boolean (gkeyfile, "remmina_pref", "hide_statusbar", NULL);
    else
        remmina_pref.hide_statusbar = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "show_quick_search", NULL))
        remmina_pref.show_quick_search = g_key_file_get_boolean (gkeyfile, "remmina_pref", "show_quick_search", NULL);
    else
        remmina_pref.show_quick_search = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "small_toolbutton", NULL))
        remmina_pref.small_toolbutton = g_key_file_get_boolean (gkeyfile, "remmina_pref", "small_toolbutton", NULL);
    else
        remmina_pref.small_toolbutton = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "view_file_mode", NULL))
        remmina_pref.view_file_mode = g_key_file_get_integer (gkeyfile, "remmina_pref", "view_file_mode", NULL);
    else
        remmina_pref.view_file_mode = REMMINA_VIEW_FILE_LIST;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "resolutions", NULL))
        remmina_pref.resolutions = g_key_file_get_string (gkeyfile, "remmina_pref", "resolutions", NULL);
    else
        remmina_pref.resolutions = g_strdup (default_resolutions);

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "main_width", NULL))
        remmina_pref.main_width = MAX (600, g_key_file_get_integer (gkeyfile, "remmina_pref", "main_width", NULL));
    else
        remmina_pref.main_width = 600;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "main_height", NULL))
        remmina_pref.main_height = MAX (400, g_key_file_get_integer (gkeyfile, "remmina_pref", "main_height", NULL));
    else
        remmina_pref.main_height = 400;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "main_maximize", NULL))
        remmina_pref.main_maximize = g_key_file_get_boolean (gkeyfile, "remmina_pref", "main_maximize", NULL);
    else
        remmina_pref.main_maximize = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "main_sort_column_id", NULL))
        remmina_pref.main_sort_column_id = g_key_file_get_integer (gkeyfile, "remmina_pref", "main_sort_column_id", NULL);
    else
        remmina_pref.main_sort_column_id = 1;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "main_sort_order", NULL))
        remmina_pref.main_sort_order = g_key_file_get_integer (gkeyfile, "remmina_pref", "main_sort_order", NULL);
    else
        remmina_pref.main_sort_order = 0;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "expanded_group", NULL))
        remmina_pref.expanded_group = g_key_file_get_string (gkeyfile, "remmina_pref", "expanded_group", NULL);
    else
        remmina_pref.expanded_group = g_strdup ("");

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "toolbar_pin_down", NULL))
        remmina_pref.toolbar_pin_down = g_key_file_get_boolean (gkeyfile, "remmina_pref", "toolbar_pin_down", NULL);
    else
        remmina_pref.toolbar_pin_down = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "sshtunnel_port", NULL))
        remmina_pref.sshtunnel_port = g_key_file_get_integer (gkeyfile, "remmina_pref", "sshtunnel_port", NULL);
    else
        remmina_pref.sshtunnel_port = DEFAULT_SSHTUNNEL_PORT;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "applet_new_ontop", NULL))
        remmina_pref.applet_new_ontop = g_key_file_get_boolean (gkeyfile, "remmina_pref", "applet_new_ontop", NULL);
    else
        remmina_pref.applet_new_ontop = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "applet_hide_count", NULL))
        remmina_pref.applet_hide_count = g_key_file_get_boolean (gkeyfile, "remmina_pref", "applet_hide_count", NULL);
    else
        remmina_pref.applet_hide_count = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "applet_enable_avahi", NULL))
        remmina_pref.applet_enable_avahi = g_key_file_get_boolean (gkeyfile, "remmina_pref", "applet_enable_avahi", NULL);
    else
        remmina_pref.applet_enable_avahi = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "disable_tray_icon", NULL))
        remmina_pref.disable_tray_icon = g_key_file_get_boolean (gkeyfile, "remmina_pref", "disable_tray_icon", NULL);
    else
        remmina_pref.disable_tray_icon = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "minimize_to_tray", NULL))
        remmina_pref.minimize_to_tray = g_key_file_get_boolean (gkeyfile, "remmina_pref", "minimize_to_tray", NULL);
    else
        remmina_pref.minimize_to_tray = FALSE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "recent_maximum", NULL))
        remmina_pref.recent_maximum = g_key_file_get_integer (gkeyfile, "remmina_pref", "recent_maximum", NULL);
    else
        remmina_pref.recent_maximum = 10;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "default_mode", NULL))
        remmina_pref.default_mode = g_key_file_get_integer (gkeyfile, "remmina_pref", "default_mode", NULL);
    else
        remmina_pref.default_mode = 0;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "tab_mode", NULL))
        remmina_pref.tab_mode = g_key_file_get_integer (gkeyfile, "remmina_pref", "tab_mode", NULL);
    else
        remmina_pref.tab_mode = 0;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "auto_scroll_step", NULL))
        remmina_pref.auto_scroll_step = g_key_file_get_integer (gkeyfile, "remmina_pref", "auto_scroll_step", NULL);
    else
        remmina_pref.auto_scroll_step = 10;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "hostkey", NULL))
        remmina_pref.hostkey = g_key_file_get_integer (gkeyfile, "remmina_pref", "hostkey", NULL);
    else
        remmina_pref.hostkey = GDK_KEY_Control_R;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "shortcutkey_fullscreen", NULL))
        remmina_pref.shortcutkey_fullscreen = g_key_file_get_integer (gkeyfile, "remmina_pref", "shortcutkey_fullscreen", NULL);
    else
        remmina_pref.shortcutkey_fullscreen = GDK_KEY_f;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "shortcutkey_autofit", NULL))
        remmina_pref.shortcutkey_autofit = g_key_file_get_integer (gkeyfile, "remmina_pref", "shortcutkey_autofit", NULL);
    else
        remmina_pref.shortcutkey_autofit = GDK_KEY_1;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "shortcutkey_nexttab", NULL))
        remmina_pref.shortcutkey_nexttab = g_key_file_get_integer (gkeyfile, "remmina_pref", "shortcutkey_nexttab", NULL);
    else
        remmina_pref.shortcutkey_nexttab = GDK_KEY_Right;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "shortcutkey_prevtab", NULL))
        remmina_pref.shortcutkey_prevtab = g_key_file_get_integer (gkeyfile, "remmina_pref", "shortcutkey_prevtab", NULL);
    else
        remmina_pref.shortcutkey_prevtab = GDK_KEY_Left;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "shortcutkey_scale", NULL))
        remmina_pref.shortcutkey_scale = g_key_file_get_integer (gkeyfile, "remmina_pref", "shortcutkey_scale", NULL);
    else
        remmina_pref.shortcutkey_scale = GDK_KEY_s;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "shortcutkey_grab", NULL))
        remmina_pref.shortcutkey_grab = g_key_file_get_integer (gkeyfile, "remmina_pref", "shortcutkey_grab", NULL);
    else
        remmina_pref.shortcutkey_grab = GDK_KEY_Control_R;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "shortcutkey_minimize", NULL))
        remmina_pref.shortcutkey_minimize = g_key_file_get_integer (gkeyfile, "remmina_pref", "shortcutkey_minimize", NULL);
    else
        remmina_pref.shortcutkey_minimize = GDK_KEY_F9;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "shortcutkey_disconnect", NULL))
        remmina_pref.shortcutkey_disconnect = g_key_file_get_integer (gkeyfile, "remmina_pref", "shortcutkey_disconnect", NULL);
    else
        remmina_pref.shortcutkey_disconnect = GDK_KEY_F4;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "shortcutkey_toolbar", NULL))
        remmina_pref.shortcutkey_toolbar = g_key_file_get_integer (gkeyfile, "remmina_pref", "shortcutkey_toolbar", NULL);
    else
        remmina_pref.shortcutkey_toolbar = GDK_KEY_t;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "secret", NULL))
        remmina_pref.secret = g_key_file_get_string (gkeyfile, "remmina_pref", "secret", NULL);
    else
        remmina_pref.secret = NULL;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "vte_font", NULL))
        remmina_pref.vte_font = g_key_file_get_string (gkeyfile, "remmina_pref", "vte_font", NULL);
    else
        remmina_pref.vte_font = NULL;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "vte_allow_bold_text", NULL))
        remmina_pref.vte_allow_bold_text = g_key_file_get_integer (gkeyfile, "remmina_pref", "vte_allow_bold_text", NULL);
    else
        remmina_pref.vte_allow_bold_text = TRUE;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "vte_lines", NULL))
        remmina_pref.vte_lines = g_key_file_get_integer (gkeyfile, "remmina_pref", "vte_lines", NULL);
    else
        remmina_pref.vte_lines = 512;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "vte_shortcutkey_copy", NULL))
        remmina_pref.vte_shortcutkey_copy = g_key_file_get_integer (gkeyfile, "remmina_pref", "vte_shortcutkey_copy", NULL);
    else
        remmina_pref.vte_shortcutkey_copy = GDK_KEY_c;

    if (g_key_file_has_key (gkeyfile, "remmina_pref", "vte_shortcutkey_paste", NULL))
        remmina_pref.vte_shortcutkey_paste = g_key_file_get_integer (gkeyfile, "remmina_pref", "vte_shortcutkey_paste", NULL);
    else
        remmina_pref.vte_shortcutkey_paste = GDK_KEY_v;

    g_key_file_free (gkeyfile);

    if (remmina_pref.secret == NULL) remmina_pref_gen_secret ();

    remmina_pref_init_keymap ();
}
예제 #24
0
/**
 * cedit_plugin_info_new:
 * @filename: the filename where to read the plugin information
 *
 * Creates a new #CeditPluginInfo from a file on the disk.
 *
 * Return value: a newly created #CeditPluginInfo.
 */
CeditPluginInfo *
_cedit_plugin_info_new (const gchar *file)
{
	CeditPluginInfo *info;
	GKeyFile *plugin_file = NULL;
	gchar *str;

	g_return_val_if_fail (file != NULL, NULL);

	cedit_debug_message (DEBUG_PLUGINS, "Loading plugin: %s", file);

	info = g_new0 (CeditPluginInfo, 1);
	info->refcount = 1;
	info->file = g_strdup (file);

	plugin_file = g_key_file_new ();
	if (!g_key_file_load_from_file (plugin_file, file, G_KEY_FILE_NONE, NULL))
	{
		g_warning ("Bad plugin file: %s", file);
		goto error;
	}

	if (!g_key_file_has_key (plugin_file,
			   	 "Cedit Plugin",
				 "IAge",
				 NULL))
	{
		cedit_debug_message (DEBUG_PLUGINS,
				     "IAge key does not exist in file: %s", file);
		goto error;
	}
	
	/* Check IAge=2 */
	if (g_key_file_get_integer (plugin_file,
				    "Cedit Plugin",
				    "IAge",
				    NULL) != 2)
	{
		cedit_debug_message (DEBUG_PLUGINS,
				     "Wrong IAge in file: %s", file);
		goto error;
	}
				    
	/* Get module name */
	str = g_key_file_get_string (plugin_file,
				     "Cedit Plugin",
				     "Module",
				     NULL);

	if ((str != NULL) && (*str != '\0'))
	{
		info->module_name = str;
	}
	else
	{
		g_warning ("Could not find 'Module' in %s", file);
		g_free (str);
		goto error;
	}

	/* Get the dependency list */
	info->dependencies = g_key_file_get_string_list (plugin_file,
							 "Cedit Plugin",
							 "Depends",
							 NULL,
							 NULL);
	if (info->dependencies == NULL)
	{
		cedit_debug_message (DEBUG_PLUGINS, "Could not find 'Depends' in %s", file);
		info->dependencies = g_new0 (gchar *, 1);
	}
예제 #25
0
static gboolean
gs_plugin_repos_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
	GsPluginData *priv = gs_plugin_get_data (plugin);
	g_autoptr(GDir) dir = NULL;
	const gchar *fn;

	/* already valid */
	if (priv->valid)
		return TRUE;

	/* clear existing */
	g_hash_table_remove_all (priv->urls);

	/* search all files */
	dir = g_dir_open (priv->reposdir, 0, error);
	if (dir == NULL) {
		gs_utils_error_convert_gio (error);
		return FALSE;
	}
	while ((fn = g_dir_read_name (dir)) != NULL) {
		g_autofree gchar *filename = NULL;
		g_auto(GStrv) groups = NULL;
		g_autoptr(GKeyFile) kf = g_key_file_new ();
		guint i;

		/* not a repo */
		if (!g_str_has_suffix (fn, ".repo"))
			continue;

		/* load file */
		filename = g_build_filename (priv->reposdir, fn, NULL);
		if (!g_key_file_load_from_file (kf, filename,
						G_KEY_FILE_NONE,
						error)) {
			gs_utils_error_convert_gio (error);
			return FALSE;
		}

		/* we can have multiple repos in one file */
		groups = g_key_file_get_groups (kf, NULL);
		for (i = 0; groups[i] != NULL; i++) {
			g_autofree gchar *tmp = NULL;
			tmp = g_key_file_get_string (kf, groups[i], "baseurl", NULL);
			if (tmp != NULL) {
				g_hash_table_insert (priv->urls,
						     g_strdup (groups[i]),
						     g_strdup (tmp));
				continue;
			}
			tmp = g_key_file_get_string (kf, groups[i], "metalink", NULL);
			if (tmp != NULL) {
				g_hash_table_insert (priv->urls,
						     g_strdup (groups[i]),
						     g_strdup (tmp));
				continue;
			}
		}
	}

	/* success */
	priv->valid = TRUE;
	return TRUE;
}
예제 #26
0
/* reads the user and system presets files and merges them together. This
 * function caches the GKeyFile on the element type. If there is no existing
 * preset file, a new in-memory GKeyFile will be created. */
static GKeyFile *
preset_get_keyfile (GstPreset * preset)
{
  GKeyFile *presets;
  GType type = G_TYPE_FROM_INSTANCE (preset);

  /* first see if the have a cached version for the type */
  if (!(presets = g_type_get_qdata (type, preset_quark))) {
    const gchar *preset_user_path, *preset_app_path, *preset_system_path;
    guint64 version_system = G_GUINT64_CONSTANT (0);
    guint64 version_app = G_GUINT64_CONSTANT (0);
    guint64 version_user = G_GUINT64_CONSTANT (0);
    guint64 version = G_GUINT64_CONSTANT (0);
    gboolean merged = FALSE;
    GKeyFile *in_user, *in_app = NULL, *in_system;

    preset_get_paths (preset, &preset_user_path, &preset_app_path,
        &preset_system_path);

    /* try to load the user, app and system presets, we do this to get the
     * versions of all files. */
    in_user = preset_open_and_parse_header (preset, preset_user_path,
        &version_user);
    if (preset_app_path) {
      in_app = preset_open_and_parse_header (preset, preset_app_path,
          &version_app);
    }
    in_system = preset_open_and_parse_header (preset, preset_system_path,
        &version_system);

    /* compare version to check for merge */
    if (in_system) {
      presets = in_system;
      version = version_system;
    }
    if (in_app) {
      /* if system version is higher, merge */
      if (version > version_app) {
        preset_merge (presets, in_app);
        g_key_file_free (in_app);
      } else {
        if (presets)
          g_key_file_free (presets);
        presets = in_app;
        version = version_system;
      }
    }
    if (in_user) {
      /* if system or app version is higher, merge */
      if (version > version_user) {
        preset_merge (presets, in_user);
        g_key_file_free (in_user);
        merged = TRUE;
      } else {
        if (presets)
          g_key_file_free (presets);
        presets = in_user;
        version = version_user;
      }
    }

    if (!presets) {
      /* we did not load a user, app or system presets file, create a new one */
      presets = g_key_file_new ();
      g_key_file_set_string (presets, PRESET_HEADER, PRESET_HEADER_ELEMENT_NAME,
          G_OBJECT_TYPE_NAME (preset));
    }

    /* attach the preset to the type */
    g_type_set_qdata (type, preset_quark, (gpointer) presets);

    if (merged) {
      gst_preset_default_save_presets_file (preset);
    }
  }
  return presets;
}
예제 #27
0
gboolean
open_file_with_filemanager (GtkWidget * window,
                            const gchar * file)
{
	GDesktopAppInfo * d_app_info;
	GKeyFile * key_file;
	GdkAppLaunchContext * ctx = NULL;
	GList * list = NULL;
	GAppInfo * g_app_info;
	GFile * g_file;
	gchar * command;
	gchar * contents;
	gchar * uri;
	gboolean result = TRUE;

	uri = g_filename_to_uri (file, NULL, NULL);
	list = g_list_prepend (list, uri);

	g_file = g_file_new_for_path (file);
	g_app_info = g_file_query_default_handler (g_file, NULL, NULL);

	if (strcmp (g_app_info_get_executable (g_app_info), "nautilus") == 0) {
		command = g_strconcat ("nautilus ",
		                       "--sm-disable ",
		                       "--no-desktop ",
		                       "--no-default-window ",
		                       NULL);
	}
	else {
		command = g_strconcat (g_app_info_get_executable (g_app_info),
		                       " ", NULL);
	}

	contents = g_strdup_printf ("[Desktop Entry]\n"
				    "Name=Nautilus\n"
				    "Icon=file-manager\n"
				    "Exec=%s\n"
				    "Terminal=false\n"
				    "StartupNotify=true\n"
				    "Type=Application\n",
				    command);
	key_file = g_key_file_new ();
	g_key_file_load_from_data (key_file, contents, strlen(contents), G_KEY_FILE_NONE, NULL);
	d_app_info = g_desktop_app_info_new_from_keyfile (key_file);
	
	if (d_app_info != NULL) {
		ctx = gdk_app_launch_context_new ();
		gdk_app_launch_context_set_screen (ctx, gtk_widget_get_screen (window));

		result = g_app_info_launch_uris (G_APP_INFO (d_app_info), list,  G_APP_LAUNCH_CONTEXT (ctx), NULL);
	}
	else {
		result = FALSE;
	}

	g_object_unref (g_app_info);
	g_object_unref (d_app_info);
	g_object_unref (g_file);
	g_object_unref (ctx);
	g_key_file_free (key_file);
	g_list_free (list);
	g_free (contents);
	g_free (command);
	g_free (uri);

	return result;
}
예제 #28
0
CCMExtension *
ccm_extension_new (gchar * filename)
{
    g_return_val_if_fail (filename != NULL, NULL);

    CCMExtension *self = g_object_new (CCM_TYPE_EXTENSION, NULL);
    GKeyFile *plugin_file = g_key_file_new ();
    gint cpt;
    gchar *dirname = NULL;

    /* Load plugin configuration file */
    if (!g_key_file_load_from_file (plugin_file, filename, 
                                    G_KEY_FILE_NONE, NULL))
    {
        g_warning ("Error on load %s", filename);
        g_object_unref (self);
        return NULL;
    }

    /* Get plugin name */
    if ((self->priv->name = g_key_file_get_string (plugin_file, 
                                                   PLUGIN_SECTION, 
                                                   "Plugin",  NULL)) == NULL)
    {
        g_warning ("Error on get plugin name in %s", filename);
        g_object_unref (self);
        return NULL;
    }
    for (cpt = 0; self->priv->name[cpt]; ++cpt)
    {
        if (self->priv->name[cpt] == '-')
            self->priv->name[cpt] = '_';
    }
    g_type_module_set_name (G_TYPE_MODULE (self), self->priv->name);

    /* Get Label */
    self->priv->label =
        g_key_file_get_locale_string (plugin_file, PLUGIN_SECTION, "Name", NULL,
                                      NULL);

    /* Get description */
    self->priv->description =
        g_key_file_get_locale_string (plugin_file, PLUGIN_SECTION,
                                      "Description", NULL, NULL);

    /* Get version */
    self->priv->version =
        g_key_file_get_locale_string (plugin_file, PLUGIN_SECTION, "Version",
                                      NULL, NULL);

    /* Get backends */
    self->priv->backends =
        g_key_file_get_string_list (plugin_file, PLUGIN_SECTION, "Backends",
                                    NULL, NULL);

    /* Get plugin depends */
    self->priv->depends =
        g_key_file_get_string_list (plugin_file, PLUGIN_SECTION, "Depends",
                                    NULL, NULL);

    g_key_file_free (plugin_file);

    dirname = g_path_get_dirname (filename);
    self->priv->filename =
        g_module_build_path (dirname, G_TYPE_MODULE (self)->name);
    g_free (dirname);

    g_type_module_use (G_TYPE_MODULE (self));

    return self;
}
예제 #29
0
gboolean
exchanges_load_config ( void )
{
  GMappedFile *f;
  GKeyFile *kf;
  GError *error = NULL;
  gsize flen, len_config;
  gchar *config;
  gchar *finput;
  gchar *exch_name_str;
  gchar **exch_name_str_list;
  gchar *exch_desc_str;
  gchar **exch_desc_str_list;
  gint i;

  /* read configuration file */
  f = g_mapped_file_new ( CONFIG_FILENAME, FALSE, &error );

  if ( f == NULL )
    {
      log_print ( "error: exchanges_load_config(): file \'%s\' cannot be read: %s\n", CONFIG_FILENAME, error->message  );
      g_error_free ( error );
      return TRUE;
    }

  flen = g_mapped_file_get_length ( f );
  len_config = strlen(CONFIG_HEADER) + flen + 1;

  /* copy configuration in a buffer after prepending a key-file group name to make GLib happy */
  config = (gchar *) g_malloc ( sizeof(gchar) * len_config );
  strcpy ( config, CONFIG_HEADER );
  finput = g_mapped_file_get_contents ( f );
  memcpy ( config+strlen(CONFIG_HEADER), finput, flen );
  g_mapped_file_unref ( f );
  config[len_config-1] = '\0';

  /* parse configuration file to get exchanges list */
  kf = g_key_file_new ( );
  g_key_file_load_from_data ( kf, config, len_config, G_KEY_FILE_NONE, &error );

  if ( error != NULL )
    {
      log_print ( "error: exchanges_load_config(): unable to parse config file \'%s\': %s\n", CONFIG_FILENAME, error->message  );
      g_error_free ( error );
      return TRUE;
    }

  exch_name_str = g_key_file_get_string ( kf, "markets", "EXCHANGES", &error );

  if ( exch_name_str == NULL )
    {
      log_print ( "error: exchanges_load_config(): unable to find \'EXCHANGES\' key\n"  );
      return TRUE;
    }

  if ( exch_name_str[0] == '\"' )
    exch_name_str[0] = ' '; /* remove \" characters */
  if ( exch_name_str[strlen(exch_name_str)-1] == '\"' )
    exch_name_str[strlen(exch_name_str)-1] = ' ';

  exch_desc_str = g_key_file_get_string ( kf, "markets", "EXCHANGES_DESC", &error );

  if ( exch_desc_str == NULL )
    {
      log_print ( "error: exchanges_load_config(): unable to find \'EXCHANGES_DESC\' key\n"  );
      return TRUE;
    }

  if ( exch_desc_str[0] == '\"' )
    exch_desc_str[0] = ' '; /* remove \" characters */
  if ( exch_desc_str[strlen(exch_desc_str)-1] == '\"' )
    exch_desc_str[strlen(exch_desc_str)-1] = ' ';

  /* build EXCH_DESC array */
  exch_name_str_list = g_strsplit_set ( exch_name_str, " ", 0 );
  exch_desc_str_list = g_strsplit_set ( exch_desc_str, " ", 0 );

  for ( i=0; i<EXCH_NB_MAX; ++i )
    {
      if ( exch_name_str_list[i] == NULL )
        break;

      if ( strlen(exch_name_str_list[i]) == 0 )
        continue;

      /* log_print ( "core: adding exchange \'%s\'\n", exch_name_str_list[i] ); */
      EXCH_DESC[nb_exchanges].name = g_strdup ( exch_name_str_list[i] );

      if ( ( exch_desc_str_list[i] != NULL ) && ( strlen(exch_desc_str_list[i]) > 0 ) )
        EXCH_DESC[nb_exchanges].desc = g_strdup ( exch_desc_str_list[i] );
      else
        EXCH_DESC[nb_exchanges].desc = g_strdup ( exch_name_str_list[i] );

      ++nb_exchanges;
    }

  /* clean up */
  g_key_file_free ( kf );
  g_free ( config );
  g_free ( exch_name_str );
  g_free ( exch_desc_str );
  g_strfreev ( exch_name_str_list );
  g_strfreev ( exch_desc_str_list );

  return FALSE;
}
예제 #30
0
int
main (int argc, char **argv)
{
    GMainLoop *loop;
    XigScreen *screen;
    XigVisual *visual;
    gchar *script_name, *config_file, *config_path;
    GString *command_line;
    gchar **compiz_env, **compiz_argv;
    gint compiz_stdin, compiz_stdout, compiz_stderr;
    GIOChannel *compiz_stdout_channel = NULL;
    GError *error = NULL;

    signal (SIGINT, signal_cb);
    signal (SIGTERM, signal_cb);

    g_type_init ();

    loop = g_main_loop_new (NULL, FALSE);

    if (argc != 2)
    {
        g_printerr ("Usage %s SCRIPT-NAME\n", argv[0]);
        quit (EXIT_FAILURE);
    }
    script_name = argv[1];
    config_file = g_strdup_printf ("%s.conf", script_name);
    config_path = g_build_filename (COMPIZ_XIG_TEST_SOURCE_DIR "/scripts", config_file, NULL);
    g_free (config_file);

    config = g_key_file_new ();
    g_key_file_load_from_file (config, config_path, G_KEY_FILE_NONE, NULL);

    load_script (config_path);

    /* Disable config if requested */
    if (g_key_file_has_key (config, "test-runner-config", "have-config", NULL) &&
        !g_key_file_get_boolean (config, "test-runner-config", "have-config", NULL))
        config_path = NULL;

    g_print ("----------------------------------------\n");
    g_print ("Running script %s\n", script_name);

    /* Create an X server to test with */
    xserver = xig_server_new ("compiz-test", 99);
    xig_server_set_listen_tcp (xserver, FALSE);
    g_signal_connect (xserver, "client-connected", G_CALLBACK (client_connected_cb), NULL);
    g_signal_connect (xserver, "client-disconnected", G_CALLBACK (client_disconnected_cb), NULL);
    xig_server_add_pixmap_format (xserver, 1, 1, 32);
    xig_server_add_pixmap_format (xserver, 4, 8, 32);
    xig_server_add_pixmap_format (xserver, 8, 8, 32);
    xig_server_add_pixmap_format (xserver, 15, 16, 32);
    xig_server_add_pixmap_format (xserver, 16, 16, 32);
    xig_server_add_pixmap_format (xserver, 24, 32, 32);
    xig_server_add_pixmap_format (xserver, 32, 32, 32);
    screen = xig_server_add_screen (xserver, 0x00FFFFFF, 0x00000000, 1024, 768, 1024, 768);
    visual = xig_screen_add_visual (screen, 24, XIG_VISUAL_CLASS_TrueColor, 8, 1, 0x00FF0000, 0x0000FF00, 0x000000FF);
    xig_screen_add_root (screen, visual);

    run_commands ();

    status_timeout = g_timeout_add (STATUS_TIMEOUT, status_timeout_cb, NULL);

    if (!xig_server_start (xserver, &error))
    {
        g_printerr ("Failed to start Xig X server: %s", error->message);
        quit (EXIT_FAILURE);
    }

    compiz_env = g_strsplit ("DISPLAY=:99", " ", -1);
    command_line = g_string_new (compiz_BINARY_DIR "/src/compiz");
    g_print ("Start Compiz with command: %s\n", command_line->str);
    if (!g_shell_parse_argv (command_line->str, NULL, &compiz_argv, &error))
    {
        g_warning ("Error parsing command line: %s", error->message);
        quit (EXIT_FAILURE);
    }
    g_clear_error (&error);
    if (!g_spawn_async_with_pipes (NULL, /* working directory */
                                   compiz_argv,
                                   compiz_env,
                                   G_SPAWN_DO_NOT_REAP_CHILD,
                                   NULL, NULL, /* child setup */
                                   &compiz_pid,
                                   &compiz_stdin,
                                   &compiz_stdout,
                                   &compiz_stderr,
                                   &error))
    {
        g_warning ("Error launching Compiz: %s", error->message);
        quit (EXIT_FAILURE);
    }
    g_clear_error (&error);
    g_child_watch_add (compiz_pid, compiz_exit_cb, NULL);
    if (getenv ("DEBUG"))
        g_print ("Compiz running with PID %d\n", compiz_pid);

    compiz_stdout_channel = g_io_channel_unix_new (compiz_stdout);
    g_io_channel_set_flags (compiz_stdout_channel, G_IO_FLAG_NONBLOCK, NULL);
    g_io_add_watch (compiz_stdout_channel, G_IO_IN, client_stdout_cb, NULL);

    check_status ("COMPIZ START");

    g_main_loop_run (loop);

    g_object_unref (compiz_stdout_channel);

    return EXIT_FAILURE;
}