Commit a0159520 authored by Robert Roth's avatar Robert Roth

Removed iconthemewrapper

parent 45157961
......@@ -31,7 +31,6 @@ gnome_system_monitor_cpp_files = \
gsm_gksu.cpp \
gsm_pkexec.cpp \
lsof.cpp \
iconthemewrapper.cpp \
prefsdialog.cpp \
application.cpp
......
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <config.h>
#include <giomm.h>
#include <giomm/themedicon.h>
#include <gtk/gtk.h>
#include <glibtop/mountlist.h>
#include <glibtop/fsusage.h>
......@@ -11,7 +9,6 @@
#include "disks.h"
#include "application.h"
#include "util.h"
#include "iconthemewrapper.h"
#include "settings-keys.h"
#include "treeview.h"
......@@ -65,49 +62,44 @@ fsusage_stats(const glibtop_fsusage *buf,
}
}
namespace
static const char* get_icon_for_path(const char* path)
{
string get_icon_for_path(const std::string& path)
{
using namespace Glib;
using namespace Gio;
// FIXME: I don't know whether i should use Volume or Mount or UnixMount
// all i need an icon name.
RefPtr<VolumeMonitor> monitor = VolumeMonitor::get();
std::vector<RefPtr<Mount> > mounts = monitor->get_mounts();
for (size_t i = 0; i != mounts.size(); ++i) {
if (mounts[i]->get_name() != path)
continue;
RefPtr<Icon> icon = mounts[i]->get_icon();
RefPtr<ThemedIcon> themed_icon = RefPtr<ThemedIcon>::cast_dynamic(icon);
GVolumeMonitor *monitor;
GList *mounts;
uint i;
GMount *mount;
GIcon *icon;
const char* name = "";
monitor = g_volume_monitor_get ();
mounts = g_volume_monitor_get_mounts (monitor);
for (i = 0; i < g_list_length (mounts); i++) {
mount = G_MOUNT (g_list_nth_data(mounts, i));
if (strcmp(g_mount_get_name(mount), path))
continue;
icon = g_mount_get_icon (mount);
if (!icon)
continue;
name = g_icon_to_string (icon);
g_object_unref (icon);
}
if (themed_icon) {
char* name = 0;
// FIXME: not wrapped yet
g_object_get(G_OBJECT(themed_icon->gobj()), "name", &name, NULL);
return make_string(name);
}
}
g_list_free_full (mounts, g_object_unref);
return name;
return "";
}
}
static Glib::RefPtr<Gdk::Pixbuf>
static GdkPixbuf*
get_icon_for_device(const char *mountpoint)
{
procman::IconThemeWrapper icon_theme;
string icon_name = get_icon_for_path(mountpoint);
if (icon_name == "")
const char* icon_name = get_icon_for_path(mountpoint);
if (!strcmp(icon_name, ""))
// FIXME: defaults to a safe value
icon_name = "drive-harddisk"; // get_icon_for_path("/");
return icon_theme->load_icon(icon_name, 24, Gtk::ICON_LOOKUP_USE_BUILTIN);
return gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), icon_name, 24, GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
}
......@@ -184,7 +176,7 @@ remove_old_disks(GtkTreeModel *model, const glibtop_mountentry *entries, guint n
static void
add_disk(GtkListStore *list, const glibtop_mountentry *entry, bool show_all_fs)
{
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
GdkPixbuf* pixbuf;
GtkTreeIter iter;
glibtop_fsusage usage;
guint64 bused, bfree, bavail, btotal;
......@@ -209,7 +201,7 @@ add_disk(GtkListStore *list, const glibtop_mountentry *entry, bool show_all_fs)
gtk_list_store_append(list, &iter);
gtk_list_store_set(list, &iter,
DISK_ICON, pixbuf->gobj(),
DISK_ICON, pixbuf,
DISK_DEVICE, entry->devname,
DISK_DIR, entry->mountdir,
DISK_TYPE, entry->type,
......
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <config.h>
#include <gtkmm/icontheme.h>
#include <giomm/error.h>
#include "iconthemewrapper.h"
Glib::RefPtr<Gdk::Pixbuf>
procman::IconThemeWrapper::load_icon(const Glib::ustring& icon_name,
int size, Gtk::IconLookupFlags flags) const
{
try
{
return Gtk::IconTheme::get_default()->load_icon(icon_name, size, flags);
}
catch (Gtk::IconThemeError &error)
{
if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND)
g_error("Cannot load icon '%s' from theme: %s", icon_name.c_str(), error.what().c_str());
return Glib::RefPtr<Gdk::Pixbuf>();
}
catch (Gio::Error &error)
{
g_debug("Could not load icon '%s' : %s", icon_name.c_str(), error.what().c_str());
return Glib::RefPtr<Gdk::Pixbuf>();
}
}
Glib::RefPtr<Gdk::Pixbuf>
procman::IconThemeWrapper::load_gicon(const Glib::RefPtr<Gio::Icon>& gicon,
int size, Gtk::IconLookupFlags flags) const
{
Gtk::IconInfo icon_info;
icon_info = Gtk::IconTheme::get_default()->lookup_icon(gicon, size, flags);
if (!icon_info) {
return Glib::RefPtr<Gdk::Pixbuf>();
}
try
{
return icon_info.load_icon();
}
catch (Gtk::IconThemeError &error)
{
if (error.code() != Gtk::IconThemeError::ICON_THEME_NOT_FOUND)
g_error("Cannot load gicon from theme: %s", error.what().c_str());
return Glib::RefPtr<Gdk::Pixbuf>();
}
catch (Gio::Error &error)
{
g_debug("Could not load gicon: %s", error.what().c_str());
return Glib::RefPtr<Gdk::Pixbuf>();
}
}
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#ifndef _GSM_ICON_THEME_WRAPPER_H_
#define _GSM_ICON_THEME_WRAPPER_H_
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <gtkmm/icontheme.h>
#include <gdkmm/pixbuf.h>
namespace procman
{
class IconThemeWrapper
{
public:
// returns 0 instead of raising an exception
Glib::RefPtr<Gdk::Pixbuf>
load_icon(const Glib::ustring& icon_name, int size, Gtk::IconLookupFlags flags) const;
Glib::RefPtr<Gdk::Pixbuf>
load_gicon(const Glib::RefPtr<Gio::Icon>& gicon, int size, Gtk::IconLookupFlags flags) const;
const IconThemeWrapper* operator->() const
{ return this; }
};
}
#endif /* _GSM_ICON_THEME_WRAPPER_H_ */
......@@ -77,7 +77,7 @@ PrettyTable::on_application_opened(WnckScreen* screen, WnckApplication* app, gpo
Glib::RefPtr<Gdk::Pixbuf> icon;
icon = that->theme->load_icon(icon_name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
icon = Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), icon_name, APP_ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL));
if (not icon) {
icon = Glib::wrap(wnck_application_get_icon(app), /* take_copy */ true);
......@@ -156,7 +156,7 @@ void PrettyTable::file_monitor_event(Glib::RefPtr<Gio::File>,
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_from_theme(const ProcInfo &info)
{
return this->theme->load_icon(info.name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN | Gtk::ICON_LOOKUP_FORCE_SIZE);
return Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), info.name, APP_ICON_SIZE, (GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_FORCE_SIZE), NULL));
}
......@@ -189,7 +189,7 @@ PrettyTable::get_icon_from_default(const ProcInfo &info)
IconCache::iterator it(this->defaults.find(name));
if (it == this->defaults.end()) {
pix = this->theme->load_icon(name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN | Gtk::ICON_LOOKUP_FORCE_SIZE);
pix = Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), name.c_str(), APP_ICON_SIZE, (GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_FORCE_SIZE), NULL));
if (pix)
this->defaults[name] = pix;
} else
......@@ -209,12 +209,16 @@ PrettyTable::get_icon_from_gio(const ProcInfo &info)
if (executable) {
Glib::RefPtr<Gio::AppInfo> app = this->gio_apps[executable];
Glib::RefPtr<Gio::Icon> gicon;
Gtk::IconInfo info;
if (app)
gicon = app->get_icon();
if (gicon)
icon = this->theme->load_gicon(gicon, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN | Gtk::ICON_LOOKUP_FORCE_SIZE);
info = Glib::wrap(gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), gicon->gobj(), APP_ICON_SIZE, (GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_FORCE_SIZE)));
if (info)
icon = Glib::wrap(gtk_icon_info_load_icon (info.gobj(), NULL));
}
g_strfreev(cmdline);
......@@ -240,14 +244,14 @@ PrettyTable::get_icon_from_wnck(const ProcInfo &info)
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_from_name(const ProcInfo &info)
{
return this->theme->load_icon(info.name, APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN | Gtk::ICON_LOOKUP_FORCE_SIZE);
return Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), info.name, APP_ICON_SIZE, (GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_FORCE_SIZE), NULL));
}
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_dummy(const ProcInfo &)
{
return this->theme->load_icon("application-x-executable", APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
return Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "application-x-executable", APP_ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL));
}
......@@ -273,7 +277,7 @@ Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_for_kernel(const ProcInfo &info)
{
if (is_kthread(info))
return this->theme->load_icon("applications-system", APP_ICON_SIZE, Gtk::ICON_LOOKUP_USE_BUILTIN);
return Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "applications-system", APP_ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN, NULL));
return Glib::RefPtr<Gdk::Pixbuf>();
}
......
......@@ -19,8 +19,6 @@ extern "C" {
}
#endif
#include "iconthemewrapper.h"
class ProcInfo;
using std::string;
......@@ -70,7 +68,6 @@ private:
IconCache defaults;
DesktopDirMonitors monitors;
AppCache gio_apps;
procman::IconThemeWrapper theme;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment