QString
LauncherApplication::icon() const
{
    if (sticky() && (m_appInfo != NULL)) {
        GCharPointer ptr(g_icon_to_string(g_app_info_get_icon(m_appInfo.data())));
        return QString::fromUtf8(ptr.data());
    }

    if (m_application != NULL) {
        return m_application->icon();
    }

    if (m_appInfo != NULL) {
        GCharPointer ptr(g_icon_to_string(g_app_info_get_icon(m_appInfo.data())));
        return QString::fromUtf8(ptr.data());
    }

    if (m_snStartupSequence != NULL) {
        return QString::fromUtf8(sn_startup_sequence_get_icon_name(m_snStartupSequence.data()));
    }

    return QString("");
}
Example #2
0
static void
panel_drawer_prepare (const char  *drawer_id,
                      GIcon       *custom_icon,
                      gboolean     use_custom_icon,
                      const char  *tooltip,
                      char       **attached_toplevel_id)
{
    GSettings *settings;
    char *path;

    path = g_strdup_printf ("%s%s/", PANEL_OBJECT_PATH, drawer_id);
    settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
    g_free (path);

    if (tooltip) {
        g_settings_set_string (settings, PANEL_OBJECT_TOOLTIP_KEY, tooltip);
    }

    g_settings_set_boolean (settings, PANEL_OBJECT_USE_CUSTOM_ICON_KEY, use_custom_icon);

    if (custom_icon) {
	gchar *icon_name;
	icon_name = g_icon_to_string(custom_icon);
	g_settings_set_string (settings, PANEL_OBJECT_CUSTOM_ICON_KEY, icon_name);
	g_free(icon_name);
    }

    if (attached_toplevel_id) {
        char *toplevel_id;
        char *toplevel_path;
        GSettings *toplevel_settings;

        toplevel_id = panel_profile_find_new_id (PANEL_GSETTINGS_TOPLEVELS);

        toplevel_path = g_strdup_printf (PANEL_TOPLEVEL_PATH "%s/", toplevel_id);

        toplevel_settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA, toplevel_path);

        g_settings_set_string (settings, PANEL_OBJECT_ATTACHED_TOPLEVEL_ID_KEY, toplevel_id);
        g_settings_set_boolean (toplevel_settings, PANEL_TOPLEVEL_ENABLE_BUTTONS_KEY, TRUE);
        g_settings_set_boolean (toplevel_settings, PANEL_TOPLEVEL_ENABLE_ARROWS_KEY, TRUE);

        *attached_toplevel_id = toplevel_id;

        g_object_unref (toplevel_settings);
        g_free (toplevel_path);
    }
    g_object_unref (settings);
}
Example #3
0
void TrashLauncherIcon::UpdateTrashIconCb(GObject* source, GAsyncResult* res, gpointer data)
{
  auto self = static_cast<TrashLauncherIcon*>(data);

  // FIXME: should use the generic LoadIcon function (not taking from the unity theme)
  glib::Object<GFileInfo> info(g_file_query_info_finish(G_FILE(source), res, nullptr));

  if (info)
  {
    glib::Object<GIcon> icon(g_file_info_get_icon(info), glib::AddRef());
    glib::String icon_string(g_icon_to_string(icon));

    self->icon_name = icon_string.Str();
    self->empty_ = (self->icon_name == "user-trash");
  }
}
bool DefaultThumbnailer::Run(int size, std::string const& input_file, std::string& output_file, std::string& error_hint)
{
  glib::Object<GFile> file(::g_file_new_for_uri(input_file.c_str()));

  GError *err = NULL;
  glib::Object<GFileInfo> file_info(g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_ICON, G_FILE_QUERY_INFO_NONE, NULL, &err));
  if (err != NULL)
  {
    error_hint = err->message;
    g_error_free (err);
    return "";
  }

  GIcon* icon = g_file_info_get_icon(file_info); // [transfer none]
  output_file = g_icon_to_string(icon);

  return true;
}
Example #5
0
GdkPixbuf *
iconstore_get_pixbuf (GFileInfo * file_info)
{
    // create new hash table
    if (pixbuf_hash_table == NULL) {
        pixbuf_hash_table = g_hash_table_new_full (g_str_hash,
                                                   g_str_equal,
                                                   g_free,
                                                   g_object_unref);
    }

    GIcon *icon = NULL;
    gboolean icon_needs_free = FALSE;
    if (file_info) {
        icon = g_file_info_get_icon (file_info);
    }
    else {
        icon = g_icon_new_for_string ("image-missing", NULL);
        icon_needs_free = TRUE;
    }
    gchar *icon_string = g_icon_to_string (icon);
    GdkPixbuf *pixbuf = (GdkPixbuf *) g_hash_table_lookup (pixbuf_hash_table,
                                                           icon_string);

    if (pixbuf == NULL) {
        pixbuf = get_themed_icon_pixbuf (G_THEMED_ICON (icon),
                                         ICON_SIZE,
                                         gtk_icon_theme_get_default ());
        g_hash_table_insert (pixbuf_hash_table,
                             g_strdup (icon_string),
                             pixbuf);
    }
    if (icon_needs_free) {
        g_object_unref (icon);
    }
    g_free (icon_string);
    return pixbuf;
}
Example #6
0
// -------------------------------------------------------------------------------- //
// guGIO_Mount
// -------------------------------------------------------------------------------- //
guGIO_Mount::guGIO_Mount( GMount * mount )
{
    m_Mount = mount;
    g_object_ref( mount );
//    m_PanelActive = wxNOT_FOUND;

    char * mount_name = g_mount_get_name( m_Mount );
    if( mount_name )
    {
        m_Name = wxString( mount_name, wxConvUTF8 );
        g_free( mount_name );
    }

    GFile * RootFile = g_mount_get_root( mount );
    if( RootFile)
    {
        char * Path = g_file_get_path( RootFile );
        m_MountPath = wxString( Path, wxConvUTF8 ) + wxT( "/" );
        guLogMessage( wxT( "Mount Path: %s" ), m_MountPath.c_str() );
        g_free( Path );
        g_object_unref( RootFile );
    }
    GIcon * Icon = g_mount_get_icon( mount );
    if( Icon )
    {
        char * IconStr = g_icon_to_string( Icon );
        if( IconStr )
        {
            m_IconString = wxString( IconStr, wxConvUTF8 );
            guLogMessage( wxT( "IconStr: '%s'" ), m_IconString.c_str() );
            g_free( IconStr );
        }
        g_object_unref( Icon );
    }

    wxFileConfig * Config = new wxFileConfig( wxEmptyString, wxEmptyString, m_MountPath + wxT( ".is_audio_player" ) );
    m_Id = Config->Read( wxT( "audio_player_id" ), wxString::Format( wxT( "%08lX" ), wxGetLocalTime() ) );
}
Example #7
0
static void _gtk_image_set_from_file_scaled(GtkWidget * img, ImgData * data)
{
    if (data->pixbuf != NULL)
    {
        g_object_unref(data->pixbuf);
        data->pixbuf = NULL;
    }

    /* if there is a cached hilighted version of this pixbuf, free it */
    if (data->hilight != NULL)
    {
        g_object_unref(data->hilight);
        data->hilight = NULL;
    }

    if (G_LIKELY(G_IS_THEMED_ICON(data->icon)))
        data->pixbuf = fm_pixbuf_from_icon_with_fallback(data->icon, data->size,
                                                         "application-x-executable");
    else
    {
        char *file = g_icon_to_string(fm_icon_get_gicon(data->icon));
        data->pixbuf = gdk_pixbuf_new_from_file_at_scale(file, -1, data->size, TRUE, NULL);
        g_free(file);
    }

    if (data->pixbuf != NULL)
    {
        /* Set the pixbuf into the image widget. */
        gtk_image_set_from_pixbuf((GtkImage *)img, data->pixbuf);
    }
    else
    {
        /* No pixbuf available.  Set the "missing image" icon. */
        gtk_image_set_from_stock(GTK_IMAGE(img), GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON);
    }
}
/**
 * st_texture_cache_load_gicon:
 * @cache: The texture cache instance
 * @theme_node: (nullable): The #StThemeNode to use for colors, or NULL
 *                            if the icon must not be recolored
 * @icon: the #GIcon to load
 * @size: Size of themed
 * @scale: Scale factor of display
 *
 * This method returns a new #ClutterActor for a given #GIcon. If the
 * icon isn't loaded already, the texture will be filled
 * asynchronously.
 *
 * Return Value: (transfer none): A new #ClutterActor for the icon, or %NULL if not found
 */
ClutterActor *
st_texture_cache_load_gicon (StTextureCache    *cache,
                             StThemeNode       *theme_node,
                             GIcon             *icon,
                             gint               size,
                             gint               scale)
{
  AsyncTextureLoadData *request;
  ClutterActor *texture;
  char *gicon_string;
  char *key;
  GtkIconTheme *theme;
  GtkIconInfo *info;
  StTextureCachePolicy policy;
  StIconColors *colors = NULL;
  StIconStyle icon_style = ST_ICON_STYLE_REQUESTED;
  GtkIconLookupFlags lookup_flags;

  if (theme_node)
    {
      colors = st_theme_node_get_icon_colors (theme_node);
      icon_style = st_theme_node_get_icon_style (theme_node);
    }

  /* Do theme lookups in the main thread to avoid thread-unsafety */
  theme = cache->priv->icon_theme;

  lookup_flags = GTK_ICON_LOOKUP_USE_BUILTIN;

  if (icon_style == ST_ICON_STYLE_REGULAR)
    lookup_flags |= GTK_ICON_LOOKUP_FORCE_REGULAR;
  else if (icon_style == ST_ICON_STYLE_SYMBOLIC)
    lookup_flags |= GTK_ICON_LOOKUP_FORCE_SYMBOLIC;

  if (clutter_get_default_text_direction () == CLUTTER_TEXT_DIRECTION_RTL)
    lookup_flags |= GTK_ICON_LOOKUP_DIR_RTL;
  else
    lookup_flags |= GTK_ICON_LOOKUP_DIR_LTR;

  info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, size, scale, lookup_flags);
  if (info == NULL)
    return NULL;

  gicon_string = g_icon_to_string (icon);
  /* A return value of NULL indicates that the icon can not be serialized,
   * so don't have a unique identifier for it as a cache key, and thus can't
   * be cached. If it is cachable, we hardcode a policy of FOREVER here for
   * now; we should actually blow this away on icon theme changes probably */
  policy = gicon_string != NULL ? ST_TEXTURE_CACHE_POLICY_FOREVER
                                : ST_TEXTURE_CACHE_POLICY_NONE;
  if (colors)
    {
      /* This raises some doubts about the practice of using string keys */
      key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,scale=%d,style=%d,colors=%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x",
                             gicon_string, size, scale, icon_style,
                             colors->foreground.red, colors->foreground.blue, colors->foreground.green, colors->foreground.alpha,
                             colors->warning.red, colors->warning.blue, colors->warning.green, colors->warning.alpha,
                             colors->error.red, colors->error.blue, colors->error.green, colors->error.alpha,
                             colors->success.red, colors->success.blue, colors->success.green, colors->success.alpha);
    }
  else
    {
      key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,scale=%d,style=%d",
                             gicon_string, size, scale, icon_style);
    }
  g_free (gicon_string);

  texture = (ClutterActor *) create_default_texture ();
  clutter_actor_set_size (texture, size * scale, size * scale);

  if (ensure_request (cache, key, policy, &request, texture))
    {
      /* If there's an outstanding request, we've just added ourselves to it */
      g_object_unref (info);
      g_free (key);
    }
  else
    {
      /* Else, make a new request */

      request->cache = cache;
      /* Transfer ownership of key */
      request->key = key;
      request->policy = policy;
      request->colors = colors ? st_icon_colors_ref (colors) : NULL;
      request->icon_info = info;
      request->width = request->height = size;
      request->scale = scale;

      load_texture_async (cache, request);
    }

  return CLUTTER_ACTOR (texture);
}
void ApplicationPreview::SetupViews()
{
  dash::ApplicationPreview* app_preview_model = dynamic_cast<dash::ApplicationPreview*>(preview_model_.get());
  if (!app_preview_model)
  {
    LOG_ERROR(logger) << "Could not derive application preview model from given parameter.";
    return;
  }

  previews::Style& style = dash::previews::Style::Instance();

  auto on_mouse_down = [this](int x, int y, unsigned long button_flags, unsigned long key_flags) { this->preview_container_->OnMouseDown(x, y, button_flags, key_flags); };

  nux::HLayout* image_data_layout = new nux::HLayout();
  image_data_layout->SetSpaceBetweenChildren(style.GetPanelSplitWidth());

  /////////////////////
  // Image
  image_ = new CoverArt();
  AddChild(image_.GetPointer());
  UpdateCoverArtImage(image_.GetPointer());
  /////////////////////

    /////////////////////
    // App Data Panel
    full_data_layout_ = new nux::VLayout();
    full_data_layout_->SetPadding(style.GetDetailsTopMargin(), 0, style.GetDetailsBottomMargin(), style.GetDetailsLeftMargin());
    full_data_layout_->SetSpaceBetweenChildren(16);

      /////////////////////
      // Main App Info
      nux::HLayout* main_app_info = new nux::HLayout();
      main_app_info->SetSpaceBetweenChildren(style.GetSpaceBetweenIconAndDetails());

        /////////////////////
        // Icon Layout
        nux::VLayout* icon_layout = new nux::VLayout();
        icon_layout->SetSpaceBetweenChildren(3);
        app_icon_ = new IconTexture(app_preview_model->app_icon.Get().RawPtr() ? g_icon_to_string(app_preview_model->app_icon.Get().RawPtr()) : "", 72);
        AddChild(app_icon_.GetPointer());
        app_icon_->SetMinimumSize(style.GetAppIconAreaWidth(), style.GetAppIconAreaWidth());
        app_icon_->SetMaximumSize(style.GetAppIconAreaWidth(), style.GetAppIconAreaWidth());
        app_icon_->mouse_click.connect(on_mouse_down);
        icon_layout->AddView(app_icon_.GetPointer(), 0);

        if (app_preview_model->rating >= 0) {
          app_rating_ = new PreviewRatingsWidget();
          AddChild(app_rating_.GetPointer());
          app_rating_->SetMaximumHeight(style.GetRatingWidgetHeight());
          app_rating_->SetMinimumHeight(style.GetRatingWidgetHeight());
          app_rating_->SetRating(app_preview_model->rating);
          app_rating_->SetReviews(app_preview_model->num_ratings);
          app_rating_->request_close().connect([this]() { preview_container_->request_close.emit(); });
          icon_layout->AddView(app_rating_.GetPointer(), 0);
        }

        /////////////////////

        /////////////////////
        // Data

        nux::VLayout* app_data_layout = new nux::VLayout();
        app_data_layout->SetSpaceBetweenChildren(16);

        title_subtitle_layout_ = new nux::VLayout();
        title_subtitle_layout_->SetSpaceBetweenChildren(style.GetSpaceBetweenTitleAndSubtitle());

        title_ = new StaticCairoText(preview_model_->title, true, NUX_TRACKER_LOCATION);
        AddChild(title_.GetPointer());
        title_->SetLines(-1);
        title_->SetFont(style.title_font().c_str());
        title_->mouse_click.connect(on_mouse_down);
        title_subtitle_layout_->AddView(title_.GetPointer(), 1);

        if (!preview_model_->subtitle.Get().empty())
        {
          subtitle_ = new StaticCairoText(preview_model_->subtitle, true, NUX_TRACKER_LOCATION);
          AddChild(subtitle_.GetPointer());
          subtitle_->SetFont(style.subtitle_size_font().c_str());
          subtitle_->SetLines(-1);
          subtitle_->mouse_click.connect(on_mouse_down);
          title_subtitle_layout_->AddView(subtitle_.GetPointer(), 1);
        }

        nux::VLayout* app_updated_copywrite_layout = new nux::VLayout();
        app_updated_copywrite_layout->SetSpaceBetweenChildren(8);

        if (!app_preview_model->license.Get().empty())
        {
          license_ = new StaticCairoText(app_preview_model->license, true, NUX_TRACKER_LOCATION);
          AddChild(license_.GetPointer());
          license_->SetFont(style.app_license_font().c_str());
          license_->SetLines(-1);
          license_->mouse_click.connect(on_mouse_down);
          app_updated_copywrite_layout->AddView(license_.GetPointer(), 1);
        }

        if (!app_preview_model->last_update.Get().empty())
        {
          std::stringstream last_update;
          last_update << _("Last Updated") << " " << app_preview_model->last_update.Get();

          last_update_ = new StaticCairoText(last_update.str(), true, NUX_TRACKER_LOCATION);
          AddChild(last_update_.GetPointer());
          last_update_->SetFont(style.app_last_update_font().c_str());
          last_update_->mouse_click.connect(on_mouse_down);
          app_updated_copywrite_layout->AddView(last_update_.GetPointer(), 1);
        }

        if (!app_preview_model->copyright.Get().empty())
        {
          copywrite_ = new StaticCairoText(app_preview_model->copyright, true, NUX_TRACKER_LOCATION);
          AddChild(copywrite_.GetPointer());
          copywrite_->SetFont(style.app_copywrite_font().c_str());
          copywrite_->SetLines(-1);
          copywrite_->mouse_click.connect(on_mouse_down);
          app_updated_copywrite_layout->AddView(copywrite_.GetPointer(), 1);
        }

        app_data_layout->AddLayout(title_subtitle_layout_);
        app_data_layout->AddLayout(app_updated_copywrite_layout);

        // buffer space
        /////////////////////

      main_app_info->AddLayout(icon_layout, 0);
      main_app_info->AddLayout(app_data_layout, 1);
      /////////////////////

      /////////////////////
      // Description
      nux::ScrollView* app_info = new DetailsScrollView(NUX_TRACKER_LOCATION);
      app_info->EnableHorizontalScrollBar(false);
      app_info->mouse_click.connect(on_mouse_down);

      nux::VLayout* app_info_layout = new nux::VLayout();
      app_info_layout->SetSpaceBetweenChildren(12);
      app_info->SetLayout(app_info_layout);

      if (!preview_model_->description.Get().empty())
      {
        description_ = new StaticCairoText(preview_model_->description, false, NUX_TRACKER_LOCATION); // not escaped!
        AddChild(description_.GetPointer());
        description_->SetFont(style.description_font().c_str());
        description_->SetTextAlignment(StaticCairoText::NUX_ALIGN_TOP);
        description_->SetLines(-style.GetDescriptionLineCount());
        description_->SetLineSpacing(style.GetDescriptionLineSpacing());
        description_->mouse_click.connect(on_mouse_down);
        app_info_layout->AddView(description_.GetPointer());
      }

      if (!preview_model_->GetInfoHints().empty())
      {
        preview_info_hints_ = new PreviewInfoHintWidget(preview_model_, style.GetInfoHintIconSizeWidth());
        AddChild(preview_info_hints_.GetPointer());
        preview_info_hints_->request_close().connect([this]() { preview_container_->request_close.emit(); });
        app_info_layout->AddView(preview_info_hints_.GetPointer());
      }
      /////////////////////

      /////////////////////
      // Actions
      action_buttons_.clear();
      nux::Layout* actions_layout = BuildGridActionsLayout(preview_model_->GetActions(), action_buttons_);
      actions_layout->SetLeftAndRightPadding(0, style.GetDetailsRightMargin());
      ///////////////////

    full_data_layout_->AddLayout(main_app_info, 0);
    full_data_layout_->AddView(app_info, 1);
    full_data_layout_->AddLayout(actions_layout, 0);
    /////////////////////
  
  image_data_layout->AddView(image_.GetPointer(), 0);
  image_data_layout->AddLayout(full_data_layout_, 1);

  mouse_click.connect(on_mouse_down);

  SetLayout(image_data_layout);
}
Example #10
0
/**
 * udisks_client_get_object_info:
 * @client: A #UDisksClient.
 * @object: A #UDisksObject.
 *
 * Gets information about a #UDisksObject instance that is suitable to
 * present in an user interface. Information is returned in the
 * #UDisksObjectInfo object and is localized.
 *
 * Returns: (transfer full): A #UDisksObjectInfo instance that should be freed with g_object_unref().
 *
 * Since: 2.1
 */
