ayttm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Ayttm-commits] CVS: ayttm/src prefs.c,1.19,1.20


From: Andy Maloney <address@hidden>
Subject: [Ayttm-commits] CVS: ayttm/src prefs.c,1.19,1.20
Date: Mon, 20 Jan 2003 09:06:33 -0500

Update of /cvsroot/ayttm/ayttm/src
In directory subversions:/tmp/cvs-serv6054/src

Modified Files:
        prefs.c 
Log Message:
Cleanup the plugin prefs window [this was driving me nuts!]

Index: prefs.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/prefs.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- prefs.c     17 Jan 2003 23:21:42 -0000      1.19
+++ prefs.c     20 Jan 2003 14:06:31 -0000      1.20
@@ -24,17 +24,11 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include "intl.h"
-#include <gtk/gtk.h>
+
 #include <gdk/gdkkeysyms.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <glib.h>
 
 #include "dialog.h"
 #include "service.h"
@@ -42,7 +36,6 @@
 #include "libproxy/libproxy.h"
 #include "sound.h"
 #include "defaults.h"
-#include "input_list.h"
 #include "value_pair.h"
 #include "gtk_globals.h"
 #include "status.h"
@@ -224,7 +217,6 @@
  *
  */
 
-static GtkWidget       *plugin_prefs_win = NULL;
 static GtkWidget       *length_contact_window_entry = NULL;
 static GtkWidget       *font_size_entry = NULL;
 static GtkWidget       *alternate_browser_entry = NULL;
@@ -876,6 +868,7 @@
        gtk_widget_destroy(font_size_entry);
        font_size_entry=NULL;
 }
+
 /*
  * Proxies Preferences Tab
  */
@@ -1243,6 +1236,12 @@
 
 #endif
 
+/*
+ * Plugin Preferences Tab
+ */
+
+static GtkWidget       *plugin_prefs_win = NULL;
+
 /* Used when loading service modules later, so passwords and user names are 
still available
  * as service:username */
 void save_account_info(char *service, GList *pairs)
@@ -1349,26 +1348,6 @@
        gtk_widget_draw(GTK_WIDGET(profile_submenuitem), NULL);
 }
 
-/*
-void rebuild_connections_prefs()
-{
-       GtkWidget *prefs_note, *connections_tab;
-       static int connections_page=0;
-
-       connections_tab = GetPref("widget::connections_tab");
-       prefs_note = GetPref("widget::prefs_note");
-       connections_page = gtk_notebook_page_num(GTK_NOTEBOOK(prefs_note), 
connections_tab);
-       gtk_notebook_remove_page(GTK_NOTEBOOK(prefs_note), connections_page);
-       SetPref("connections_page_num", &connections_page);
-       build_connections_prefs(prefs_note);
-       // Remove the page number for future builds of the prefs screen that 
are not from a reload
-       SetPref("connections_page_num", NULL);
-       // Need to refresh the widget -- 
-       //      This forces the widget to redraw itself. 
-       gtk_widget_draw(GTK_WIDGET(prefs_note), NULL);
-}
-*/
-
 static void reload_modules(GtkWidget * w, int * data)
 {
         GtkWidget *module_list;
@@ -1386,7 +1365,6 @@
         cSetLocalPref("modules_path", modules_path);
         load_modules();
         build_modules_list(module_list);
-//      rebuild_connections_prefs();
         rebuild_set_status_menu();
         rebuild_import_menu();
         rebuild_profile_menu();
@@ -1442,7 +1420,6 @@
        gtk_clist_insert(PCD->clist, PCD->row, module_info);
        if(PCD->epi->pi.type==PLUGIN_SERVICE)
        {
-//             rebuild_connections_prefs();
                rebuild_set_status_menu();
        }
 }
@@ -1466,7 +1443,6 @@
                eb_debug(DBG_CORE, "Unloaded plugin %s\n", PCD->epi->name);
                if(PCD->epi->pi.type==PLUGIN_SERVICE)
                {
-//                     rebuild_connections_prefs();
                        rebuild_set_status_menu();
                }
        }
@@ -1478,11 +1454,23 @@
 {
        eb_debug(DBG_MOD, "updating prefs\n");
        eb_input_accept(prefs);
+       
        gtk_widget_destroy(plugin_prefs_win);
+       plugin_prefs_win = NULL;
+}
+
+static void cancel_plugin_prefs( GtkWidget *w, input_list *prefs )
+{
+       eb_debug(DBG_MOD, "canceling prefs\n");
+       eb_input_cancel( prefs );
+       
+       gtk_widget_destroy( plugin_prefs_win );
+       plugin_prefs_win = NULL;
 }
 
 static void destroy_plugin_prefs(GtkWidget *w, void * data)
 {
+       gtk_widget_destroy( plugin_prefs_win );
        plugin_prefs_win = NULL;
 }
 
@@ -1551,54 +1539,153 @@
        }
        else if(event->button == 1)
        {
-               GtkWidget *plugin_prefs_w=GetPref("widget::plugin_prefs_w");
+               GString         *windowName = g_string_new( NULL );
+               const char      *pluginDescr = _("Plugin");
+               
+               if ( epi->service != NULL )
+                       pluginDescr = epi->service;
+               
+               windowName = g_string_append( windowName, pluginDescr );
+               windowName = g_string_append( windowName, _(" Preferences") );
+               
                eb_debug(DBG_MOD, "Setting prefs for %s\n", plugin_path);
 
-               /* If the window already has a child, destroy it. */
-               if(plugin_prefs_win!=NULL)
+               /* Create the window if it doesn't exist. */
+               if ( plugin_prefs_win == NULL )
+               {
+                       plugin_prefs_win = gtk_window_new( GTK_WINDOW_DIALOG );
+                       gtk_widget_realize( plugin_prefs_win );
+                       
+                       gtk_window_set_position( GTK_WINDOW(plugin_prefs_win), 
GTK_WIN_POS_MOUSE) ;
+                       gtk_window_set_policy( GTK_WINDOW(plugin_prefs_win), 
FALSE, FALSE, TRUE );
+                                                       
+                       gtk_container_border_width( 
GTK_CONTAINER(plugin_prefs_win), 5 );
+
+                       gtk_signal_connect(GTK_OBJECT(plugin_prefs_win), 
"destroy",
+                                          
GTK_SIGNAL_FUNC(destroy_plugin_prefs), NULL );
+               }
+               else
                {
-                       gtk_widget_destroy(plugin_prefs_win);
-                       gtk_widget_destroy(GTK_BIN(plugin_prefs_w)->child);
+                       /* otherwise just destroy it's current contents */
+                       gtk_widget_destroy( GTK_BIN(plugin_prefs_win)->child );
                }
                
-               plugin_prefs_w=gtk_scrolled_window_new(NULL,NULL);
-               
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(plugin_prefs_w),
-                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-               gtk_widget_set_usize(plugin_prefs_w, 300, 300);
-               SetPref("widget::plugin_prefs_w", plugin_prefs_w);
-               /*gtk_box_pack_start(GTK_BOX(vbox), w, TRUE, TRUE, 10);*/
-               plugin_prefs_win = gtk_window_new(GTK_WINDOW_DIALOG);
-               gtk_window_set_position(GTK_WINDOW(plugin_prefs_win), 
GTK_WIN_POS_MOUSE);
-               gtk_window_set_title(GTK_WINDOW(plugin_prefs_win), _("Plugin 
preferences"));
-               gtk_container_add(GTK_CONTAINER(plugin_prefs_win), 
plugin_prefs_w);
-               gtk_widget_hide(plugin_prefs_win);
-
-               if(epi->pi.prefs)
+               gtk_window_set_title( GTK_WINDOW(plugin_prefs_win), 
windowName->str );
+               
+               if ( epi->pi.prefs != NULL )
                {
-                       GtkWidget *button;
-                       GtkWidget *hbox;
-                       GtkWidget *vbox;
-                       vbox = gtk_vbox_new(FALSE, 5);
-                       eb_input_render(epi->pi.prefs, vbox);
-
-                       hbox = gtk_hbox_new(TRUE, 50);
-                       button = eb_push_button(_("Update"), hbox);
-                       gtk_widget_show(hbox);
+                       GtkWidget       *button = NULL;
+                       GtkWidget       *hbox = NULL;
+                       GtkWidget       *label = NULL;
+                       GtkWidget       *iconwid = NULL;
+                       GdkPixmap       *icon = NULL;
+                       GdkBitmap       *mask = NULL;
+                       GtkWidget       *buttonHBox = gtk_hbox_new( TRUE, 5 );
+                       GtkWidget       *vbox = gtk_vbox_new( FALSE, 5 );
+
+
+                       /* Show the plugin prefs */
+                       eb_input_render( epi->pi.prefs, vbox );
+                       
+                       gtk_widget_set_usize( buttonHBox, 200, 25 );
+                       gtk_widget_show( buttonHBox );
+                                 
+                       /* OK Button*/
+                       hbox = gtk_hbox_new( FALSE, 5 );
+
+                       icon = gdk_pixmap_create_from_xpm_d( 
plugin_prefs_win->window, &mask, NULL, ok_xpm );
+                       iconwid = gtk_pixmap_new( icon, mask );
+                       label = gtk_label_new( _("Ok") );
+                       button = gtk_button_new();
+                       
+                       gtk_box_pack_start( GTK_BOX(hbox), iconwid, FALSE, 
FALSE, 2 );
+                       gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, FALSE, 
2 );
+
+                       gtk_widget_show( iconwid );
+                       gtk_widget_show( label );
+                       gtk_widget_show( hbox );
+                       gtk_widget_show( button );
+
+                       gtk_signal_connect( GTK_OBJECT(button), "clicked",
+                                       GTK_SIGNAL_FUNC(update_plugin_prefs), 
(gpointer)epi->pi.prefs );
+            
+                       gtk_container_add( GTK_CONTAINER(button), hbox );
+   
+                       gtk_box_pack_start( GTK_BOX(buttonHBox), button, TRUE, 
TRUE, 5 );
+   
+                       /*Cancel Button*/
+                       hbox = gtk_hbox_new( FALSE, 5 );
 
-                       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 
0);
+                       icon = 
gdk_pixmap_create_from_xpm_d(plugin_prefs_win->window, &mask, NULL, cancel_xpm);
+                       iconwid = gtk_pixmap_new(icon, mask);
+                       label = gtk_label_new(_("Cancel"));
+                       button = gtk_button_new();
+
+                       gtk_box_pack_start(GTK_BOX(hbox), iconwid, FALSE, 
FALSE, 2);
+                       gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 
2);
+
+                       gtk_widget_show( iconwid );
+                       gtk_widget_show( label  );
+                       gtk_widget_show( hbox );
+                       gtk_widget_show( button );
+                       
                        gtk_signal_connect(GTK_OBJECT(button), "clicked",
-                                       GTK_SIGNAL_FUNC(update_plugin_prefs), 
(gpointer)epi->pi.prefs);
-                       gtk_scrolled_window_add_with_viewport
-                               (GTK_SCROLLED_WINDOW(plugin_prefs_w),
-                               vbox);
-                       gtk_widget_show(vbox);
-                       gtk_widget_show(plugin_prefs_w);
-                       gtk_widget_show(plugin_prefs_win);
-                       gtk_signal_connect(GTK_OBJECT(plugin_prefs_win), 
"destroy",
-                                          
GTK_SIGNAL_FUNC(destroy_plugin_prefs), NULL );
+                                          
GTK_SIGNAL_FUNC(cancel_plugin_prefs), (gpointer)epi->pi.prefs );
+
+                       gtk_container_add( GTK_CONTAINER (button), hbox );
+
+                       gtk_box_pack_start( GTK_BOX(buttonHBox), button, TRUE, 
TRUE, 5 );
+
+                       /* ICK!  use another hbox to put the buttons over on 
the right */
+                       hbox = gtk_hbox_new( FALSE, 5 );
+                       gtk_widget_show( hbox );        
+                       gtk_box_pack_end( GTK_BOX(hbox), buttonHBox, FALSE, 
FALSE, 5 );
+
+                       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 
5);
+
+                       gtk_widget_show( vbox );
+
+                       gtk_container_add( GTK_CONTAINER(plugin_prefs_win), 
GTK_WIDGET(vbox) );
                }
                else
+               {
+                       GtkLabel        *label = GTK_LABEL(gtk_label_new( NULL 
));
+                       GString         *labelText = g_string_new( _("No 
preferences for ") );
+                       gint            newWidth = 0;
+                       gint            newHeight = 0;
+                       
+                       if ( epi->service != NULL )
+                       {
+                               labelText = g_string_append( labelText, 
epi->service );
+                       }
+                       else
+                       {
+                               labelText = g_string_append( labelText, "'" );
+                               labelText = g_string_append( labelText, 
epi->pi.brief_desc );
+                               labelText = g_string_append( labelText, "'" );
+                       }
+                       
+                       gtk_label_set_text( label, labelText->str );
+                       gtk_widget_show( GTK_WIDGET(label) );
+
+                       /* adjust to a reasonable height if necessary */
+                       newHeight = GTK_WIDGET(label)->allocation.height;
+                       if ( newHeight < 50 )
+                               newHeight = 50;
+                               
+                       gtk_widget_set_usize( GTK_WIDGET(label), newWidth, 
newHeight );
+                       
+                       gtk_container_add(GTK_CONTAINER(plugin_prefs_win), 
GTK_WIDGET(label));
+
                        eb_debug(DBG_MOD, "No prefs defined for %s\n", 
plugin_path);
+               
+                       g_string_free( labelText, TRUE );
+               }
+               
+               gtk_widget_show( plugin_prefs_win );
+               gdk_window_raise( plugin_prefs_win->window );
+               
+               g_string_free( windowName, TRUE );
        }
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]