static gboolean
GuestInfoGather(gpointer data)
{
   char name[256];  // Size is derived from the SUS2 specification
                    // "Host names are limited to 255 bytes"
   char *osString = NULL;
   gboolean disableQueryDiskInfo;
   NicInfoV3 *nicInfo = NULL;
   GuestDiskInfo *diskInfo = NULL;
#if defined(_WIN32) || defined(linux)
   GuestMemInfo vmStats = {0};
   gboolean perfmonEnabled;
#endif
   ToolsAppCtx *ctx = data;

   g_debug("Entered guest info gather.\n");

   /* Send tools version. */
   if (!GuestInfoUpdateVmdb(ctx, INFO_BUILD_NUMBER, BUILD_NUMBER)) {
      /*
       * An older vmx talking to new tools wont be able to handle
       * this message. Continue, if thats the case.
       */

      g_warning("Failed to update VMDB with tools version.\n");
   }

   /* Gather all the relevant guest information. */
   osString = Hostinfo_GetOSName();
   if (osString == NULL) {
      g_warning("Failed to get OS info.\n");
   } else {
      if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME_FULL, osString)) {
         g_warning("Failed to update VMDB\n");
      }
   }
   free(osString);

   osString = Hostinfo_GetOSGuestString();
   if (osString == NULL) {
      g_warning("Failed to get OS info.\n");
   } else {
      if (!GuestInfoUpdateVmdb(ctx, INFO_OS_NAME, osString)) {
         g_warning("Failed to update VMDB\n");
      }
   }
   free(osString);

   disableQueryDiskInfo =
      g_key_file_get_boolean(ctx->config, CONFGROUPNAME_GUESTINFO,
                             CONFNAME_GUESTINFO_DISABLEQUERYDISKINFO, NULL);
   if (!disableQueryDiskInfo) {
      if ((diskInfo = GuestInfo_GetDiskInfo()) == NULL) {
         g_warning("Failed to get disk info.\n");
      } else {
         if (GuestInfoUpdateVmdb(ctx, INFO_DISK_FREE_SPACE, diskInfo)) {
            GuestInfo_FreeDiskInfo(gInfoCache.diskInfo);
            gInfoCache.diskInfo = diskInfo;
         } else {
            g_warning("Failed to update VMDB\n.");
            GuestInfo_FreeDiskInfo(diskInfo);
         }
      }
   }

   if (!System_GetNodeName(sizeof name, name)) {
      g_warning("Failed to get netbios name.\n");
   } else if (!GuestInfoUpdateVmdb(ctx, INFO_DNS_NAME, name)) {
      g_warning("Failed to update VMDB.\n");
   }

   /* Get NIC information. */
   if (!GuestInfo_GetNicInfo(&nicInfo)) {
      g_warning("Failed to get nic info.\n");
   } else if (GuestInfo_IsEqual_NicInfoV3(nicInfo, gInfoCache.nicInfo)) {
      g_debug("Nic info not changed.\n");
      GuestInfo_FreeNicInfo(nicInfo);
   } else if (GuestInfoUpdateVmdb(ctx, INFO_IPADDRESS, nicInfo)) {
      /*
       * Since the update succeeded, free the old cached object, and assign
       * ours to the cache.
       */
      GuestInfo_FreeNicInfo(gInfoCache.nicInfo);
      gInfoCache.nicInfo = nicInfo;
   } else {
      g_warning("Failed to update VMDB.\n");
      GuestInfo_FreeNicInfo(nicInfo);
   }

   /* Send the uptime to VMX so that it can detect soft resets. */
   SendUptime(ctx);

#if defined(_WIN32) || defined(linux)
   /* Send the vmstats to the VMX. */
   perfmonEnabled = !g_key_file_get_boolean(ctx->config,
                                            CONFGROUPNAME_GUESTINFO,
                                            CONFNAME_GUESTINFO_DISABLEPERFMON,
                                            NULL);

   if (perfmonEnabled) {
      if (!GuestInfo_PerfMon(&vmStats)) {
         g_debug("Failed to get vmstats.\n");
      } else {
         vmStats.version = 1;
         if (!GuestInfoUpdateVmdb(ctx, INFO_MEMORY, &vmStats)) {
            g_warning("Failed to send vmstats.\n");
         }
      }
   }
#endif

   return TRUE;
}
示例#2
0
static void read_config ()
{
  // Set default options.
  options.vim_mode = FALSE;
  options.box_width = 200;
  options.box_height = 40;
  options.colorize = TRUE;
  options.color_offset = 0;
  options.show_icons = TRUE;
  options.show_desktop = TRUE;
  options.show_titles = TRUE;
  options.icon_size = 16;
  options.font = g_strdup ("Sans 10");
  options.read_stdin = FALSE;
  options.screenshot = FALSE;
  options.screenshot_offset_x = 0;
  options.screenshot_offset_y = 0;

  gchar *filename = g_strjoin ("/", g_get_user_config_dir (), "xwinmosaic/config", NULL);

  GError *error = NULL;
  GKeyFile *config = g_key_file_new ();

  if (!g_key_file_load_from_file (config, filename, 0, &error)) {
    write_default_config ();
    return;
  }

  const gchar *group = "default";
  if (g_key_file_has_group (config, group)) {
    if (g_key_file_has_key (config, group, "vim_mode", &error))
      options.vim_mode = g_key_file_get_boolean (config, group, "vim_mode", &error);
    if (g_key_file_has_key (config, group, "box_width", &error))
      options.box_width = g_key_file_get_integer (config, group, "box_width", &error);
    if (g_key_file_has_key (config, group, "box_height", &error))
      options.box_height = g_key_file_get_integer (config, group, "box_height", &error);
    if (g_key_file_has_key (config, group, "colorize", &error))
      options.colorize = g_key_file_get_boolean (config, group, "colorize", &error);
    if (g_key_file_has_key (config, group, "color_offset", &error))
      options.color_offset = g_key_file_get_integer (config, group, "color_offset", &error);
    if (g_key_file_has_key (config, group, "show_icons", &error))
      options.show_icons = g_key_file_get_boolean (config, group, "show_icons", &error);
    if (g_key_file_has_key (config, group, "show_desktop", &error))
      options.show_desktop = g_key_file_get_boolean (config, group, "show_desktop", &error);
    if (g_key_file_has_key (config, group, "show_titles", &error))
      options.show_titles = g_key_file_get_boolean (config, group, "show_titles", &error);
    if (g_key_file_has_key (config, group, "icon_size", &error))
      options.icon_size = g_key_file_get_integer (config, group, "icon_size", &error);
    if (g_key_file_has_key (config, group, "font", &error))
      options.font = g_key_file_get_string (config, group, "font", &error);
    if (g_key_file_has_key (config, group, "screenshot", &error))
      options.screenshot = g_key_file_get_boolean (config, group, "screenshot", &error);
    if (g_key_file_has_key (config, group, "screenshot_offset_x", &error))
      options.screenshot_offset_x = g_key_file_get_integer (config, group, "screenshot_offset_x", &error);
    if (g_key_file_has_key (config, group, "screenshot_offset_y", &error))
      options.screenshot_offset_y = g_key_file_get_integer (config, group, "screenshot_offset_y", &error);
    if (g_key_file_has_key (config, group, "at_pointer", &error))
      options.at_pointer = g_key_file_get_boolean (config, group, "at_pointer", &error);
    if (g_key_file_has_key (config, group, "color_file", &error))
      options.color_file = g_key_file_get_string (config, group, "color_file", &error);
  }

  g_key_file_free (config);
}
示例#3
0
文件: drun.c 项目: pfsmorigo/rofi
/**
 * This function absorbs/freeś path, so this is no longer available afterwards.
 */
static gboolean read_desktop_file ( DRunModePrivateData *pd, const char *root, const char *path )
{
    // Create ID on stack.
    // We know strlen (path ) > strlen(root)+1
    const ssize_t id_len = strlen ( path ) - strlen ( root );
    char          id[id_len];
    g_strlcpy ( id, &( path[strlen ( root ) + 1] ), id_len );
    for ( int index = 0; index < id_len; index++ ) {
        if ( id[index] == '/' ) {
            id[index] = '-';
        }
    }

    // Check if item is on disabled list.
    if ( g_hash_table_contains ( pd->disabled_entries, id ) ) {
        g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Skipping: %s, was previously seen.", id );
        return TRUE;
    }
    GKeyFile *kf    = g_key_file_new ();
    GError   *error = NULL;
    g_key_file_load_from_file ( kf, path, 0, &error );
    // If error, skip to next entry
    if ( error != NULL ) {
        g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Failed to parse desktop file: %s because: %s", path, error->message );
        g_error_free ( error );
        g_key_file_free ( kf );
        return FALSE;
    }
    // Skip non Application entries.
    gchar *key = g_key_file_get_string ( kf, "Desktop Entry", "Type", NULL );
    if ( key == NULL ) {
        // No type? ignore.
        g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: No type indicated", path );
        g_key_file_free ( kf );
        return FALSE;
    }
    if ( g_strcmp0 ( key, "Application" ) ) {
        g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Skipping desktop file: %s because: Not of type application (%s)", path, key );
        g_free ( key );
        g_key_file_free ( kf );
        return FALSE;
    }
    g_free ( key );

    // Name key is required.
    if ( !g_key_file_has_key ( kf, "Desktop Entry", "Name", NULL ) ) {
        g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Invalid DesktopFile: '%s', no 'Name' key present.\n", path );
        g_key_file_free ( kf );
        return FALSE;
    }

    // Skip hidden entries.
    if ( g_key_file_get_boolean ( kf, "Desktop Entry", "Hidden", NULL ) ) {
        g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Adding desktop file: %s to disabled list because: Hdden", path );
        g_key_file_free ( kf );
        g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) );
        return FALSE;
    }
    // Skip entries that have NoDisplay set.
    if ( g_key_file_get_boolean ( kf, "Desktop Entry", "NoDisplay", NULL ) ) {
        g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Adding desktop file: %s to disabled list because: NoDisplay", path );
        g_key_file_free ( kf );
        g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) );
        return FALSE;
    }
    // We need Exec, don't support DBusActivatable
    if ( !g_key_file_has_key ( kf, "Desktop Entry", "Exec", NULL ) ) {
        g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Unsupported DesktopFile: '%s', no 'Exec' key present.\n", path );
        g_key_file_free ( kf );
        return FALSE;
    }
    size_t nl = ( ( pd->cmd_list_length ) + 1 );
    if ( nl >= pd->cmd_list_length_actual ) {
        pd->cmd_list_length_actual += 256;
        pd->entry_list              = g_realloc ( pd->entry_list, pd->cmd_list_length_actual * sizeof ( *( pd->entry_list ) ) );
    }
    pd->entry_list[pd->cmd_list_length].root = g_strdup ( root );
    pd->entry_list[pd->cmd_list_length].path = g_strdup ( path );
    gchar *n = g_key_file_get_locale_string ( kf, "Desktop Entry", "Name", NULL, NULL );
    pd->entry_list[pd->cmd_list_length].name = n;
    gchar *gn = g_key_file_get_locale_string ( kf, "Desktop Entry", "GenericName", NULL, NULL );
    pd->entry_list[pd->cmd_list_length].generic_name = gn;
#ifdef GET_CAT_PARSE_TIME
    pd->entry_list[pd->cmd_list_length].categories = g_key_file_get_locale_string_list ( kf, "Desktop Entry", "Categories", NULL, NULL, NULL );
#endif
    pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, "Desktop Entry", "Exec", NULL );

    // Keep keyfile around.
    pd->entry_list[pd->cmd_list_length].key_file = kf;
    // We don't want to parse items with this id anymore.
    g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) );
    ( pd->cmd_list_length )++;
    return TRUE;
}
示例#4
0
/* Open the named notmuch configuration file. If the filename is NULL,
 * the value of the environment variable $NOTMUCH_CONFIG will be used.
 * If $NOTMUCH_CONFIG is unset, the default configuration file
 * ($HOME/.notmuch-config) will be used.
 *
 * If any error occurs, (out of memory, or a permission-denied error,
 * etc.), this function will print a message to stderr and return
 * NULL.
 *
 * FILE NOT FOUND: When the specified configuration file (whether from
 * 'filename' or the $NOTMUCH_CONFIG environment variable) does not
 * exist, the behavior of this function depends on the 'is_new_ret'
 * variable.
 *
 *	If is_new_ret is NULL, then a "file not found" message will be
 *	printed to stderr and NULL will be returned.

 *	If is_new_ret is non-NULL then a default configuration will be
 *	returned and *is_new_ret will be set to 1 on return so that
 *	the caller can recognize this case.
 *
 * 	These default configuration settings are determined as
 * 	follows:
 *
 *		database_path:		$HOME/mail
 *
 *		user_name:		From /etc/passwd
 *
 *		user_primary_mail: 	$EMAIL variable if set, otherwise
 *					constructed from the username and
 *					hostname of the current machine.
 *
 *		user_other_email:	Not set.
 *
 *	The default configuration also contains comments to guide the
 *	user in editing the file directly.
 */