UDisksObjectInfo *
udisks_client_get_object_info (UDisksClient        *client,
                               UDisksObject        *object)
{
  UDisksObjectInfo *ret = NULL;
  UDisksDrive *drive = NULL;
  UDisksBlock *block = NULL;
  UDisksPartition *partition = NULL;
  UDisksMDRaid *mdraid = NULL;
  UDisksLoop *loop = NULL;

  g_return_val_if_fail (UDISKS_IS_CLIENT (client), NULL);
  g_return_val_if_fail (UDISKS_IS_OBJECT (object), NULL);

  ret = udisks_object_info_new (object);
  drive = udisks_object_get_drive (object);
  block = udisks_object_get_block (object);
  loop = udisks_object_get_loop (object);
  partition = udisks_object_get_partition (object);
  mdraid = udisks_object_get_mdraid (object);
  if (drive != NULL)
    {
      udisks_client_get_object_info_for_drive (client, drive, NULL, ret);
    }
  else if (mdraid != NULL)
    {
      udisks_client_get_object_info_for_mdraid (client, mdraid, NULL, ret);
    }
  else if (block != NULL)
    {
      drive = udisks_client_get_drive_for_block (client, block);
      if (drive != NULL)
        {
          udisks_client_get_object_info_for_drive (client, drive, partition, ret);
          goto out;
        }

      mdraid = udisks_client_get_mdraid_for_block (client, block);
      if (mdraid != NULL)
        {
          udisks_client_get_object_info_for_mdraid (client, mdraid, partition, ret);
          goto out;
        }

      if (loop != NULL)
        udisks_client_get_object_info_for_loop (client, loop, block, partition, ret);
      else
        udisks_client_get_object_info_for_block (client, block, partition, ret);
    }
 out:
  g_clear_object (&loop);
  g_clear_object (&mdraid);
  g_clear_object (&partition);
  g_clear_object (&block);
  g_clear_object (&drive);

#if 0
  /* for debugging */
  g_print ("%s -> dd='%s', md='%s', ol='%s' and di='%s', mi='%s' sk='%s'\n",
           g_dbus_object_get_object_path (G_DBUS_OBJECT (object)),
           ret->description,
           ret->media_description,
           ret->one_liner,
           ret->icon == NULL ? "" : g_icon_to_string (ret->icon),
           ret->media_icon == NULL ? "" : g_icon_to_string (ret->media_icon),
           ret->sort_key);
#endif

  return ret;
}
static void
fill_combo_box(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list, gchar* mime)
{
    guint index = 0;
    GList* entry;
    GtkTreeModel* model;
    GtkCellRenderer* renderer;
    GtkTreeIter iter;
    GdkPixbuf* pixbuf;
    GAppInfo* default_app;

    default_app = NULL;
    if (g_strcmp0(mime, "terminal") == 0)
    {
        GSettings *terminal_settings = g_settings_new (TERMINAL_SCHEMA);
        gchar *default_terminal = g_settings_get_string (terminal_settings, TERMINAL_KEY);
        for (entry = app_list; entry != NULL; entry = g_list_next(entry))
        {
            GAppInfo* item = (GAppInfo*) entry->data;
            if (g_strcmp0 (g_app_info_get_executable (item), default_terminal) == 0)
            {
                default_app = item;
            }
        }
        g_free (default_terminal);
        g_object_unref (terminal_settings);
    }
    else if (g_strcmp0(mime, "visual") == 0)
    {
        GSettings *visual_settings = g_settings_new (VISUAL_SCHEMA);
        gchar *default_visual = g_settings_get_string (visual_settings, VISUAL_KEY);
        for (entry = app_list; entry != NULL; entry = g_list_next(entry))
        {
            GAppInfo* item = (GAppInfo*) entry->data;
            if (g_strcmp0 (g_app_info_get_executable (item), default_visual) == 0)
            {
                default_app = item;
            }
        }
        g_free (default_visual);
        g_object_unref (visual_settings);
    }
    else if (g_strcmp0(mime, "mobility") == 0)
    {
        GSettings *mobility_settings = g_settings_new (MOBILITY_SCHEMA);
        gchar *default_mobility = g_settings_get_string (mobility_settings, MOBILITY_KEY);
        for (entry = app_list; entry != NULL; entry = g_list_next(entry))
        {
            GAppInfo* item = (GAppInfo*) entry->data;
            if (g_strcmp0 (g_app_info_get_executable (item), default_mobility) == 0)
            {
                default_app = item;
            }
        }
        g_free (default_mobility);
        g_object_unref (mobility_settings);
    }
    else
    {
        default_app = g_app_info_get_default_for_type (mime, FALSE);
    }

    if (theme == NULL)
    {
        theme = gtk_icon_theme_get_default();
    }

    model = GTK_TREE_MODEL(gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
    gtk_combo_box_set_model(combo_box, model);

    renderer = gtk_cell_renderer_pixbuf_new();

    /* Not all cells have a pixbuf, this prevents the combo box to shrink */
    gtk_cell_renderer_set_fixed_size(renderer, -1, 22);
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, FALSE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer,
                                   "pixbuf", PIXBUF_COL,
                                   NULL);

    renderer = gtk_cell_renderer_text_new();

    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer,
                                   "text", TEXT_COL,
                                   NULL);

    for (entry = app_list; entry != NULL; entry = g_list_next(entry))
    {
        GAppInfo* item = (GAppInfo*) entry->data;

        /* Icon */
        GIcon* icon = g_app_info_get_icon(item);
        gchar* icon_name = g_icon_to_string(icon);

        if (icon_name == NULL)
        {
            /* Default icon */
            icon_name = g_strdup("binary");
        }

        pixbuf = gtk_icon_theme_load_icon(theme, icon_name, 22, 0, NULL);

        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        gtk_list_store_set(GTK_LIST_STORE(model), &iter,
                           PIXBUF_COL, pixbuf,
                           TEXT_COL, g_app_info_get_display_name(item),
                           ID_COL, g_app_info_get_id(item),
                           ICONAME_COL, icon_name,
                           -1);

        if (pixbuf)
        {
            g_object_unref(pixbuf);
        }

        /* Set the index for the default app */
        if (default_app != NULL && g_app_info_equal(item, default_app))
        {
            gtk_combo_box_set_active(combo_box, index);
        }

        g_free(icon_name);

        index++;
    }
}
Example #12
0
static VALUE
icon_to_string(VALUE self)
{
        /* TODO: Should we raise if it returns NULL? */
        return CSTR2RVAL_FREE(g_icon_to_string(_SELF(self)));
}
Example #13
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 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);
  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);

  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);
  return ret;
}
Example #14
0
char *
gvfs_file_info_marshal (GFileInfo *info,
			gsize     *size)
{
  GOutputStream *memstream;
  GDataOutputStream *out;
  GFileAttributeType type;
  GFileAttributeStatus status;
  GObject *obj;
  char **attrs, *attr;
  char *data;
  int i;

  memstream = g_memory_output_stream_new (NULL, 0, g_realloc, NULL);

  out = g_data_output_stream_new (memstream);
  g_object_unref (memstream);

  attrs = g_file_info_list_attributes (info, NULL);

  g_data_output_stream_put_uint32 (out,
				   g_strv_length (attrs),
				   NULL, NULL);

  for (i = 0; attrs[i] != NULL; i++)
    {
      attr = attrs[i];

      type = g_file_info_get_attribute_type  (info, attr);
      status = g_file_info_get_attribute_status  (info, attr);
      
      put_string (out, attr);
      g_data_output_stream_put_byte (out, type, 
				     NULL, NULL);
      g_data_output_stream_put_byte (out, status, 
				     NULL, NULL);

      switch (type)
	{
	case G_FILE_ATTRIBUTE_TYPE_STRING:
	  put_string (out, g_file_info_get_attribute_string (info, attr));
	  break;
	case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
	  put_string (out, g_file_info_get_attribute_byte_string (info, attr));
	  break;
	case G_FILE_ATTRIBUTE_TYPE_STRINGV:
	  put_stringv (out, g_file_info_get_attribute_stringv (info, attr));
	  break;
	case G_FILE_ATTRIBUTE_TYPE_BOOLEAN:
	  g_data_output_stream_put_byte (out,
					 g_file_info_get_attribute_boolean (info, attr),
					 NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_UINT32:
	  g_data_output_stream_put_uint32 (out,
					   g_file_info_get_attribute_uint32 (info, attr),
					  NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_INT32:
	  g_data_output_stream_put_int32 (out,
					  g_file_info_get_attribute_int32 (info, attr),
					  NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_UINT64:
	  g_data_output_stream_put_uint64 (out,
					   g_file_info_get_attribute_uint64 (info, attr),
					  NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_INT64:
	  g_data_output_stream_put_int64 (out,
					  g_file_info_get_attribute_int64 (info, attr),
					  NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_OBJECT:
          obj = g_file_info_get_attribute_object (info, attr);
	  if (obj == NULL)
	    {
	      g_data_output_stream_put_byte (out, 0,
					     NULL, NULL);
	    }
	  else if (G_IS_ICON (obj))
	    {
	      char *icon_str;

	      icon_str = g_icon_to_string (G_ICON (obj));
	      g_data_output_stream_put_byte (out, 1,
					     NULL, NULL);
	      put_string (out, icon_str);
	      g_free (icon_str);
	    }
	  else
	    {
	      g_warning ("Unsupported GFileInfo object type %s\n",
			 g_type_name_from_instance ((GTypeInstance *)obj));
	      g_data_output_stream_put_byte (out, 0,
					     NULL, NULL);
	    }
	  break;
	case G_FILE_ATTRIBUTE_TYPE_INVALID:
	default:
	  break;
	}
    }

  data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (memstream));
  *size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (memstream));
  g_object_unref (out);
  g_strfreev (attrs);
  return data;
}
static void
fill_combo_box(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list, gchar* mime)
{
	guint index = 0;
	GList* entry;
	GtkTreeModel* model;
	GtkCellRenderer* renderer;
	GtkTreeIter iter;
	GdkPixbuf* pixbuf;
	GAppInfo* default_app;
	
	default_app = g_app_info_get_default_for_type(mime, FALSE);

	if (theme == NULL)
	{
		theme = gtk_icon_theme_get_default();
	}

	model = GTK_TREE_MODEL(gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
	gtk_combo_box_set_model(combo_box, model);

	renderer = gtk_cell_renderer_pixbuf_new();

	/* not all cells have a pixbuf, this prevents the combo box to shrink */
	gtk_cell_renderer_set_fixed_size(renderer, -1, 22);
	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, FALSE);
	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer,
		"pixbuf", PIXBUF_COL,
		NULL);

	renderer = gtk_cell_renderer_text_new();

	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer,
		"text", TEXT_COL,
		NULL);

	for (entry = app_list; entry != NULL; entry = g_list_next(entry))
	{
		GAppInfo* item = (GAppInfo*) entry->data;
		
		// icon
		GIcon* icon = g_app_info_get_icon(item);
		gchar* icon_name = g_icon_to_string(icon);
		
		if (icon_name == NULL)
		{
			icon_name = g_strdup("binary"); // default icon
		}
		
		pixbuf = gtk_icon_theme_load_icon(theme, icon_name, 22, 0, NULL);

		gtk_list_store_append(GTK_LIST_STORE(model), &iter);
		gtk_list_store_set(GTK_LIST_STORE(model), &iter,
			PIXBUF_COL, pixbuf,
			TEXT_COL, g_app_info_get_display_name(item),
			ID_COL, g_app_info_get_id(item),
			ICONAME_COL, icon_name,
			-1);

		if (pixbuf)
		{
			g_object_unref(pixbuf);
		}
		
		/* set the index */
		if (default_app != NULL && g_app_info_equal(item, default_app))
		{
			gtk_combo_box_set_active(combo_box, index);
		}
		
		g_free(icon_name);
		
		index++;
	}
}
Example #16
0
static char *
panel_run_dialog_create_desktop_file (PanelRunDialog *dialog)
{
	GKeyFile *key_file;
	gboolean  exec = FALSE;
	char     *text;
	char     *name;
	char     *disk;
	char     *scheme;
	char     *save_uri;

	text = g_strdup (panel_run_dialog_get_combo_text (dialog));

	if (!text || !text [0]) {
		g_free (text);
		return NULL;
	}

	key_file = panel_key_file_new_desktop ();
	disk = g_locale_from_utf8 (text, -1, NULL, NULL, NULL);

	scheme = g_uri_parse_scheme (disk);
	/* if it's an absolute path or not a URI, it's possibly an executable */
	if (g_path_is_absolute (disk) || !scheme)
		exec = command_is_executable (disk, NULL, NULL);
	g_free (scheme);

	if (exec) {
		panel_key_file_set_string (key_file, "Type", "Application");
		panel_key_file_set_string (key_file, "Exec", text);
		name = g_strdup (text);
	} else {
		GFile *file;
		char  *uri;

		file = panel_util_get_file_optional_homedir (disk);
		uri = g_file_get_uri (file);
		g_object_unref (file);

		panel_key_file_set_string (key_file, "Type", "Link");
		panel_key_file_set_string (key_file, "URL", uri);
		name = uri;
	}

	g_free (disk);

	panel_key_file_set_locale_string (key_file, "Name",
					  (dialog->item_name) ?
					  dialog->item_name : text);

	panel_key_file_set_boolean (key_file, "Terminal",
				    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->terminal_checkbox)));

	if (dialog->icon) {
		gchar *icon_path = g_icon_to_string (dialog->icon);
		panel_key_file_set_locale_string (key_file, "Icon", icon_path);
		g_free (icon_path);
	}
	else
		panel_key_file_set_locale_string (key_file, "Icon",
						  PANEL_ICON_LAUNCHER);

	save_uri = panel_make_unique_desktop_uri (g_get_tmp_dir (), name);
	disk = g_filename_from_uri (save_uri, NULL, NULL);

	if (!disk || !panel_key_file_to_file (key_file, disk, NULL)) {
		g_free (save_uri);
		save_uri = NULL;
	}

	g_key_file_free (key_file);
	g_free (disk);
	g_free (name);
	g_free (text);

	return save_uri;
}