/* rggladewindow.cc * * Copyright (c) 2003 Michael Vogt * * Author: Michael Vogt * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include #include #include "config.h" #include "i18n.h" #include "rggladewindow.h" /* the convention is that the top window is named: "window_$windowname" in your glade-source */ RGGladeWindow::RGGladeWindow(RGWindow *parent, string name, string mainName) { //std::cout << "RGGladeWindow::RGGladeWindow(parent,name)" << endl; _busyCursor = gdk_cursor_new(GDK_WATCH); // for development gchar *filename = NULL; gchar *main_widget = NULL; filename = g_strdup_printf("window_%s.glade", name.c_str()); if (mainName.empty()) main_widget = g_strdup_printf("window_%s", name.c_str()); else main_widget = g_strdup_printf("window_%s", mainName.c_str()); if (FileExists(filename)) { _gladeXML = glade_xml_new(filename, main_widget, NULL); } else { g_free(filename); filename = g_strdup_printf(SYNAPTIC_GLADEDIR "window_%s.glade", name.c_str()); _gladeXML = glade_xml_new(filename, main_widget, NULL); } assert(_gladeXML); _win = glade_xml_get_widget(_gladeXML, main_widget); gtk_window_set_position(GTK_WINDOW(_win), GTK_WIN_POS_CENTER_ON_PARENT); if(parent != NULL) gtk_window_set_transient_for(GTK_WINDOW(_win), GTK_WINDOW(parent->window())); assert(_win); g_free(filename); g_free(main_widget); //gtk_window_set_title(GTK_WINDOW(_win), (char *)name.c_str()); gtk_object_set_data(GTK_OBJECT(_win), "me", this); gtk_signal_connect(GTK_OBJECT(_win), "delete-event", (GtkSignalFunc) windowCloseCallback, this); _topBox = NULL; //gtk_widget_realize(_win); // if we have no parent, don't skip the taskbar hint int id = _config->FindI("Volatile::ParentWindowId", -1); if(_config->FindB("Volatile::HideMainwindow",false) && id < 0) { gtk_window_set_skip_taskbar_hint(GTK_WINDOW(_win), FALSE); gtk_window_set_urgency_hint(GTK_WINDOW(_win), TRUE); } } bool RGGladeWindow::setLabel(const char *widget_name, const char *value) { GtkWidget *widget = glade_xml_get_widget(_gladeXML, widget_name); if (widget == NULL) { cout << "widget == NULL with: " << widget_name << endl; return false; } if (!value) value = _("N/A"); gtk_label_set_label(GTK_LABEL(widget), utf8(value)); return true; } bool RGGladeWindow::setLabel(const char *widget_name, const long value) { string strVal; GtkWidget *widget = glade_xml_get_widget(_gladeXML, widget_name); if (widget == NULL) { cout << "widget == NULL with: " << widget_name << endl; return false; } // we can never have values of zero or less if (value <= 0) // TRANSLATORS: this is a abbreviation for "not applicable" (on forms) // happens when e.g. a package has no installed version (or no // downloadable version) strVal = _("N/A"); else strVal = SizeToStr(value); gtk_label_set_label(GTK_LABEL(widget), utf8(strVal.c_str())); return true; } bool RGGladeWindow::setTreeList(const char *widget_name, vector values, bool use_markup) { char *type; string strVal; GtkWidget *widget = glade_xml_get_widget(_gladeXML, widget_name); if (widget == NULL) { cout << "widget == NULL with: " << widget_name << endl; return false; } // create column (if needed) if(gtk_tree_view_get_column(GTK_TREE_VIEW(widget), 0) == NULL) { // cell renderer GtkCellRenderer *renderer; renderer = gtk_cell_renderer_text_new(); if(use_markup) type = "markup"; else type = "text"; GtkTreeViewColumn *column; column = gtk_tree_view_column_new_with_attributes("SubView", renderer, type, 0, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(widget), column); } // store stuff GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING); GtkTreeIter iter; for(unsigned int i=0;iwindow, _busyCursor); #if GTK_CHECK_VERSION(2,4,0) // if we don't iterate here, the busy cursor is not shown while (gtk_events_pending()) gtk_main_iteration(); #endif } else { if(GTK_WIDGET_VISIBLE(_win)) gdk_window_set_cursor(window()->window, NULL); } }