notmuch_config_t *
notmuch_config_open (void *ctx,
		     const char *filename,
		     notmuch_bool_t create_new)
{
    GError *error = NULL;
    size_t tmp;
    char *notmuch_config_env = NULL;
    int file_had_database_group;
    int file_had_new_group;
    int file_had_user_group;
    int file_had_maildir_group;
    int file_had_search_group;

    notmuch_config_t *config = talloc (ctx, notmuch_config_t);
    if (config == NULL) {
	fprintf (stderr, "Out of memory.\n");
	return NULL;
    }
    
    talloc_set_destructor (config, notmuch_config_destructor);

    if (filename) {
	config->filename = talloc_strdup (config, filename);
    } else if ((notmuch_config_env = getenv ("NOTMUCH_CONFIG"))) {
	config->filename = talloc_strdup (config, notmuch_config_env);
    } else {
	config->filename = talloc_asprintf (config, "%s/.notmuch-config",
					    getenv ("HOME"));
    }

    config->key_file = g_key_file_new ();

    config->is_new = FALSE;
    config->database_path = NULL;
    config->user_name = NULL;
    config->user_primary_email = NULL;
    config->user_other_email = NULL;
    config->user_other_email_length = 0;
    config->new_tags = NULL;
    config->new_tags_length = 0;
    config->new_ignore = NULL;
    config->new_ignore_length = 0;
    config->maildir_synchronize_flags = TRUE;
    config->search_exclude_tags = NULL;
    config->search_exclude_tags_length = 0;

    if (! g_key_file_load_from_file (config->key_file,
				     config->filename,
				     G_KEY_FILE_KEEP_COMMENTS,
				     &error))
    {
	/* If create_new is true, then the caller is prepared for a
	 * default configuration file in the case of FILE NOT
	 * FOUND. Otherwise, any read failure is an error.
	 */
	if (create_new &&
	    error->domain == G_FILE_ERROR &&
	    error->code == G_FILE_ERROR_NOENT)
	{
	    g_error_free (error);
	    config->is_new = TRUE;
	}
	else
	{
	    fprintf (stderr, "Error reading configuration file %s: %s\n",
		     config->filename, error->message);
	    talloc_free (config);
	    g_error_free (error);
	    return NULL;
	}
    }

    /* Whenever we know of configuration sections that don't appear in
     * the configuration file, we add some comments to help the user
     * understand what can be done.
     *
     * It would be convenient to just add those comments now, but
     * apparently g_key_file will clear any comments when keys are
     * added later that create the groups. So we have to check for the
     * groups now, but add the comments only after setting all of our
     * values.
     */
    file_had_database_group = g_key_file_has_group (config->key_file,
						    "database");
    file_had_new_group = g_key_file_has_group (config->key_file, "new");
    file_had_user_group = g_key_file_has_group (config->key_file, "user");
    file_had_maildir_group = g_key_file_has_group (config->key_file, "maildir");
    file_had_search_group = g_key_file_has_group (config->key_file, "search");


    if (notmuch_config_get_database_path (config) == NULL) {
	char *path = talloc_asprintf (config, "%s/mail",
				      getenv ("HOME"));
	notmuch_config_set_database_path (config, path);
	talloc_free (path);
    }

    if (notmuch_config_get_user_name (config) == NULL) {
	char *name = get_name_from_passwd_file (config);
	notmuch_config_set_user_name (config, name);
	talloc_free (name);
    }

    if (notmuch_config_get_user_primary_email (config) == NULL) {
	char *email = getenv ("EMAIL");
	if (email) {
	    notmuch_config_set_user_primary_email (config, email);
	} else {
	    char hostname[256];
	    struct hostent *hostent;
	    const char *domainname;

	    char *username = get_username_from_passwd_file (config);

	    gethostname (hostname, 256);
	    hostname[255] = '\0';

	    hostent = gethostbyname (hostname);
	    if (hostent && (domainname = strchr (hostent->h_name, '.')))
		domainname += 1;
	    else
		domainname = "(none)";

	    email = talloc_asprintf (config, "%s@%s.%s",
				     username, hostname, domainname);

	    notmuch_config_set_user_primary_email (config, email);

	    talloc_free (username);
	    talloc_free (email);
	}
    }

    if (notmuch_config_get_new_tags (config, &tmp) == NULL) {
        const char *tags[] = { "unread", "inbox" };
	notmuch_config_set_new_tags (config, tags, 2);
    }

    if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {
	notmuch_config_set_new_ignore (config, NULL, 0);
    }

    if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
	if (config->is_new) {
	    const char *tags[] = { "deleted", "spam" };
	    notmuch_config_set_search_exclude_tags (config, tags, 2);
	} else {
	    notmuch_config_set_search_exclude_tags (config, NULL, 0);
	}
    }

    error = NULL;
    config->maildir_synchronize_flags =
	g_key_file_get_boolean (config->key_file,
				"maildir", "synchronize_flags", &error);
    if (error) {
	notmuch_config_set_maildir_synchronize_flags (config, TRUE);
	g_error_free (error);
    }

    /* Whenever we know of configuration sections that don't appear in
     * the configuration file, we add some comments to help the user
     * understand what can be done. */
    if (config->is_new)
	g_key_file_set_comment (config->key_file, NULL, NULL,
				toplevel_config_comment, NULL);

    if (! file_had_database_group)
	g_key_file_set_comment (config->key_file, "database", NULL,
				database_config_comment, NULL);

    if (! file_had_new_group)
	g_key_file_set_comment (config->key_file, "new", NULL,
				new_config_comment, NULL);

    if (! file_had_user_group)
	g_key_file_set_comment (config->key_file, "user", NULL,
				user_config_comment, NULL);

    if (! file_had_maildir_group)
	g_key_file_set_comment (config->key_file, "maildir", NULL,
				maildir_config_comment, NULL);

    if (! file_had_search_group)
	g_key_file_set_comment (config->key_file, "search", NULL,
				search_config_comment, NULL);

    return config;
}
示例#5
0
static gpointer _dentry_ui_init(GtkBuilder *ui, gpointer uidata, FmFileInfoList *files)
{
    GObject *widget;
    GtkWidget *new_widget;
    FmFilePropertiesDEntryData *data;
    GtkTable *table;
    GtkLabel *label;
    GError *err = NULL;
    FmFileInfo *fi;
    GFile *gf;
    gchar *txt;
    gsize length;
    const gchar * const *langs;
    gboolean tmp_bool;

    /* disable permissions tab and open_with in any case */
#define HIDE_WIDGET(x) widget = gtk_builder_get_object(ui, x); \
        gtk_widget_hide(GTK_WIDGET(widget))
    /* HIDE_WIDGET("permissions_tab");
       TODO: made visibility of permissions_tab configurable */
    table = GTK_TABLE(gtk_builder_get_object(ui, "general_table"));
    HIDE_WIDGET("open_with");
    HIDE_WIDGET("open_with_label");
    gtk_table_set_row_spacing(table, 5, 0);
    /* we will do the thing only for single file! */
    if (fm_file_info_list_get_length(files) != 1)
        return NULL;
    fi = fm_file_info_list_peek_head(files);
    gf = fm_path_to_gfile(fm_file_info_get_path(fi));
    if (!g_file_load_contents(gf, NULL, &txt, &length, NULL, NULL))
    {
        g_warning("file properties dialog: cannot access desktop entry file");
        g_object_unref(gf);
        return NULL;
    }
    data = g_slice_new(FmFilePropertiesDEntryData);
    data->changed = FALSE;
    data->file = gf;
    data->kf = g_key_file_new();
    g_key_file_load_from_data(data->kf, txt, length,
                              G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
                              NULL);
    g_free(txt);
    /* FIXME: handle errors, also do g_key_file_has_group() */
    /* get locale name */
    data->lang = NULL;
    langs = g_get_language_names();
    if (strcmp(langs[0], "C") != 0)
    {
        /* remove encoding from locale name */
        char *sep = strchr(langs[0], '.');
        if (sep)
            data->lang = g_strndup(langs[0], sep - langs[0]);
        else
            data->lang = g_strdup(langs[0]);
    }
    /* enable events for icon */
    widget = gtk_builder_get_object(ui, "icon_eventbox");
    data->icon = gtk_builder_get_object(ui, "icon");
    gtk_widget_set_can_focus(GTK_WIDGET(widget), TRUE);
    /* disable Name event handler in the widget */
    widget = gtk_builder_get_object(ui, "name");
    g_signal_handlers_block_matched(widget, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, uidata);
    g_signal_connect(widget, "changed", G_CALLBACK(_dentry_name_changed), data);
    data->name = GTK_ENTRY(widget);
    data->saved_name = g_strdup(gtk_entry_get_text(data->name));
    /* FIXME: two lines below is temporary workaround on FIXME in widget */
    gtk_widget_set_can_focus(GTK_WIDGET(widget), TRUE);
    gtk_editable_set_editable(GTK_EDITABLE(widget), TRUE);
    /* Name is set from "Name" by libfm already so don't touch it */
    /* support 'hidden' option */
    data->hidden = NULL;
    widget = gtk_builder_get_object(ui, "hidden");
    if (widget && GTK_IS_TOGGLE_BUTTON(widget) && fm_file_info_is_native(fi))
    {
        data->hidden = (GtkToggleButton*)widget;
        data->was_hidden = fm_file_info_is_hidden(fi);
        g_signal_connect(widget, "toggled", G_CALLBACK(_dentry_hidden_toggled), data);
        gtk_widget_set_can_focus(GTK_WIDGET(data->hidden), TRUE);
        /* set sensitive since it can be toggled for desktop entry */
        gtk_widget_set_sensitive(GTK_WIDGET(widget), TRUE);
        gtk_widget_show(GTK_WIDGET(data->hidden));
    }
#undef HIDE_WIDGET
    /* FIXME: migrate to GtkGrid */
    table = GTK_TABLE(gtk_table_new(8, 2, FALSE));
    gtk_table_set_row_spacings(table, 4);
    gtk_table_set_col_spacings(table, 12);
    gtk_container_set_border_width(GTK_CONTAINER(table), 4);
    /* row 0: "Exec" GtkHBox: GtkEntry+GtkButton */
    new_widget = gtk_label_new(NULL);
    label = GTK_LABEL(new_widget);
    gtk_misc_set_alignment(GTK_MISC(new_widget), 0.0, 0.0);
    gtk_label_set_markup_with_mnemonic(label, _("<b>Co_mmand:</b>"));
    gtk_table_attach(table, new_widget, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
#if GTK_CHECK_VERSION(3, 2, 0)
    /* FIXME: migrate to GtkGrid */
    widget = G_OBJECT(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6));
#else
    widget = G_OBJECT(gtk_hbox_new(FALSE, 6));
#endif
    new_widget = gtk_button_new_with_mnemonic(_("_Browse..."));
    gtk_box_pack_end(GTK_BOX(widget), new_widget, FALSE, FALSE, 0);
    g_signal_connect(new_widget, "clicked",
                     G_CALLBACK(_dentry_browse_exec_event), data);
    new_widget = gtk_entry_new();
    data->exec = GTK_ENTRY(new_widget);
    txt = g_key_file_get_locale_string(data->kf, GRP_NAME, "Exec", NULL, NULL);
    if (txt)
    {
        gtk_entry_set_text(data->exec, txt);
        g_free(txt);
    }
    gtk_widget_set_tooltip_text(new_widget,
                                _("Command to execute when the application icon is activated"));
    gtk_box_pack_start(GTK_BOX(widget), new_widget, TRUE, TRUE, 0);
    g_signal_connect(new_widget, "changed", G_CALLBACK(_dentry_exec_changed), data);
    gtk_table_attach(table, GTK_WIDGET(widget), 1, 2, 0, 1, GTK_FILL|GTK_EXPAND, 0, 0, 0);
    gtk_label_set_mnemonic_widget(label, new_widget);
    /* row 1: "Terminal" GtkCheckButton */
    new_widget = gtk_check_button_new_with_mnemonic(_("_Execute in terminal emulator"));
    data->terminal = GTK_TOGGLE_BUTTON(new_widget);
    tmp_bool = g_key_file_get_boolean(data->kf, GRP_NAME, "Terminal", &err);
    if (err) /* no such key present */
    {
        tmp_bool = FALSE;
        g_clear_error(&err);
    }
    gtk_toggle_button_set_active(data->terminal, tmp_bool);
    g_signal_connect(new_widget, "toggled", G_CALLBACK(_dentry_terminal_toggled), data);
    gtk_table_attach(table, new_widget, 0, 2, 1, 2, GTK_FILL, 0, 18, 0);
    /* row 2: "X-KeepTerminal" GtkCheckButton */
    new_widget = gtk_check_button_new_with_mnemonic(_("_Keep terminal window open after command execution"));
    data->keep_open = GTK_TOGGLE_BUTTON(new_widget);
    gtk_widget_set_sensitive(new_widget, tmp_bool); /* disable if not in terminal */
    tmp_bool = g_key_file_get_boolean(data->kf, GRP_NAME, "X-KeepTerminal", &err);
    if (err) /* no such key present */
    {
        tmp_bool = FALSE;
        g_clear_error(&err);
    }
    gtk_toggle_button_set_active(data->keep_open, tmp_bool);
    g_signal_connect(new_widget, "toggled", G_CALLBACK(_dentry_keepterm_toggled), data);
    gtk_table_attach(table, new_widget, 0, 2, 2, 3, GTK_FILL, 0, 27, 0);
    /* row 4: "GenericName" GtkEntry */
    new_widget = gtk_label_new(NULL);
    label = GTK_LABEL(new_widget);
    gtk_misc_set_alignment(GTK_MISC(new_widget), 0.0, 0.0);
    gtk_label_set_markup_with_mnemonic(label, _("<b>D_escription:</b>"));
    gtk_table_attach(table, new_widget, 0, 1, 4, 5, GTK_FILL, 0, 0, 0);
    new_widget = gtk_entry_new();
    data->generic_name = GTK_ENTRY(new_widget);
    txt = g_key_file_get_locale_string(data->kf, GRP_NAME, "GenericName", NULL, NULL);
    if (txt)
    {
        gtk_entry_set_text(data->generic_name, txt);
        g_free(txt);
    }
    gtk_widget_set_tooltip_text(new_widget, _("Generic name of the application"));
    g_signal_connect(new_widget, "changed", G_CALLBACK(_dentry_genname_changed), data);
    gtk_table_attach(table, new_widget, 1, 2, 4, 5, GTK_FILL|GTK_EXPAND, 0, 0, 0);
    gtk_label_set_mnemonic_widget(label, new_widget);
    /* row 3: "Path" GtkEntry */
    new_widget = gtk_label_new(NULL);
    label = GTK_LABEL(new_widget);
    gtk_misc_set_alignment(GTK_MISC(new_widget), 0.0, 0.0);
    gtk_label_set_markup_with_mnemonic(label, _("<b>_Working directory:</b>"));
    gtk_table_attach(table, new_widget, 0, 1, 3, 4, GTK_FILL, 0, 0, 0);
    new_widget = gtk_entry_new();
    data->path = GTK_ENTRY(new_widget);
    txt = g_key_file_get_locale_string(data->kf, GRP_NAME, "Path", NULL, NULL);
    if (txt)
    {
        gtk_entry_set_text(data->path, txt);
        g_free(txt);
    }
    gtk_widget_set_tooltip_text(new_widget,
                                _("The working directory to run the program in"));
    g_signal_connect(new_widget, "changed", G_CALLBACK(_dentry_path_changed), data);
    gtk_table_attach(table, new_widget, 1, 2, 3, 4, GTK_FILL|GTK_EXPAND, 0, 0, 0);
    gtk_label_set_mnemonic_widget(label, new_widget);
    /* row 5: "Comment" GtkEntry */
    new_widget = gtk_label_new(NULL);
    label = GTK_LABEL(new_widget);
    gtk_misc_set_alignment(GTK_MISC(new_widget), 0.0, 0.0);
    gtk_label_set_markup_with_mnemonic(label, _("<b>_Tooltip:</b>"));
    gtk_table_attach(table, new_widget, 0, 1, 5, 6, GTK_FILL, 0, 0, 0);
    new_widget = gtk_entry_new();
    data->comment = GTK_ENTRY(new_widget);
    txt = g_key_file_get_locale_string(data->kf, GRP_NAME, "Comment", NULL, NULL);
    if (txt)
    {
        gtk_entry_set_text(data->comment, txt);
        g_free(txt);
    }
    gtk_widget_set_tooltip_text(new_widget, _("Tooltip to show on application"));
    g_signal_connect(new_widget, "changed", G_CALLBACK(_dentry_tooltip_changed), data);
    gtk_table_attach(table, new_widget, 1, 2, 5, 6, GTK_FILL|GTK_EXPAND, 0, 0, 0);
    gtk_label_set_mnemonic_widget(label, new_widget);
    /* TODO: handle "TryExec" field ? */
    /* row 7: "StartupNotify" GtkCheckButton */
    new_widget = gtk_check_button_new_with_mnemonic(_("_Use startup notification"));
    data->notification = GTK_TOGGLE_BUTTON(new_widget);
    tmp_bool = g_key_file_get_boolean(data->kf, GRP_NAME, "StartupNotify", &err);
    if (err) /* no such key present */
    {
        tmp_bool = FALSE;
        g_clear_error(&err);
    }
    gtk_toggle_button_set_active(data->notification, tmp_bool);
    g_signal_connect(new_widget, "toggled", G_CALLBACK(_dentry_notification_toggled), data);
    gtk_table_attach(table, new_widget, 0, 2, 7, 8, GTK_FILL, 0, 0, 0);
    /* put the table into third tab and enable it */
    widget = gtk_builder_get_object(ui, "extra_tab_label");
    gtk_label_set_markup_with_mnemonic(GTK_LABEL(widget), _("_Desktop Entry"));
    widget = gtk_builder_get_object(ui, "extra_tab");
    gtk_container_add(GTK_CONTAINER(widget), GTK_WIDGET(table));
    gtk_widget_show_all(GTK_WIDGET(widget));
    return data;
}
示例#6
0
文件: drun.c 项目: guyhughes/rofi
/**
 * Internal spider used to get list of executables.
 */
static void get_apps_dir ( DRunModePrivateData *pd, const char *bp )
{
    DIR *dir = opendir ( bp );

    if ( dir != NULL ) {
        struct dirent *dent;

        while ( ( dent = readdir ( dir ) ) != NULL ) {
            if ( dent->d_type != DT_REG && dent->d_type != DT_LNK && dent->d_type != DT_UNKNOWN ) {
                continue;
            }
            // Skip dot files.
            if ( dent->d_name[0] == '.' ) {
                continue;
            }
            gchar    *path  = g_build_filename ( bp, dent->d_name, NULL );
            GKeyFile *kf    = g_key_file_new ();
            GError   *error = NULL;
            // TODO: check what flags to set;
            g_key_file_load_from_file ( kf, path, 0, NULL );
            if ( error == NULL ) {
                if ( g_key_file_has_key ( kf, "Desktop Entry", "Exec", NULL ) ) {
                    pd->cmd_list   = g_realloc ( pd->cmd_list, ( ( pd->cmd_list_length ) + 2 ) * sizeof ( *( pd->cmd_list ) ) );
                    pd->entry_list = g_realloc ( pd->entry_list, ( pd->cmd_list_length + 2 ) * sizeof ( *( pd->entry_list ) ) );
                    if ( g_key_file_has_key ( kf, "Desktop Entry", "Name", NULL ) ) {
                        gchar *n  = NULL;
                        gchar *gn = NULL;
                        n  = g_key_file_get_locale_string ( kf, "Desktop Entry", "Name", NULL, NULL );
                        gn = g_key_file_get_locale_string ( kf, "Desktop Entry", "GenericName", NULL, NULL );
                        if ( gn == NULL ) {
                            pd->cmd_list[pd->cmd_list_length] = g_markup_escape_text ( n, -1 );
                        }
                        else {
                            ( pd->cmd_list )[( pd->cmd_list_length )] = g_markup_printf_escaped (
                                "%s <span weight='light' size='small'><i>(%s)</i></span>",
                                n,
                                gn ? gn : "" );
                        }
                        g_free ( n ); g_free ( gn );
                    }
                    else {
                        ( pd->cmd_list )[( pd->cmd_list_length )] = g_strdup ( dent->d_name );
                    }
                    pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, "Desktop Entry", "Exec", NULL );
                    if ( g_key_file_has_key ( kf, "Desktop Entry", "Terminal", NULL ) ) {
                        pd->entry_list[pd->cmd_list_length].terminal = g_key_file_get_boolean ( kf, "Desktop Entry", "Terminal", NULL );
                    }
                    ( pd->cmd_list )[( pd->cmd_list_length ) + 1] = NULL;
                    ( pd->cmd_list_length )++;
                }
            }
            else {
                g_error_free ( error );
            }
            g_key_file_free ( kf );
            g_free ( path );
        }

        closedir ( dir );
    }
}
示例#7
0
gboolean
accounts_rename(const char *const account_name, const char *const new_name)
{
    if (g_key_file_has_group(accounts, new_name)) {
        return FALSE;
    }

    if (!g_key_file_has_group(accounts, account_name)) {
        return FALSE;
    }

    // treat all properties as strings for copy
    gchar *string_keys[] = {
        "enabled",
        "jid",
        "server",
        "port",
        "resource",
        "password",
        "eval_password",
        "presence.last",
        "presence.laststatus",
        "presence.login",
        "priority.online",
        "priority.chat",
        "priority.away",
        "priority.xa",
        "priority.dnd",
        "muc.service",
        "muc.nick",
        "otr.policy",
        "otr.manual",
        "otr.opportunistic",
        "otr.always",
        "pgp.keyid",
        "last.activity",
        "script.start",
        "tls.policy"
    };

    int i;
    for (i = 0; i < ARRAY_SIZE(string_keys); i++) {
        char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
        if (value) {
            g_key_file_set_string(accounts, new_name, string_keys[i], value);
            g_free(value);
        }
    }

    g_key_file_remove_group(accounts, account_name, NULL);
    _save_accounts();

    autocomplete_remove(all_ac, account_name);
    autocomplete_add(all_ac, new_name);
    if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) {
        autocomplete_remove(enabled_ac, account_name);
        autocomplete_add(enabled_ac, new_name);
    }

    return TRUE;
}
static guint
get_flags_from_key_file (DesktopEntry *entry,
                         GKeyFile     *key_file,
                         const char   *desktop_entry_group)
{
  GError    *error;
  char     **strv;
  gboolean   no_display;
  gboolean   hidden;
  gboolean   show_in_mate;
  gboolean   tryexec_failed;
  char      *tryexec;
  guint      flags;
  int        i;

  error = NULL;
  no_display = g_key_file_get_boolean (key_file,
                                       desktop_entry_group,
                                       "NoDisplay",
                                       &error);
  if (error)
    {
      no_display = FALSE;
      g_error_free (error);
    }

  error = NULL;
  hidden = g_key_file_get_boolean (key_file,
                                   desktop_entry_group,
                                   "Hidden",
                                   &error);
  if (error)
    {
      hidden = FALSE;
      g_error_free (error);
    }

  show_in_mate = TRUE;
  strv = g_key_file_get_string_list (key_file,
                                     desktop_entry_group,
                                     "OnlyShowIn",
                                     NULL,
                                     NULL);
  if (strv)
    {
      show_in_mate = FALSE;
      for (i = 0; strv[i]; i++)
        {
          if (!strcmp (strv[i], "MATE"))
            {
              show_in_mate = TRUE;
              break;
            }
        }
    }
  else
    {
      strv = g_key_file_get_string_list (key_file,
                                         desktop_entry_group,
                                         "NotShowIn",
                                         NULL,
                                         NULL);
      if (strv)
        {
          show_in_mate = TRUE;
          for (i = 0; strv[i]; i++)
            {
              if (!strcmp (strv[i], "MATE"))
                {
                  show_in_mate = FALSE;
                }
            }
        }
    }
  g_strfreev (strv);

  tryexec_failed = FALSE;
  tryexec = g_key_file_get_string (key_file,
                                   desktop_entry_group,
                                   "TryExec",
                                   NULL);
  if (tryexec)
    {
      char *path;

      path = g_find_program_in_path (g_strstrip (tryexec));

      tryexec_failed = (path == NULL);

      g_free (path);
      g_free (tryexec);
    }

  flags = 0;
  if (no_display)
    flags |= DESKTOP_ENTRY_NO_DISPLAY;
  if (hidden)
    flags |= DESKTOP_ENTRY_HIDDEN;
  if (show_in_mate)
    flags |= DESKTOP_ENTRY_SHOW_IN_MATE;
  if (tryexec_failed)
    flags |= DESKTOP_ENTRY_TRYEXEC_FAILED;

  return flags;
}
示例#9
0
/* read config from disk */
int
read_config (window_board_t *win)
{
	char rcfile[1024];
	snprintf (rcfile, sizeof (rcfile), "%s/%s",
		g_get_user_config_dir (), "tenacerc");

	if (! g_key_file_load_from_file (win->keyfile, rcfile,
		G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL) &&
	    ! g_key_file_load_from_data_dirs (win->keyfile, "tenacerc", NULL,
		G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL)
	) {
		return 0;
	}

	/* Card display */

	char *p;
	if ((p = g_key_file_get_string (win->keyfile, "tenace", "show_as", NULL))) {
		win->hand_display_style = !strcmp (p, "cards") ?
			HAND_DISPLAY_STYLE_CARDS : HAND_DISPLAY_STYLE_TEXT;
	} else {
		win->hand_display_style = HAND_DISPLAY_STYLE_CARDS;
	}
	if (win->svg)
		g_free (win->svg);
	if ((p = g_key_file_get_string (win->keyfile, "tenace", "svg", NULL))) {
		win->svg = p;
	} else {
		win->svg = NULL;
	}
	int i;
	if ((i = g_key_file_get_integer (win->keyfile, "tenace", "card_width", NULL))) {
		win->card_width = i;
	}
	if ((i = g_key_file_get_boolean (win->keyfile, "tenace", "show_played_cards", NULL))) {
		win->show_played_cards = i;
	}

	/* Hands */

	if ((p = g_key_file_get_string (win->keyfile, "tenace", "show_hands", NULL))) {
		if (! strcmp (p, "none"))
			win->show_hands = seat_none;
		else if (! strcmp (p, "ns"))
			win->show_hands = north_south;
		else if (! strcmp (p, "ew"))
			win->show_hands = east_west;
		else
			win->show_hands = seat_all;
	}
	if ((p = g_key_file_get_string (win->keyfile, "tenace", "show_dd", NULL))) {
		if (! strcmp (p, "none"))
			win->show_dd_scores = seat_none;
		else if (! strcmp (p, "ns"))
			win->show_dd_scores = north_south;
		else if (! strcmp (p, "ew"))
			win->show_dd_scores = east_west;
		else
			win->show_dd_scores = seat_all;
	}

	return 1;
}
示例#10
0
/* returns FALSE if object is not (or no longer) valid */
static gboolean
update_account_object (GoaDaemon           *daemon,
                       GoaObjectSkeleton   *object,
                       const gchar         *path,
                       const gchar         *group,
                       GKeyFile            *key_file,
                       gboolean             just_added)
{
  GoaAccount *account;
  GoaProvider *provider;
  gboolean is_locked;
  gboolean ret;
  gchar *identity;
  gchar *presentation_identity;
  gchar *type;
  gchar *name;
  GIcon *icon;
  gchar *serialized_icon;
  GError *error;

  g_return_val_if_fail (GOA_IS_DAEMON (daemon), FALSE);
  g_return_val_if_fail (G_IS_DBUS_OBJECT_SKELETON (object), FALSE);
  g_return_val_if_fail (group != NULL, FALSE);
  g_return_val_if_fail (key_file != NULL, FALSE);

  ret = FALSE;
  identity = NULL;
  type = NULL;
  account = NULL;
  name = NULL;
  icon = NULL;
  serialized_icon = NULL;

  g_debug ("updating %s %d", g_dbus_object_get_object_path (G_DBUS_OBJECT (object)), just_added);

  type = g_key_file_get_string (key_file, group, "Provider", NULL);
  identity = g_key_file_get_string (key_file, group, "Identity", NULL);
  presentation_identity = g_key_file_get_string (key_file, group, "PresentationIdentity", NULL);
  is_locked = g_key_file_get_boolean (key_file, group, "IsLocked", NULL);
  if (just_added)
    {
      account = goa_account_skeleton_new ();
      goa_object_skeleton_set_account (object, account);
    }
  else
    {
      account = goa_object_get_account (GOA_OBJECT (object));
    }

  provider = goa_provider_get_for_provider_type (type);
  if (provider == NULL)
    {
      g_warning ("Unsupported account type %s for identity %s (no provider)", type, identity);
      goto out;
    }

  goa_account_set_id (account, g_strrstr (g_dbus_object_get_object_path (G_DBUS_OBJECT (object)), "/") + 1);
  goa_account_set_provider_type (account, type);
  goa_account_set_identity (account, identity);
  goa_account_set_presentation_identity (account, presentation_identity);
  goa_account_set_is_locked (account, is_locked);

  error = NULL;
  if (!goa_provider_build_object (provider, object, key_file, group, daemon->connection, just_added, &error))
    {
      g_warning ("Error parsing account: %s (%s, %d)",
                 error->message, g_quark_to_string (error->domain), error->code);
      g_error_free (error);
      goto out;
    }

  name = goa_provider_get_provider_name (provider, GOA_OBJECT (object));
  goa_account_set_provider_name (account, name);

  icon = goa_provider_get_provider_icon (provider, GOA_OBJECT (object));
  serialized_icon = g_icon_to_string (icon);
  goa_account_set_provider_icon (account, serialized_icon);

  ret = TRUE;

 out:
  g_free (serialized_icon);
  if (icon != NULL)
    g_object_unref (icon);
  g_free (name);
  if (provider != NULL)
    g_object_unref (provider);
  g_object_unref (account);
  g_free (type);
  g_free (identity);
  g_free (presentation_identity);
  return ret;
}
static DesktopEntry *
desktop_entry_load (DesktopEntry *entry)
{
  DesktopEntry *retval = NULL;
  GKeyFile     *key_file;
  GError       *error;
  const char   *desktop_entry_group;
  char         *name_str;
  char         *type_str;

  key_file = g_key_file_new ();

  error = NULL;
  if (!g_key_file_load_from_file (key_file, entry->path, 0, &error))
    {
      menu_verbose ("Failed to load \"%s\": %s\n",
                    entry->path, error->message);
      g_error_free (error);
      goto out;
    }

  if (g_key_file_has_group (key_file, DESKTOP_ENTRY_GROUP))
    {
      desktop_entry_group = DESKTOP_ENTRY_GROUP;
    }
  else
    {
      menu_verbose ("\"%s\" contains no \"" DESKTOP_ENTRY_GROUP "\" group\n",
                    entry->path);

      if (g_key_file_has_group (key_file, KDE_DESKTOP_ENTRY_GROUP))
        {
          desktop_entry_group = KDE_DESKTOP_ENTRY_GROUP;
          menu_verbose ("\"%s\" contains deprecated \"" KDE_DESKTOP_ENTRY_GROUP "\" group\n",
                        entry->path);
        }
      else
        {
          goto out;
        }
    }

  if (!g_key_file_has_key (key_file, desktop_entry_group, "Name", NULL))
    {
      menu_verbose ("\"%s\" contains no \"Name\" key\n", entry->path);
      goto out;
    }

  name_str = g_key_file_get_locale_string (key_file, desktop_entry_group, "Name", NULL, NULL);
  if (!name_str)
    {
      menu_verbose ("\"%s\" contains an invalid \"Name\" key\n", entry->path);
      goto out;
    }

  g_free (name_str);

  type_str = g_key_file_get_string (key_file, desktop_entry_group, "Type", NULL);
  if (!type_str)
    {
      menu_verbose ("\"%s\" contains no \"Type\" key\n", entry->path);
      goto out;
    }

  if ((entry->type == DESKTOP_ENTRY_DESKTOP && strcmp (type_str, "Application") != 0) ||
      (entry->type == DESKTOP_ENTRY_DIRECTORY && strcmp (type_str, "Directory") != 0))
    {
      menu_verbose ("\"%s\" does not contain the correct \"Type\" value\n", entry->path);
      g_free (type_str);
      goto out;
    }

  g_free (type_str);

  if (entry->type == DESKTOP_ENTRY_DESKTOP &&
      !g_key_file_has_key (key_file, desktop_entry_group, "Exec", NULL))
    {
      menu_verbose ("\"%s\" does not contain an \"Exec\" key\n", entry->path);
      goto out;
    }

  retval = entry;

#define GET_LOCALE_STRING(n) g_key_file_get_locale_string (key_file, desktop_entry_group, (n), NULL, NULL)

  retval->name         = GET_LOCALE_STRING ("Name");
  retval->generic_name = GET_LOCALE_STRING ("GenericName");
  retval->full_name    = GET_LOCALE_STRING ("X-MATE-FullName");
  retval->comment      = GET_LOCALE_STRING ("Comment");
  retval->icon         = GET_LOCALE_STRING ("Icon");
  retval->flags        = get_flags_from_key_file (retval, key_file, desktop_entry_group);
  retval->categories   = get_categories_from_key_file (retval, key_file, desktop_entry_group);

  if (entry->type == DESKTOP_ENTRY_DESKTOP)
    {
      retval->exec = g_key_file_get_string (key_file, desktop_entry_group, "Exec", NULL);
      retval->terminal = g_key_file_get_boolean (key_file, desktop_entry_group, "Terminal", NULL);
    }

#undef GET_LOCALE_STRING

  menu_verbose ("Desktop entry \"%s\" (%s, %s, %s, %s, %s) flags: NoDisplay=%s, Hidden=%s, ShowInMATE=%s, TryExecFailed=%s\n",
                retval->basename,
                retval->name,
                retval->generic_name ? retval->generic_name : "(null)",
                retval->full_name ? retval->full_name : "(null)",
                retval->comment ? retval->comment : "(null)",
                retval->icon ? retval->icon : "(null)",
                retval->flags & DESKTOP_ENTRY_NO_DISPLAY     ? "(true)" : "(false)",
                retval->flags & DESKTOP_ENTRY_HIDDEN         ? "(true)" : "(false)",
                retval->flags & DESKTOP_ENTRY_SHOW_IN_MATE  ? "(true)" : "(false)",
                retval->flags & DESKTOP_ENTRY_TRYEXEC_FAILED ? "(true)" : "(false)");

 out:
  g_key_file_free (key_file);

  if (!retval)
    desktop_entry_unref (entry);

  return retval;
}
示例#12
0
static void
add_config_file (GoaDaemon     *daemon,
                 const gchar   *path,
                 GHashTable    *group_name_to_key_file_data,
                 GList        **key_files_to_free)
{
  GKeyFile *key_file;
  GError *error;

  key_file = g_key_file_new ();

  error = NULL;
  if (!g_key_file_load_from_file (key_file,
                                  path,
                                  G_KEY_FILE_NONE,
                                  &error))
    {
      if (!(error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT))
        {
          g_warning ("Error loading %s: %s (%s, %d)",
                     path,
                     error->message, g_quark_to_string (error->domain), error->code);
        }
      g_error_free (error);
      g_key_file_free (key_file);
    }
  else
    {
      gchar **groups;
      const char *guid;
      gsize num_groups;
      guint n;

      guid = g_dbus_connection_get_guid (daemon->connection);
      groups = g_key_file_get_groups (key_file, &num_groups);
      for (n = 0; n < num_groups; n++)
        {
          if (g_str_has_prefix (groups[n], "Account "))
            {
              gboolean is_temporary;
              char *session_id;

              is_temporary = g_key_file_get_boolean (key_file,
                                                     groups[n],
                                                     "IsTemporary",
                                                     NULL);

              if (is_temporary)
                {
                  session_id = g_key_file_get_string (key_file,
                                                      groups[n],
                                                      "SessionId",
                                                      NULL);

                  /* discard temporary accounts from older sessions */
                  if (session_id != NULL &&
                      g_strcmp0 (session_id, guid) != 0)
                    {
                      g_debug ("ignoring account \"%s\" in file %s because it's stale",
                               groups[n], path);
                      g_free (groups[n]);
                      g_free (session_id);
                      continue;
                    }
                  g_free (session_id);
                }
              else
                {
                  g_key_file_remove_key (key_file, groups[n], "SessionId", NULL);
                }

              g_hash_table_insert (group_name_to_key_file_data,
                                   groups[n], /* steals string */
                                   key_file_data_new (key_file, path));
            }
          else
            {
              g_warning ("Unexpected group \"%s\" in file %s", groups[n], path);
              g_free (groups[n]);
            }
        }
      g_free (groups);

      *key_files_to_free = g_list_prepend (*key_files_to_free, key_file);
    }
}
示例#13
0
文件: main.c 项目: bitptr/bytestream
/*
 * Insert all desktop files in a directory into the GtkListStore.
 */
