[MPlayer-cvslog] r38525 - in trunk/gui: dialog/url.c gtk-compat.h

ib subversion at mplayerhq.hu
Thu May 16 23:11:53 EEST 2024


Author: ib
Date: Thu May 16 23:11:53 2024
New Revision: 38525

Log:
Disable the OK button of the URL dialog unless an entry has been made.

Modified:
   trunk/gui/dialog/url.c
   trunk/gui/gtk-compat.h

Modified: trunk/gui/dialog/url.c
==============================================================================
--- trunk/gui/dialog/url.c	Thu May 16 23:09:10 2024	(r38524)
+++ trunk/gui/dialog/url.c	Thu May 16 23:11:53 2024	(r38525)
@@ -37,6 +37,14 @@ GtkWidget *URLDialog;
 
 static GtkWidget *urlCombo;
 
+static void entry_changed(GtkComboBox *combo_box, gpointer user_data)
+{
+    gboolean set = (*gtk_entry_get_text(gtkEntry(GTK_WIDGET(combo_box))) != 0);
+
+    if (gtk_widget_get_sensitive(GTK_WIDGET(user_data)) ^ set)
+        gtk_widget_set_sensitive(GTK_WIDGET(user_data), set);
+}
+
 /**
  * @brief Add the entered URL to the URL list and stream it,
  *        if the button clicked is the OK button
@@ -55,7 +63,7 @@ static void button_clicked(GtkButton *bu
     if (user_data) {
         char *str = strdup(gtk_entry_get_text(gtkEntry(urlCombo)));
 
-        if (str) {
+        if (str && *str) {
             if (!strstr(str, "://")) {
                 char *tmp = malloc(strlen(str) + 8);
 
@@ -125,6 +133,8 @@ static GtkWidget *CreateURLDialog(void)
     Ok     = gtkAddButton(_(MSGTR_GUI_Ok), hbuttonbox1);
     Cancel = gtkAddButton(_(MSGTR_GUI_Cancel), hbuttonbox1);
 
+    gtk_widget_set_sensitive(Ok, FALSE);
+
     geometry.max_width  = gdk_screen_get_width(gtk_widget_get_screen(URLDialog));
     geometry.max_height = -1;
     gtk_window_set_geometry_hints(GTK_WINDOW(URLDialog), NULL, &geometry, GDK_HINT_MAX_SIZE);
@@ -133,6 +143,7 @@ static GtkWidget *CreateURLDialog(void)
     gtk_widget_add_accelerator(Cancel, "clicked", accel_group, GDK_KEY_Escape, 0, GTK_ACCEL_VISIBLE);
 
     g_signal_connect(G_OBJECT(URLDialog), "destroy", G_CALLBACK(gtk_widget_destroyed), &URLDialog);
+    g_signal_connect(G_OBJECT(urlCombo), "changed", G_CALLBACK(entry_changed), Ok);
     g_signal_connect(G_OBJECT(Ok), "clicked", G_CALLBACK(button_clicked), Ok);
     g_signal_connect(G_OBJECT(Cancel), "clicked", G_CALLBACK(button_clicked), NULL);
 

Modified: trunk/gui/gtk-compat.h
==============================================================================
--- trunk/gui/gtk-compat.h	Thu May 16 23:09:10 2024	(r38524)
+++ trunk/gui/gtk-compat.h	Thu May 16 23:11:53 2024	(r38525)
@@ -35,6 +35,10 @@
 #define gtk_widget_get_window(widget) widget->window
 #endif
 
+#if !GTK_CHECK_VERSION(2,18,0)
+#define gtk_widget_get_sensitive(widget) GTK_WIDGET_SENSITIVE(widget)
+#endif
+
 #if !GTK_CHECK_VERSION(2,22,0)
 #define GDK_KEY_BackSpace GDK_BackSpace
 #define GDK_KEY_Escape GDK_Escape


More information about the MPlayer-cvslog mailing list