void
apps_list_insert_files(GtkListStore *apps, GHashTable *entry_files, char *dir,
    DIR *dirp, size_t len)
{
	char		*fn = NULL, *name_v = NULL, *exec_v = NULL;
	char		*icon_v = NULL;
	int		 ret;
	size_t		 len_name, len_fn;
	uint8_t		 field_code_flags;
	struct dirent	*dp;
	GKeyFile	*key_file = NULL;
	GError		*error = NULL;
	gboolean	 nodisplay_v, hidden_v, use_term_v;

	while ((dp = readdir(dirp)) != NULL) {
		len_name = strlen(dp->d_name);
		if (len_name <= 8)
			goto cont;
		if (strncmp(dp->d_name + len_name - 8, ".desktop", 8) != 0)
			goto cont;

		len_fn = len_name + len + 1;
		if ((fn = calloc(len_fn, sizeof(char))) == NULL)
			err(1, NULL);
		ret = snprintf(fn, len_fn, "%s/%s", dir, dp->d_name);
		if (ret < 0 || (size_t)ret >= len_fn)
			err(1, NULL);

		key_file = g_key_file_new();
		if (!g_key_file_load_from_file(key_file, fn, G_KEY_FILE_NONE, &error))
			errx(1, "%s", error->message);

		nodisplay_v = g_key_file_get_boolean(key_file,
		    G_KEY_FILE_DESKTOP_GROUP,
		    G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, NULL);
		if (nodisplay_v != FALSE)
			goto cont;

		name_v = g_key_file_get_locale_string(key_file,
		    G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME,
		    NULL, &error);
		if (name_v == NULL) {
			warnx("g_key_file_get_locale_string: %s",
			    error->message);
			g_clear_error(&error);
			goto cont;
		}

		if (!g_hash_table_add(entry_files, strdup(name_v)))
			goto cont;

		hidden_v = g_key_file_get_boolean(key_file,
		    G_KEY_FILE_DESKTOP_GROUP,
		    G_KEY_FILE_DESKTOP_KEY_HIDDEN, NULL);
		if (hidden_v != FALSE)
			goto cont;

		exec_v = g_key_file_get_locale_string(key_file,
		    G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC,
		    NULL, &error);
		if (exec_v == NULL) {
			warnx("g_key_file_get_locale_string: %s",
			    error->message);
			g_clear_error(&error);
			goto cont;
		}

		field_code_flags = field_codes(exec_v);

		icon_v = g_key_file_get_locale_string(key_file,
		    G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON,
		    NULL, &error);
		g_clear_error(&error);

		use_term_v = g_key_file_get_boolean(key_file,
		    G_KEY_FILE_DESKTOP_GROUP,
		    G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);
		g_clear_error(&error);

		gtk_list_store_insert_with_values(apps, NULL, -1,
		    NAME_COLUMN, name_v,
		    EXEC_COLUMN, exec_v,
		    FCODE_COLUMN, field_code_flags,
		    ICON_COLUMN, icon_v,
		    TERM_COLUMN, use_term_v,
		    -1);

cont:
		free(exec_v); exec_v = NULL;
		free(name_v); name_v = NULL;
		free(icon_v); icon_v = NULL;
		free(fn); fn = NULL;
		if (key_file) {
			g_key_file_free(key_file);
			key_file = NULL;
		}
	}
}
示例#14
0
gboolean
brasero_setting_load (BraseroSetting *setting)
{
	BraseroSettingPrivate *priv;
	GKeyFile *key_file;
	gboolean res;
	gchar *path;

	priv = BRASERO_SETTING_PRIVATE (setting);

	path = g_build_path (G_DIR_SEPARATOR_S,
	                     g_get_user_config_dir (),
	                     "brasero",
	                     "application-settings",
	                     NULL);

	key_file = g_key_file_new ();
	res = g_key_file_load_from_file (key_file,
	                                 path,
	                                 G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
	                                 NULL);
	g_free (path);
	if (!res)
		return res;

	priv->search_entry_history = g_key_file_get_string_list (key_file,
	                                                         "Filter",
	                                                         "history",
	                                                         NULL,
	                                                         NULL);

	priv->layout_audio = g_key_file_get_string (key_file,
	                                            "Display",
	                                            "layout-audio",
	                                            NULL);
	priv->layout_video = g_key_file_get_string (key_file,
	                                            "Display",
	                                            "layout-video",
	                                            NULL);
	priv->layout_data = g_key_file_get_string (key_file,
	                                           "Display",
	                                           "layout-data",
	                                           NULL);
	priv->show_sidepane = g_key_file_get_boolean (key_file,
	                                              "Display",
	                                              "show-sidepane",
	                                              NULL);
	priv->show_preview = g_key_file_get_boolean (key_file,
	                                             "Display",
	                                             "show-preview",
	                                             NULL);

	priv->win_width = g_key_file_get_integer (key_file,
	                                          "Display",
	                                          "main-window-width",
	                                          NULL);
	priv->win_height = g_key_file_get_integer (key_file,
	                                           "Display",
	                                           "main-window-height",
	                                           NULL);
	priv->win_maximized = g_key_file_get_boolean (key_file,
	                                             "Display",
	                                             "main-window-maximized",
	                                             NULL);
	priv->stock_file_chooser_percent = brasero_setting_get_integer (key_file,
	                                                                "Display",
	                                                                "stock-file-chooser-percent");
	priv->brasero_file_chooser_percent = brasero_setting_get_integer (key_file,
	                                                                  "Display",
	                                                                  "brasero-file-chooser-percent");
	priv->player_volume = g_key_file_get_integer (key_file,
	                                              "Player",
	                                              "player-volume",
	                                              NULL);
	priv->display_layout = g_key_file_get_integer (key_file,
	                                              "Display",
	                                              "layout",
	                                              NULL);
	priv->data_disc_column = g_key_file_get_integer (key_file,
	                                                 "Display",
	                                                 "data-disc-column",
	                                                 NULL);
	priv->data_disc_column_order = g_key_file_get_integer (key_file,
	                                                       "Display",
	                                                       "data-disc-column-order",
	                                                       NULL);
	priv->image_size_width = g_key_file_get_integer (key_file,
	                                                 "Player",
	                                                 "image-size-width",
	                                                 NULL);
	priv->image_size_height = g_key_file_get_integer (key_file,
	                                                  "Player",
	                                                  "image-size-height",
	                                                  NULL);
	priv->video_size_width = g_key_file_get_integer (key_file,
	                                                 "Player",
	                                                 "video-size-width",
	                                                 NULL);
	priv->video_size_height = g_key_file_get_integer (key_file,
	                                                  "Player",
	                                                  "video-size-height",
	                                                  NULL);
	priv->display_proportion = brasero_setting_get_integer (key_file,
	                                                        "Display",
	                                                        "pane-position");
	g_key_file_free (key_file);

	return TRUE;
}
static char *
start_startup_notification (GdkDisplay     *display,
			    EggDesktopFile *desktop_file,
			    const char     *argv0,
			    int             screen,
			    int             workspace,
			    guint32         launch_time)
{
  static int sequence = 0;
  char *startup_id;
  char *description, *wmclass;
  char *screen_str, *workspace_str;

  if (g_key_file_has_key (desktop_file->key_file,
			  EGG_DESKTOP_FILE_GROUP,
			  EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
			  NULL))
    {
      if (!g_key_file_get_boolean (desktop_file->key_file,
				   EGG_DESKTOP_FILE_GROUP,
				   EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
				   NULL))
	return NULL;
      wmclass = NULL;
    }
  else
    {
      wmclass = g_key_file_get_string (desktop_file->key_file,
				       EGG_DESKTOP_FILE_GROUP,
				       EGG_DESKTOP_FILE_KEY_STARTUP_WM_CLASS,
				       NULL);
      if (!wmclass)
	return NULL;
    }

  if (launch_time == (guint32)-1)
    launch_time = gdk_x11_display_get_user_time (display);
  startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu",
				g_get_prgname (),
				(unsigned long)getpid (),
				g_get_host_name (),
				argv0,
				sequence++,
				(unsigned long)launch_time);

  description = g_strdup_printf (_("Starting %s"), desktop_file->name);
  screen_str = g_strdup_printf ("%d", screen);
  workspace_str = workspace == -1 ? NULL : g_strdup_printf ("%d", workspace);

  gdk_x11_display_broadcast_startup_message (display, "new",
					     "ID", startup_id,
					     "NAME", desktop_file->name,
					     "SCREEN", screen_str,
					     "BIN", argv0,
					     "ICON", desktop_file->icon,
					     "DESKTOP", workspace_str,
					     "DESCRIPTION", description,
					     "WMCLASS", wmclass,
					     NULL);

  g_free (description);
  g_free (wmclass);
  g_free (screen_str);
  g_free (workspace_str);

  return startup_id;
}
示例#16
0
文件: gxkb.c 项目: zen-tools/gxkb
gboolean
xkb_load_config( t_xkb_settings *xkb, const gchar *filename )
{
    GKeyFile *cfg_file = g_key_file_new();
    if( !g_key_file_load_from_file( cfg_file, filename, G_KEY_FILE_KEEP_COMMENTS, NULL ) )
    {
        g_key_file_free( cfg_file );
        return FALSE;
    }

    xkb->group_policy = g_key_file_get_integer(
        cfg_file,
        "xkb config",
        "group_policy",
        NULL
    );

    if( xkb->group_policy != GROUP_POLICY_GLOBAL )
    {
        xkb->default_group = g_key_file_get_integer(
            cfg_file,
            "xkb config",
            "default_group",
            NULL
        );
    }

    xkb->never_modify_config = g_key_file_get_boolean(
        cfg_file,
        "xkb config",
        "never_modify_config",
        NULL
    );

    if( xkb->kbd_config == NULL )
        xkb->kbd_config = g_new0( t_xkb_kbd_config, 1 );


    xkb->kbd_config->model = g_key_file_get_string(
        cfg_file,
        "xkb config",
        "model",
        NULL
    );

    xkb->kbd_config->layouts = g_key_file_get_string(
        cfg_file,
        "xkb config",
        "layouts",
        NULL
    );

    xkb->kbd_config->variants = g_key_file_get_string(
        cfg_file,
        "xkb config",
        "variants",
        NULL
    );

    xkb->kbd_config->toggle_option = g_key_file_get_string(
        cfg_file,
        "xkb config",
        "toggle_option",
        NULL
    );

    xkb->kbd_config->compose_key_position = g_key_file_get_string(
        cfg_file,
        "xkb config",
        "compose_key_position",
        NULL
    );

    g_key_file_free( cfg_file );

    return TRUE;
}
示例#17
0
static void
load_httpserver_config (SeafileSession *session)
{
    GError *error = NULL;
    char *host = NULL;
    int port = 0;
    int max_upload_size_mb;
    int max_download_dir_size_mb;

    host = g_key_file_get_string (session->config, "httpserver", "host", &error);
    if (!error) {
        bind_addr = host;
    } else {
        if (error->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
            error->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND) {
            seaf_warning ("[conf] Error: failed to read the value of 'host'\n");
            exit (1);
        }

        bind_addr = DEFAULT_BIND_HOST;
        g_clear_error (&error);
    }

    port = g_key_file_get_integer (session->config, "httpserver", "port", &error);
    if (!error) {
        bind_port = port;
    } else {
        if (error->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
            error->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND) {
            seaf_warning ("[conf] Error: failed to read the value of 'port'\n");
            exit (1);
        }

        bind_port = DEFAULT_BIND_PORT;
        g_clear_error (&error);
    }

    use_https = g_key_file_get_boolean (session->config,
                                        "httpserver", "https",
                                        &error);
    if (error) {
        if (error->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
            error->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND) {
            seaf_warning ("[conf] Error: failed to read the value of 'https'\n");
            exit (1);
        }

        /* There is no <https> field in seafile.conf, so we use http. */
        g_clear_error (&error);

    } else if (use_https) {
        /* read https config */
        pemfile = g_key_file_get_string (session->config,
                                         "httpserver", "pemfile",
                                         &error);
        if (error) {
            seaf_warning ("[conf] Error: https is true, "
                          "but the value of pemfile is unknown\n");
            exit (1);
        }

        privkey = g_key_file_get_string (session->config,
                                         "httpserver", "privkey",
                                         &error);
        if (error) {
            seaf_warning ("[conf] Error: https is true, "
                          "but the value of privkey is unknown\n");
            exit (1);
        }
    }

    max_upload_size_mb = g_key_file_get_integer (session->config,
                                                 "httpserver",
                                                 "max_upload_size",
                                                 &error);
    if (error) {
        session->max_upload_size = -1; /* no limit */
        g_clear_error (&error);
    } else {
        if (max_upload_size_mb <= 0)
            session->max_upload_size = -1; /* no limit */
        else
            session->max_upload_size = max_upload_size_mb * ((gint64)1 << 20);
    }

    max_download_dir_size_mb = g_key_file_get_integer (session->config,
                                                 "httpserver",
                                                 "max_download_dir_size",
                                                 &error);
    if (error) {
        session->max_download_dir_size = DEFAULT_MAX_DOWNLOAD_DIR_SIZE;
        g_clear_error (&error);
    } else {
        if (max_download_dir_size_mb <= 0)
            session->max_download_dir_size = DEFAULT_MAX_DOWNLOAD_DIR_SIZE;
        else
            session->max_download_dir_size = max_download_dir_size_mb * ((gint64)1 << 20);
    }
}
static void
read_one_setting_value (NMSetting *setting,
                        const char *key,
                        const GValue *value,
                        GParamFlags flags,
                        gpointer user_data)
{
	GKeyFile *file = user_data;
	const char *setting_name;
	GType type;
	GError *err = NULL;
	gboolean check_for_key = TRUE;
	KeyParser *parser = &key_parsers[0];

	/* Property is not writable */
	if (!(flags & G_PARAM_WRITABLE))
		return;

	/* Setting name gets picked up from the keyfile's section name instead */
	if (!strcmp (key, NM_SETTING_NAME))
		return;

	/* Don't read the NMSettingConnection object's 'read-only' property */
	if (   NM_IS_SETTING_CONNECTION (setting)
	    && !strcmp (key, NM_SETTING_CONNECTION_READ_ONLY))
		return;

	setting_name = nm_setting_get_name (setting);

	/* Look through the list of handlers for non-standard format key values */
	while (parser->setting_name) {
		if (!strcmp (parser->setting_name, setting_name) && !strcmp (parser->key, key)) {
			check_for_key = parser->check_for_key;
			break;
		}
		parser++;
	}

	/* VPN properties don't have the exact key name */
	if (NM_IS_SETTING_VPN (setting))
		check_for_key = FALSE;

	/* Check for the exact key in the GKeyFile if required.  Most setting
	 * properties map 1:1 to a key in the GKeyFile, but for those properties
	 * like IP addresses and routes where more than one value is actually
	 * encoded by the setting property, this won't be true.
	 */
	if (check_for_key && !g_key_file_has_key (file, setting_name, key, &err)) {
		/* Key doesn't exist or an error ocurred, thus nothing to do. */
		if (err) {
			g_warning ("Error loading setting '%s' value: %s", setting_name, err->message);
			g_error_free (err);
		}
		return;
	}

	/* If there's a custom parser for this key, handle that before the generic
	 * parsers below.
	 */
	if (parser && parser->setting_name) {
		(*parser->parser) (setting, key, file);
		return;
	}

	type = G_VALUE_TYPE (value);

	if (type == G_TYPE_STRING) {
		char *str_val;

		str_val = g_key_file_get_string (file, setting_name, key, NULL);
		g_object_set (setting, key, str_val, NULL);
		g_free (str_val);
	} else if (type == G_TYPE_UINT) {
		int int_val;

		int_val = g_key_file_get_integer (file, setting_name, key, NULL);
		if (int_val < 0)
			g_warning ("Casting negative value (%i) to uint", int_val);
		g_object_set (setting, key, int_val, NULL);
	} else if (type == G_TYPE_INT) {
		int int_val;

		int_val = g_key_file_get_integer (file, setting_name, key, NULL);
		g_object_set (setting, key, int_val, NULL);
	} else if (type == G_TYPE_BOOLEAN) {
		gboolean bool_val;

		bool_val = g_key_file_get_boolean (file, setting_name, key, NULL);
		g_object_set (setting, key, bool_val, NULL);
	} else if (type == G_TYPE_CHAR) {
		int int_val;

		int_val = g_key_file_get_integer (file, setting_name, key, NULL);
		if (int_val < G_MININT8 || int_val > G_MAXINT8)
			g_warning ("Casting value (%i) to char", int_val);

		g_object_set (setting, key, int_val, NULL);
	} else if (type == G_TYPE_UINT64) {
		char *tmp_str;
		guint64 uint_val;

		tmp_str = g_key_file_get_value (file, setting_name, key, NULL);
		uint_val = g_ascii_strtoull (tmp_str, NULL, 10);
		g_free (tmp_str);
		g_object_set (setting, key, uint_val, NULL);
 	} else if (type == DBUS_TYPE_G_UCHAR_ARRAY) {
		gint *tmp;
		GByteArray *array;
		gsize length;
		int i;

		tmp = g_key_file_get_integer_list (file, setting_name, key, &length, NULL);

		array = g_byte_array_sized_new (length);
		for (i = 0; i < length; i++) {
			int val = tmp[i];
			unsigned char v = (unsigned char) (val & 0xFF);

			if (val < 0 || val > 255) {
				g_warning ("%s: %s / %s ignoring invalid byte element '%d' (not "
				           " between 0 and 255 inclusive)", __func__, setting_name,
				           key, val);
			} else
				g_byte_array_append (array, (const unsigned char *) &v, sizeof (v));
		}

		g_object_set (setting, key, array, NULL);
		g_byte_array_free (array, TRUE);
		g_free (tmp);
 	} else if (type == DBUS_TYPE_G_LIST_OF_STRING) {
		gchar **sa;
		gsize length;
		int i;
		GSList *list = NULL;

		sa = g_key_file_get_string_list (file, setting_name, key, &length, NULL);
		for (i = 0; i < length; i++)
			list = g_slist_prepend (list, sa[i]);

		list = g_slist_reverse (list);
		g_object_set (setting, key, list, NULL);

		g_slist_free (list);
		g_strfreev (sa);
	} else if (type == DBUS_TYPE_G_MAP_OF_STRING) {
		read_hash_of_string (file, setting, key);
	} else if (type == DBUS_TYPE_G_UINT_ARRAY) {
		if (!read_array_of_uint (file, setting, key)) {
			g_warning ("Unhandled setting property type (read): '%s/%s' : '%s'",
					 setting_name, key, G_VALUE_TYPE_NAME (value));
		}
	} else {
		g_warning ("Unhandled setting property type (read): '%s/%s' : '%s'",
				 setting_name, key, G_VALUE_TYPE_NAME (value));
	}
}
示例#19
0
ProfAccount*
accounts_get_account(const char *const name)
{
    if (!g_key_file_has_group(accounts, name)) {
        return NULL;
    } else {
        gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);

        // fix accounts that have no jid property by setting to name
        if (jid == NULL) {
            g_key_file_set_string(accounts, name, "jid", name);
            _save_accounts();
        }

        gchar *password = g_key_file_get_string(accounts, name, "password", NULL);
        gchar *eval_password = g_key_file_get_string(accounts, name, "eval_password", NULL);
        gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);

        gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
        gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
        int port = g_key_file_get_integer(accounts, name, "port", NULL);

        gchar *last_presence = g_key_file_get_string(accounts, name, "presence.last", NULL);
        gchar *login_presence = g_key_file_get_string(accounts, name, "presence.login", NULL);

        int priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL);
        int priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL);
        int priority_away = g_key_file_get_integer(accounts, name, "priority.away", NULL);
        int priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL);
        int priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL);

        gchar *muc_service = NULL;
        if (g_key_file_has_key(accounts, name, "muc.service", NULL)) {
            muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
        } else {
            jabber_conn_status_t conn_status = connection_get_status();
            if (conn_status == JABBER_CONNECTED) {
                char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
                if (conf_jid) {
                    muc_service = strdup(conf_jid);
                }
            }
        }
        gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);

        gchar *otr_policy = NULL;
        if (g_key_file_has_key(accounts, name, "otr.policy", NULL)) {
            otr_policy = g_key_file_get_string(accounts, name, "otr.policy", NULL);
        }

        gsize length;
        GList *otr_manual = NULL;
        gchar **manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
        if (manual) {
            int i = 0;
            for (i = 0; i < length; i++) {
                otr_manual = g_list_append(otr_manual, strdup(manual[i]));
            }
            g_strfreev(manual);
        }

        GList *otr_opportunistic = NULL;
        gchar **opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
        if (opportunistic) {
            int i = 0;
            for (i = 0; i < length; i++) {
                otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i]));
            }
            g_strfreev(opportunistic);
        }

        GList *otr_always = NULL;
        gchar **always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
        if (always) {
            int i = 0;
            for (i = 0; i < length; i++) {
                otr_always = g_list_append(otr_always, strdup(always[i]));
            }
            g_strfreev(always);
        }

        gchar *pgp_keyid = NULL;
        if (g_key_file_has_key(accounts, name, "pgp.keyid", NULL)) {
            pgp_keyid = g_key_file_get_string(accounts, name, "pgp.keyid", NULL);
        }

        gchar *startscript = NULL;
        if (g_key_file_has_key(accounts, name, "script.start", NULL)) {
            startscript = g_key_file_get_string(accounts, name, "script.start", NULL);
        }

        gchar *theme = NULL;
        if (g_key_file_has_key(accounts, name, "theme", NULL)) {
            theme = g_key_file_get_string(accounts, name, "theme", NULL);
        }

        gchar *tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL);
        if (tls_policy && ((g_strcmp0(tls_policy, "force") != 0) &&
                (g_strcmp0(tls_policy, "allow") != 0) &&
                (g_strcmp0(tls_policy, "disable") != 0) &&
                (g_strcmp0(tls_policy, "legacy") != 0))) {
            g_free(tls_policy);
            tls_policy = NULL;
        }

        ProfAccount *new_account = account_new(name, jid, password, eval_password, enabled,
            server, port, resource, last_presence, login_presence,
            priority_online, priority_chat, priority_away, priority_xa,
            priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
            otr_opportunistic, otr_always, pgp_keyid, startscript, theme, tls_policy);

        g_free(jid);
        g_free(password);
        g_free(eval_password);
        g_free(server);
        g_free(resource);
        g_free(last_presence);
        g_free(login_presence);
        g_free(muc_service);
        g_free(muc_nick);
        g_free(otr_policy);
        g_free(pgp_keyid);
        g_free(startscript);
        g_free(theme);
        g_free(tls_policy);

        return new_account;
    }
}
示例#20
0
int audio_manager_init(DBusConnection *conn, GKeyFile *conf,
							gboolean *enable_sco)
{
	char **list;
	int i;
	char *str;
	gboolean b;
	GError *err = NULL;

	connection = dbus_connection_ref(conn);

	if (!conf)
		goto proceed;

	config = conf;

	list = g_key_file_get_string_list(config, "General", "Enable",
						NULL, NULL);
	for (i = 0; list && list[i] != NULL; i++) {
		if (g_str_equal(list[i], "Headset"))
			enabled.headset = TRUE;
		else if (g_str_equal(list[i], "Gateway"))
			enabled.gateway = TRUE;
		else if (g_str_equal(list[i], "Sink"))
			enabled.sink = TRUE;
		else if (g_str_equal(list[i], "Source"))
			enabled.source = TRUE;
		else if (g_str_equal(list[i], "Control"))
			enabled.control = TRUE;
		else if (g_str_equal(list[i], "Socket"))
			enabled.socket = TRUE;
		else if (g_str_equal(list[i], "Media"))
			enabled.media = TRUE;
	}
	g_strfreev(list);

	list = g_key_file_get_string_list(config, "General", "Disable",
						NULL, NULL);
	for (i = 0; list && list[i] != NULL; i++) {
		if (g_str_equal(list[i], "Headset"))
			enabled.headset = FALSE;
		else if (g_str_equal(list[i], "Gateway"))
			enabled.gateway = FALSE;
		else if (g_str_equal(list[i], "Sink"))
			enabled.sink = FALSE;
		else if (g_str_equal(list[i], "Source"))
			enabled.source = FALSE;
		else if (g_str_equal(list[i], "Control"))
			enabled.control = FALSE;
		else if (g_str_equal(list[i], "Socket"))
			enabled.socket = FALSE;
		else if (g_str_equal(list[i], "Media"))
			enabled.media = FALSE;
	}
	g_strfreev(list);

	b = g_key_file_get_boolean(config, "General", "AutoConnect", &err);
	if (err) {
		DBG("audio.conf: %s", err->message);
		g_clear_error(&err);
	} else
		auto_connect = b;

	b = g_key_file_get_boolean(config, "Headset", "HFP",
					&err);
	if (err)
		g_clear_error(&err);
	else
		enabled.hfp = b;

	err = NULL;
	i = g_key_file_get_integer(config, "Headset", "MaxConnected",
					&err);
	if (err) {
		DBG("audio.conf: %s", err->message);
		g_clear_error(&err);
	} else
		max_connected_headsets = i;

	str = g_key_file_get_string(config, "WBspeech",
						"I2sEnable", &err);
	if (err)
		g_clear_error(&err);
	else {
		wbs_commands_param.I2sEnable = strtol(str, NULL, 16);
	}

	str = g_key_file_get_string(config, "WBspeech",
						"IsMaster", &err);
	if (err)
		g_clear_error(&err);
	else {
		wbs_commands_param.IsMaster = strtol(str, NULL, 16);
	}

	str = g_key_file_get_string(config, "WBspeech",
						"ClockRate", &err);
	if (err)
		g_clear_error(&err);
	else {
		wbs_commands_param.ClockRate = strtol(str, NULL, 16);
	}


	str = g_key_file_get_string(config, "WBspeech",
						"PcmInterfaceRate", &err);
	if (err)
		g_clear_error(&err);
	else {
		wbs_commands_param.PcmInterfaceRate = strtol(str, NULL, 16);
	}

proceed:
	if (enabled.socket)
		unix_init();

	if (enabled.media)
		btd_register_adapter_driver(&media_server_driver);

	if (enabled.headset)
		btd_register_adapter_driver(&headset_server_driver);

	if (enabled.gateway)
		btd_register_adapter_driver(&gateway_server_driver);

	if (enabled.source || enabled.sink)
		btd_register_adapter_driver(&a2dp_server_driver);

	if (enabled.control)
		btd_register_adapter_driver(&avrcp_server_driver);

	btd_register_device_driver(&audio_driver);

	*enable_sco = (enabled.gateway || enabled.headset);

	return 0;
}
示例#21
0
/* Main code */
int main(int argc, char* argv[])
{
	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (window), "Suse Control Center");
	gtk_window_set_default_size (GTK_WINDOW (window), 650, 400);
	g_signal_connect(G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);

	bool is_root = getuid () == 0;

	View view;
	{  // adding groups
		GKeyFile *file = g_key_file_new();
		std::set <std::string> groups = subfiles (YAST_GROUPS);
		for (std::set <std::string>::iterator it = groups.begin();
		     it != groups.end(); it++) {
			if (!g_key_file_load_from_file (file, (YAST_GROUPS + (*it)).c_str(),
			                                G_KEY_FILE_NONE, NULL))
				continue;

			gchar* name = g_key_file_get_locale_string (file, "Desktop Entry", "Name", 0, NULL);
			gchar *nick = g_key_file_get_string (file, "Desktop Entry", "X-SuSE-YaST-Group", NULL);
			gchar *icon = g_key_file_get_string (file, "Desktop Entry", "Icon", NULL);
			gchar *sort_key = g_key_file_get_string (file, "Desktop Entry",
			                                         "X-SuSE-YaST-SortKey", NULL);
			if (name && nick)
				view.addGroup (name, icon, nick, sort_key);

			if (name)     g_free (name);
			if (nick)     g_free (nick);
			if (icon)     g_free (icon);
			if (sort_key) g_free (sort_key);
		}
		g_key_file_free (file);
	}
	{  // adding entries
		GKeyFile *file = g_key_file_new();
		std::set <std::string> entries = subfiles (YAST_ENTRIES);
		for (std::set <std::string>::iterator it = entries.begin();
		     it != entries.end(); it++) {
			if (!g_key_file_load_from_file (file, (YAST_ENTRIES + (*it)).c_str(),
			                                G_KEY_FILE_NONE, NULL))
				continue;

			gchar *group = g_key_file_get_string (file, "Desktop Entry", "X-SuSE-YaST-Group", NULL);
			gchar* name = g_key_file_get_locale_string (file, "Desktop Entry", "Name", 0, NULL);
			gchar *icon = g_key_file_get_string (file, "Desktop Entry", "Icon", NULL);
			gchar *command = g_key_file_get_string (file, "Desktop Entry", "Exec", NULL);
			gboolean needs_root = g_key_file_get_boolean (file, "Desktop Entry",
			                          "X-SuSE-YaST-RootOnly", NULL);

			if (group && name && command && (!needs_root || is_root))
				view.addEntry (group, name, icon, command);

			if (group)   g_free (group);
			if (name)    g_free (name);
			if (icon)    g_free (icon);
			if (command) g_free (command);
		}
		g_key_file_free (file);
	}

	gtk_container_add (GTK_CONTAINER (window), view.getWidget());
	gtk_widget_show_all (window);

	if (!is_root) {
		GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (window),
			GtkDialogFlags (0), GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
			"You are executing the control center as an ordinary user.\n"
			"Only a few modules will be available.");
		gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);
	}

	gtk_main();
	return 0;
}
示例#22
0
static int headset_server_init(struct audio_adapter *adapter)
{
	uint8_t chan = DEFAULT_HS_AG_CHANNEL;
	sdp_record_t *record;
	gboolean master = TRUE;
	GError *err = NULL;
	uint32_t features;
	GIOChannel *io;
	bdaddr_t src;

	if (config) {
		gboolean tmp;

		tmp = g_key_file_get_boolean(config, "General", "Master",
						&err);
		if (err) {
			DBG("audio.conf: %s", err->message);
			g_clear_error(&err);
		} else
			master = tmp;
	}

	adapter_get_address(adapter->btd_adapter, &src);

	io =  bt_io_listen(BT_IO_RFCOMM, NULL, ag_confirm, adapter, NULL, &err,
				BT_IO_OPT_SOURCE_BDADDR, &src,
				BT_IO_OPT_CHANNEL, chan,
				BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
				BT_IO_OPT_MASTER, master,
				BT_IO_OPT_INVALID);
	if (!io)
		goto failed;

	adapter->hsp_ag_server = io;

	record = hsp_ag_record(chan);
	if (!record) {
		error("Unable to allocate new service record");
		goto failed;
	}

	if (add_record_to_server(&src, record) < 0) {
		error("Unable to register HS AG service record");
		sdp_record_free(record);
		goto failed;
	}
	adapter->hsp_ag_record_id = record->handle;

	features = headset_config_init(config);

	if (!enabled.hfp)
		return 0;

	chan = DEFAULT_HF_AG_CHANNEL;

	io = bt_io_listen(BT_IO_RFCOMM, NULL, ag_confirm, adapter, NULL, &err,
				BT_IO_OPT_SOURCE_BDADDR, &src,
				BT_IO_OPT_CHANNEL, chan,
				BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
				BT_IO_OPT_MASTER, master,
				BT_IO_OPT_INVALID);
	if (!io)
		goto failed;

	adapter->hfp_ag_server = io;

	record = hfp_ag_record(chan, features);
	if (!record) {
		error("Unable to allocate new service record");
		goto failed;
	}

	if (add_record_to_server(&src, record) < 0) {
		error("Unable to register HF AG service record");
		sdp_record_free(record);
		goto failed;
	}
	adapter->hfp_ag_record_id = record->handle;

	return 0;

failed:
	if (err) {
		error("%s", err->message);
		g_error_free(err);
	}

	if (adapter->hsp_ag_server) {
		g_io_channel_shutdown(adapter->hsp_ag_server, TRUE, NULL);
		g_io_channel_unref(adapter->hsp_ag_server);
		adapter->hsp_ag_server = NULL;
	}

	if (adapter->hfp_ag_server) {
		g_io_channel_shutdown(adapter->hfp_ag_server, TRUE, NULL);
		g_io_channel_unref(adapter->hfp_ag_server);
		adapter->hfp_ag_server = NULL;
	}

	return -1;
}
示例#23
0
static void
load_config( GKeyFile *file )
{
    GKeyFile *config = pgm_main_window_get_config();

    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "AutoIndent", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( auto_indent ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "AutoIndent",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "IndentOnTab", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( indent_on_tab ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "IndentOnTab",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "ShowLineNumbers", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( show_line_numbers ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "ShowLineNumbers",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "SmartHomeEnd", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( smart_home_end ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "SmartHomeEnd",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "InsertSpacesInsteadOfTab", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( insert_spaces_instead_of_tabs ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "InsertSpacesInsteadOfTab",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "HighlightCurrentLine", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( highlight_current_line ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "HighlightCurrentLine",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "IndentWidth", NULL ) )
        gtk_spin_button_set_value( GTK_SPIN_BUTTON( indent_width_editor ),
                                   g_key_file_get_integer( config,
                                                           PGM_SQL_EDITOR_CONFIG_GROUP,
                                                           "IndentWidth",
                                                           NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "TabWidth", NULL ) )
        gtk_spin_button_set_value( GTK_SPIN_BUTTON( tab_width_editor ),
                                   g_key_file_get_integer( config,
                                                           PGM_SQL_EDITOR_CONFIG_GROUP,
                                                           "TabWidth",
                                                           NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "Font", NULL ) )
        gtk_font_button_set_font_name( GTK_FONT_BUTTON( font_editor ),
                                       g_key_file_get_string( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "Font",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "DrawSpaces", NULL ) )
        gtk_combo_box_set_active( GTK_COMBO_BOX( draw_spaces_editor ),
                                  g_key_file_get_integer( config,
                                                          PGM_SQL_EDITOR_CONFIG_GROUP,
                                                          "DrawSpaces",
                                                          NULL ) );
}
示例#24
0
static gboolean
as_app_parse_file_key (AsApp *app,
		       GKeyFile *kf,
		       const gchar *key,
		       AsAppParseFlags flags,
		       GError **error)
{
	guint i;
	guint j;
	g_autofree gchar *locale = NULL;
	g_autofree gchar *tmp = NULL;
	g_auto(GStrv) list = NULL;

	/* NoDisplay */
	if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY) == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && strcasecmp (tmp, "True") == 0)
			as_app_add_veto (app, "NoDisplay=true");

	/* Type */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_TYPE) == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (g_strcmp0 (tmp, G_KEY_FILE_DESKTOP_TYPE_APPLICATION) != 0) {
			g_set_error_literal (error,
					     AS_APP_ERROR,
					     AS_APP_ERROR_INVALID_TYPE,
					     "not an application");
			return FALSE;
		}

	/* Icon */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_ICON) == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0') {
			g_autoptr(AsIcon) icon = NULL;
			icon = as_app_desktop_create_icon (app, tmp, flags);
			as_app_add_icon (app, icon);
		}

	/* Categories */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_CATEGORIES) == 0) {
		list = g_key_file_get_string_list (kf,
						   G_KEY_FILE_DESKTOP_GROUP,
						   key,
						   NULL, NULL);
		for (i = 0; list[i] != NULL; i++) {
			const gchar *category_blacklist[] = {
				"X-GNOME-Settings-Panel",
				"X-Unity-Settings-Panel",
				NULL };

			/* we have to veto these */
			for (j = 0; category_blacklist[j] != NULL; j++) {
				if (g_strcmp0 (list[i], category_blacklist[j]) == 0) {
					as_app_add_veto (app, "Has category %s",
							 category_blacklist[j]);
				}
			}

			/* check the category is valid */
			if (!as_utils_is_category_id (list[i]))
				continue;

			/* ignore some useless keys */
			if (g_strcmp0 (list[i], "GTK") == 0)
				continue;
			if (g_strcmp0 (list[i], "Qt") == 0)
				continue;
			if (g_strcmp0 (list[i], "KDE") == 0)
				continue;
			if (g_strcmp0 (list[i], "GNOME") == 0)
				continue;
			as_app_add_category (app, list[i]);
		}

	} else if (g_strcmp0 (key, "Keywords") == 0) {
		list = g_key_file_get_string_list (kf,
						   G_KEY_FILE_DESKTOP_GROUP,
						   key,
						   NULL, NULL);
		for (i = 0; list[i] != NULL; i++) {
			g_auto(GStrv) kw_split = NULL;
			kw_split = g_strsplit (list[i], ",", -1);
			for (j = 0; kw_split[j] != NULL; j++) {
				if (kw_split[j][0] == '\0')
					continue;
				as_app_add_keyword (app, "C", kw_split[j]);
			}
		}

	} else if (g_str_has_prefix (key, "Keywords")) {
		locale = as_app_desktop_key_get_locale (key);
		if (flags & AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS &&
		    !g_strv_contains (g_get_language_names (), locale))
			return TRUE;
		list = g_key_file_get_locale_string_list (kf,
							  G_KEY_FILE_DESKTOP_GROUP,
							  key,
							  locale,
							  NULL, NULL);
		for (i = 0; list[i] != NULL; i++) {
			g_auto(GStrv) kw_split = NULL;
			kw_split = g_strsplit (list[i], ",", -1);
			for (j = 0; kw_split[j] != NULL; j++) {
				if (kw_split[j][0] == '\0')
					continue;
				as_app_add_keyword (app, locale, kw_split[j]);
			}
		}

	} else if (g_strcmp0 (key, "MimeType") == 0) {
		list = g_key_file_get_string_list (kf,
						   G_KEY_FILE_DESKTOP_GROUP,
						   key,
						   NULL, NULL);
		for (i = 0; list[i] != NULL; i++)
			as_app_add_mimetype (app, list[i]);

	} else if (g_strcmp0 (key, "X-AppInstall-Package") == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_add_pkgname (app, tmp);

	/* OnlyShowIn */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN) == 0) {
		/* if an app has only one entry, it's that desktop */
		list = g_key_file_get_string_list (kf,
						   G_KEY_FILE_DESKTOP_GROUP,
						   key,
						   NULL, NULL);
		if (g_strv_length (list) == 1)
			as_app_set_project_group (app, list[0]);

	/* Name */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_NAME) == 0 ||
	           g_strcmp0 (key, "_Name") == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_name (app, "C", tmp);

	/* Name[] */
	} else if (g_str_has_prefix (key, G_KEY_FILE_DESKTOP_KEY_NAME)) {
		locale = as_app_desktop_key_get_locale (key);
		if (flags & AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS &&
		    !g_strv_contains (g_get_language_names (), locale))
			return TRUE;
		tmp = g_key_file_get_locale_string (kf,
						    G_KEY_FILE_DESKTOP_GROUP,
						    G_KEY_FILE_DESKTOP_KEY_NAME,
						    locale,
						    NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_name (app, locale, tmp);

	/* Comment */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_COMMENT) == 0 ||
	           g_strcmp0 (key, "_Comment") == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_comment (app, "C", tmp);

	/* Comment[] */
	} else if (g_str_has_prefix (key, G_KEY_FILE_DESKTOP_KEY_COMMENT)) {
		locale = as_app_desktop_key_get_locale (key);
		if (flags & AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS &&
		    !g_strv_contains (g_get_language_names (), locale))
			return TRUE;
		tmp = g_key_file_get_locale_string (kf,
						    G_KEY_FILE_DESKTOP_GROUP,
						    G_KEY_FILE_DESKTOP_KEY_COMMENT,
						    locale,
						    NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_comment (app, locale, tmp);

	/* non-standard */
	} else if (g_strcmp0 (key, "X-Ubuntu-Software-Center-Name") == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_name (app, "C", tmp);
	} else if (g_str_has_prefix (key, "X-Ubuntu-Software-Center-Name")) {
		locale = as_app_desktop_key_get_locale (key);
		if (flags & AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS &&
		    !g_strv_contains (g_get_language_names (), locale))
			return TRUE;
		tmp = g_key_file_get_locale_string (kf,
						    G_KEY_FILE_DESKTOP_GROUP,
						    "X-Ubuntu-Software-Center-Name",
						    locale,
						    NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_name (app, locale, tmp);

	/* for Ubuntu */
	} else if (g_strcmp0 (key, "X-AppStream-Ignore") == 0) {
		gboolean ret;
		ret = g_key_file_get_boolean (kf,
					      G_KEY_FILE_DESKTOP_GROUP,
					      key,
					      NULL);
		if (ret)
			as_app_add_veto (app, "X-AppStream-Ignore");
	}

	/* add any external attribute as metadata to the application */
	if (flags & AS_APP_PARSE_FLAG_ADD_ALL_METADATA)
		as_app_parse_file_metadata (app, kf, key);

	return TRUE;
}
static gboolean
ide_language_defaults_migrate (GKeyFile  *key_file,
                               gint       current_version,
                               gint       new_version,
                               GError   **error)
{
  gchar **groups;
  gsize i;

  g_assert (key_file);
  g_assert (current_version >= 0);
  g_assert (current_version >= 0);
  g_assert (new_version > current_version);

  groups = g_key_file_get_groups (key_file, NULL);

  for (i = 0; groups [i]; i++)
    {
      const gchar *group = groups [i];
      g_autoptr(GSettings) settings = NULL;
      g_autofree gchar *lang_path = NULL;
      gchar **keys;
      gsize j;

      g_assert (group != NULL);

      if (g_str_equal (group, "global"))
        continue;

      lang_path = g_strdup_printf (PATH_BASE"%s/", group);
      g_assert(lang_path);

      settings = g_settings_new_with_path (SCHEMA_ID, lang_path);
      g_assert (G_IS_SETTINGS (settings));

      keys = g_key_file_get_keys (key_file, group, NULL, NULL);
      g_assert (keys);

      for (j = 0; keys [j]; j++)
        {
          const gchar *key = keys [j];
          g_autoptr(GVariant) default_value = NULL;

          g_assert (key);

          default_value = g_settings_get_default_value (settings, key);
          g_assert (default_value);

          /*
           * For all of the variant types we support, check to see if the value
           * is matching the default schema value. If so, update the key to the
           * new override value.
           *
           * This will not overwrite any change settings for files that the
           * user has previously loaded, but will for others. Overriding things
           * we have overriden gets pretty nasty, since we change things out
           * from under the user.
           *
           * That may change in the future, but not today.
           */

          if (g_variant_is_of_type (default_value, G_VARIANT_TYPE_STRING))
            {
              g_autofree gchar *current_str = NULL;
              g_autofree gchar *override_str = NULL;
              const gchar *default_str;

              default_str = g_variant_get_string (default_value, NULL);
              current_str = g_settings_get_string (settings, key);
              override_str = g_key_file_get_string (key_file, group, key, NULL);

              if (0 == g_strcmp0 (default_str, current_str))
                g_settings_set_string (settings, key, override_str);
            }
          else if (g_variant_is_of_type (default_value, G_VARIANT_TYPE_BOOLEAN))
            {
              gboolean current_bool;
              gboolean override_bool;
              gboolean default_bool;

              default_bool = g_variant_get_boolean (default_value);
              current_bool = g_settings_get_boolean (settings, key);
              override_bool = g_key_file_get_boolean (key_file, group, key, NULL);

              if (default_bool != current_bool)
                g_settings_set_boolean (settings, key, override_bool);
            }
          else if (g_variant_is_of_type (default_value, G_VARIANT_TYPE_INT32))
            {
              gint32 current_int32;
              gint32 override_int32;
              gint32 default_int32;

              default_int32 = g_variant_get_int32 (default_value);
              current_int32 = g_settings_get_int (settings, key);
              override_int32 = g_key_file_get_integer (key_file, group, key, NULL);

              if (default_int32 != current_int32)
                g_settings_set_int (settings, key, override_int32);
            }
          else
            {
              g_error ("Teach me about variant type: %s",
                       g_variant_get_type_string (default_value));
              g_assert_not_reached ();
            }
        }
    }

  return TRUE;
}
示例#26
0
文件: svte.c 项目: skawouter/svte-tmp
/* parse the config file, using the Settings struct */
static void parse_config_file(gchar *config_file) {
  GKeyFile *keyfile;
  GError *error = NULL;
  gchar *addid; 
  int i = 0;
  addid = (gchar *) g_malloc (3);

  keyfile = g_key_file_new();
  if (!g_key_file_load_from_file(keyfile, config_file, G_KEY_FILE_NONE, &error)) {
    g_warning("Error parsing config file %s: %s\n",
        config_file,
        error->message);
  }

  config = g_slice_new(Settings);

  /* General Settings */
  config->browser_command = g_key_file_get_string(
      keyfile, "general", "browser", NULL);


  /* UI Settings */
  config->audible_bell = g_key_file_get_boolean(
      keyfile, "ui", "audible_bell", NULL);
  config->autohide_mouse = g_key_file_get_boolean(
      keyfile, "ui", "autohide_mouse", NULL);
  config->allow_bold = g_key_file_get_boolean(
      keyfile, "ui", "allow_bold", NULL);
  config->font = g_key_file_get_string(
      keyfile, "ui", "font", NULL);
  config->fullscreen = g_key_file_get_boolean(
      keyfile, "ui", "fullscreen", NULL);
  config->num_scrollback_lines = g_key_file_get_integer(
      keyfile, "ui", "num_scrollback_lines", NULL);
  config->scroll_on_keystroke = g_key_file_get_boolean(
      keyfile, "ui", "scroll_on_keystroke", NULL);
  config->scroll_on_output = g_key_file_get_boolean(
      keyfile, "ui", "scroll_on_output", NULL);
  config->bg_transparent = g_key_file_get_boolean(
      keyfile, "ui", "bg_transparent", NULL);
  config->bg_image = g_key_file_get_string(
      keyfile, "ui", "bg_image", NULL);
  config->bg_saturation = g_key_file_get_double(
      keyfile, "ui", "bg_saturation", NULL);
  config->url_regex = g_key_file_get_string(
      keyfile, "ui", "url_regex", NULL);
  config->visible_bell = g_key_file_get_boolean(
      keyfile, "ui", "visible_bell", NULL);
  config->window_height = g_key_file_get_integer(
      keyfile, "ui", "window_height", NULL);
  config->window_width = g_key_file_get_integer(
      keyfile, "ui", "window_width", NULL);
  config->word_chars = g_key_file_get_string(
      keyfile, "ui", "word_chars", NULL);

  /* Color Scheme Settings */
  config->cursor = g_key_file_get_string(
      keyfile, "colour scheme", "cursor", NULL);

  config->colour_palette = (GdkColor *) g_malloc(sizeof(GdkColor) * DEFAULT_PALETTE_SIZE);
  for (i=0; i < DEFAULT_PALETTE_SIZE; i++){
    g_snprintf(addid, 3, "%d", i);
    gdk_color_parse(g_key_file_get_string(keyfile, "colour scheme", 
          addid , NULL), &config->colour_palette[i]);
  }

  if (!gdk_color_parse(g_key_file_get_string(
          keyfile, "colour scheme", "foreground", NULL), &config->foreground)){
    gdk_color_parse(DEFAULT_FOREGROUND_COLOR, &config->foreground);
    g_warning("Using default foreground color");
  }

  if (!gdk_color_parse(g_key_file_get_string(
          keyfile, "colour scheme", "background", NULL), &config->background)){
    gdk_color_parse(DEFAULT_BACKGROUND_COLOR, &config->background);
    g_warning("Using default background color");
  }

  if (NULL == config->font) {
    config->font = DEFAULT_FONT;
  }

  if(NULL == config->browser_command) {
    config->browser_command = DEFAULT_BROWSER_COMMAND; 
  }

  if (NULL == config->url_regex) {
    config->url_regex = DEFAULT_URL_REGEX;
  }

  g_free(addid);
  g_key_file_free(keyfile);
}
示例#27
0
void
prefs_load(void)
{
    GError *err;
    prefs_loc = _get_preferences_file();

    if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
        g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
    }

    prefs = g_key_file_new();
    g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS,
        NULL);

    err = NULL;
    log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err);
    if (err) {
        log_maxsize = 0;
        g_error_free(err);
    }

    // move pre 0.4.7 otr.warn to enc.warn
    err = NULL;
    gboolean otr_warn = g_key_file_get_boolean(prefs, PREF_GROUP_UI, "otr.warn", &err);
    if (err == NULL) {
        g_key_file_set_boolean(prefs, PREF_GROUP_UI, _get_key(PREF_ENC_WARN), otr_warn);
        g_key_file_remove_key(prefs, PREF_GROUP_UI, "otr.warn", NULL);
    } else {
        g_error_free(err);
    }

    // migrate pre 0.4.7 time settings format
    if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time", NULL)) {
        char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time", NULL);
        if (g_strcmp0(time, "minutes") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M");
        } else if (g_strcmp0(time, "seconds") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M:%S");
        } else if (g_strcmp0(time, "off") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "");
        }
        prefs_free_string(time);
    }
    if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time.statusbar", NULL)) {
        char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time.statusbar", NULL);
        if (g_strcmp0(time, "minutes") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M");
        } else if (g_strcmp0(time, "seconds") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M:%S");
        } else if (g_strcmp0(time, "off") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "");
        }
        prefs_free_string(time);
    }

    _save_prefs();

    boolean_choice_ac = autocomplete_new();
    autocomplete_add(boolean_choice_ac, "on");
    autocomplete_add(boolean_choice_ac, "off");
}
static char *
parse_exec (EggDesktopFile  *desktop_file,
	    GSList         **documents,
	    GError         **error)
{
  char *exec, *p, *command;
  gboolean escape, single_quot, double_quot;
  GString *gs;

  exec = g_key_file_get_string (desktop_file->key_file,
				EGG_DESKTOP_FILE_GROUP,
				EGG_DESKTOP_FILE_KEY_EXEC,
				error);
  if (!exec)
    return NULL;

  /* Build the command */
  gs = g_string_new (NULL);
  escape = single_quot = double_quot = FALSE;

  for (p = exec; *p != '\0'; p++)
    {
      if (escape)
	{
	  escape = FALSE;
	  g_string_append_c (gs, *p);
	}
      else if (*p == '\\')
	{
	  if (!single_quot)
	    escape = TRUE;
	  g_string_append_c (gs, *p);
	}
      else if (*p == '\'')
	{
	  g_string_append_c (gs, *p);
	  if (!single_quot && !double_quot)
	    single_quot = TRUE;
	  else if (single_quot)
	    single_quot = FALSE;
	}
      else if (*p == '"')
	{
	  g_string_append_c (gs, *p);
	  if (!single_quot && !double_quot)
	    double_quot = TRUE;
	  else if (double_quot)
	    double_quot = FALSE;
	}
      else if (*p == '%' && p[1])
	{
	  do_percent_subst (desktop_file, p[1], gs, documents,
			    single_quot, double_quot);
	  p++;
	}
      else
	g_string_append_c (gs, *p);
    }

  g_free (exec);
  command = g_string_free (gs, FALSE);

  /* Prepend "xdg-terminal " if needed (FIXME: use gvfs) */
  if (g_key_file_has_key (desktop_file->key_file,
			  EGG_DESKTOP_FILE_GROUP,
			  EGG_DESKTOP_FILE_KEY_TERMINAL,
			  NULL))
    {
      GError *terminal_error = NULL;
      gboolean use_terminal =
	g_key_file_get_boolean (desktop_file->key_file,
				EGG_DESKTOP_FILE_GROUP,
				EGG_DESKTOP_FILE_KEY_TERMINAL,
				&terminal_error);
      if (terminal_error)
	{
	  g_free (command);
	  g_propagate_error (error, terminal_error);
	  return NULL;
	}

      if (use_terminal)
	{
	  gs = g_string_new ("xdg-terminal ");
	  append_quoted_word (gs, command, FALSE, FALSE);
	  g_free (command);
	  command = g_string_free (gs, FALSE);
	}
    }

  return command;
}
示例#29
0
static gboolean
panel_layout_append_group_helper (GKeyFile                  *keyfile,
                                  const char                *group,
                                  int                        set_screen_to,
                                  const char                *group_prefix,
                                  const char                *id_list_key,
                                  const char                *schema,
                                  const char                *path_prefix,
                                  const char                *default_prefix,
                                  PanelLayoutKeyDefinition  *key_definitions,
                                  int                        key_definitions_len,
                                  gboolean                   dry_run,
                                  GError                   **error,
                                  const char                *type_for_error_message)
{
        gboolean    retval = FALSE;
        const char *id;
        char       *unique_id = NULL;
        char       *path = NULL;
        GSettings  *settings = NULL;
        char      **keyfile_keys = NULL;
        char       *value_str;
        int         value_int;
        gboolean    value_boolean;
        int         i, j;

        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

        /* Try to extract an id from the group, by stripping the prefix,
         * and create a unique id out of that */
        id = group + strlen (group_prefix);
        while (g_ascii_isspace (*id))
                id++;

        if (!*id)
                id = NULL;

        if (id && !panel_gsettings_is_valid_keyname (id, error))
                return FALSE;

        unique_id = panel_layout_find_free_id (id_list_key, schema, path_prefix,
                                               id, set_screen_to);

        path = g_strdup_printf ("%s%s/", path_prefix, unique_id);
        settings = g_settings_new_with_path (schema, path);
        g_free (path);

        /* Check that what the code knows matches what the schemas say */
        if (!panel_layout_append_self_check (settings,
                                             key_definitions,
                                             key_definitions_len,
                                             error))
                goto out;

        keyfile_keys = g_key_file_get_keys (keyfile, group, NULL, error);

        if (!keyfile_keys)
                goto out;

        /* Now do the real work: we validate/add keys from the keyfile */
        for (i = 0; keyfile_keys[i] != NULL; i++) {
                gboolean found = FALSE;

                for (j = 0; j < key_definitions_len; j++) {
                        if (g_strcmp0 (keyfile_keys[i],
                                       key_definitions[j].name) == 0) {
                                found = TRUE;
                                break;
                        }
                }

                if (!found) {
                        g_set_error (error, PANEL_LAYOUT_ERROR, 0,
                                     "Unknown key '%s' for %s",
                                     keyfile_keys[i],
                                     type_for_error_message);
                        return FALSE;
                }

                switch (key_definitions[j].type) {
                        case G_TYPE_STRING:
                                value_str = g_key_file_get_string (
                                                        keyfile,
                                                        group, keyfile_keys[i],
                                                        error);
                                if (!value_str)
                                        goto out;

                                if (!dry_run)
                                        g_settings_set_string (settings,
                                                               key_definitions[j].name,
                                                               value_str);
                                g_free (value_str);
                                break;

                        case G_TYPE_INT:
                                value_int = g_key_file_get_integer (
                                                        keyfile,
                                                        group, keyfile_keys[i],
                                                        error);
                                if (error && *error)
                                        goto out;

                                if (!dry_run)
                                        g_settings_set_int (settings,
                                                            key_definitions[j].name,
                                                            value_int);
                                break;

                        case G_TYPE_BOOLEAN:
                                value_boolean = g_key_file_get_boolean (
                                                        keyfile,
                                                        group, keyfile_keys[i],
                                                        error);
                                if (error && *error)
                                        goto out;

                                if (!dry_run)
                                        g_settings_set_boolean (settings,
                                                                key_definitions[j].name,
                                                                value_boolean);
                                break;
                        default:
                                g_assert_not_reached ();
                                break;
                }
        }

        if (!dry_run) {
                if (set_screen_to != -1 &&
                    g_strcmp0 (schema, PANEL_TOPLEVEL_SCHEMA) == 0)
                        g_settings_set_int (settings,
                                            PANEL_TOPLEVEL_SCREEN_KEY,
                                            set_screen_to);

                panel_gsettings_append_strv (layout_settings,
                                             id_list_key,
                                             unique_id);
        }

        retval = TRUE;

out:
        if (keyfile_keys)
                g_strfreev (keyfile_keys);
        if (settings)
                g_object_unref (settings);
        if (unique_id)
                g_free (unique_id);

        return retval;
}
示例#30
0
static gboolean
ToolsCoreRpcCapReg(RpcInData *data)
{
   char *confPath = GuestApp_GetConfPath();
   gchar *msg;
   GArray *pcaps = NULL;
   ToolsServiceState *state = data->clientData;

   g_signal_emit_by_name(state->ctx.serviceObj,
                         TOOLS_CORE_SIG_CAPABILITIES,
                         &state->ctx,
                         TRUE,
                         &pcaps);

   if (pcaps != NULL) {
      ToolsCore_SetCapabilities(state->ctx.rpc, pcaps, TRUE);
      g_array_free(pcaps, TRUE);
   }

   /* Tell the host the location of the conf directory. */
   msg = g_strdup_printf("tools.capability.guest_conf_directory %s", confPath);
   if (!RpcChannel_Send(state->ctx.rpc, msg, strlen(msg) + 1, NULL, NULL)) {
      g_debug("Unable to register guest conf directory capability.\n");
   }
   g_free(msg);
   msg = NULL;

   /* Send the tools version to the VMX. */
   if (state->mainService) {
      uint32 version;
      char *result = NULL;
      size_t resultLen;
      gchar *toolsVersion;

#if defined(OPEN_VM_TOOLS)
      version = TOOLS_VERSION_UNMANAGED;
#else
      gboolean disableVersion;

      disableVersion = g_key_file_get_boolean(state->ctx.config,
                                              "vmtools",
                                              CONFNAME_DISABLETOOLSVERSION,
                                              NULL);
      version = disableVersion ? TOOLS_VERSION_UNMANAGED : TOOLS_VERSION_CURRENT;
#endif

      toolsVersion = g_strdup_printf("tools.set.version %u", version);

      if (!RpcChannel_Send(state->ctx.rpc, toolsVersion, strlen(toolsVersion) + 1,
                           &result, &resultLen)) {
         g_debug("Error setting tools version: %s.\n", result);
      }
      vm_free(result);
      g_free(toolsVersion);
   }

#if defined (__linux__)
   /* Send the IOPL elevation capability to VMX. */
   if (state->mainService) {
      unsigned int oldLevel;
      char *result = NULL;
      size_t resultLen;

      const char ioplElev[] = "tools.capability.iopl_elevation";

      oldLevel = Iopl_Get();
      g_debug("%s: old IOPL = %u\n", __FUNCTION__, oldLevel);

      if (iopl(3) < 0) {
         g_debug("Error raising the IOPL, %s", strerror(errno));
      }

      g_debug("%s: new IOPL = %u\n", __FUNCTION__, Iopl_Get());

      if (!RpcChannel_Send(state->ctx.rpc, ioplElev, sizeof ioplElev,
                           &result, &resultLen)) {
         g_debug("Error setting tools iopl elevation capability: %s\n",
                 result);
         vm_free(result);
      }

      if (iopl(oldLevel) < 0) {
         g_debug("Error restoring the IOPL, %s", strerror(errno));
      }
   }
#endif

   state->capsRegistered = TRUE;
   free(confPath);
   return RPCIN_SETRETVALS(data, "", TRUE);
}