panel-pref: add option for log level
authorHenry Gebhardt <hsggebhardt@googlemail.com>
Thu, 26 Jul 2012 00:48:05 +0000 (02:48 +0200)
committerHenry Gebhardt <hsggebhardt@googlemail.com>
Wed, 1 Aug 2012 11:54:19 +0000 (13:54 +0200)
data/ui/panel-pref.glade
src/configurator.c
src/dbg.c
src/dbg.h
src/panel.c

index 3bc672c..52e9a70 100644 (file)
       </row>
     </data>
   </object>
+  <object class="GtkListStore" id="liststore3">
+    <columns>
+      <!-- column-name item -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">None</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Err</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Warn</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Info</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">All</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkDialog" id="panel_pref">
     <property name="visible">True</property>
     <property name="title" translatable="yes">Panel Preferences</property>
                     <property name="position">2</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkFrame" id="frame8">
+                    <property name="visible">True</property>
+                    <property name="label_xalign">0</property>
+                    <property name="shadow_type">none</property>
+                    <child>
+                      <object class="GtkAlignment" id="alignment9">
+                        <property name="visible">True</property>
+                        <property name="left_padding">12</property>
+                        <child>
+                          <object class="GtkAlignment" id="alignment10">
+                            <property name="visible">True</property>
+                            <property name="yalign">0</property>
+                            <property name="yscale">0</property>
+                            <child>
+                              <object class="GtkHBox" id="hbox7">
+                                <property name="visible">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label17">
+                                    <property name="visible">True</property>
+                                    <property name="xalign">0</property>
+                                    <property name="label" translatable="yes">Log level</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkComboBox" id="log_level">
+                                    <property name="visible">True</property>
+                                    <property name="model">liststore3</property>
+                                    <property name="active">2</property>
+                                    <child>
+                                      <object class="GtkCellRendererText" id="cellrenderertext3"/>
+                                      <attributes>
+                                        <attribute name="text">0</attribute>
+                                      </attributes>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child type="label">
+                      <object class="GtkLabel" id="label16">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">&lt;b&gt;Log level&lt;/b&gt;</property>
+                        <property name="use_markup">True</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="position">3</property>
index 28da644..80d0de3 100644 (file)
@@ -241,6 +241,15 @@ static void set_width_type( GtkWidget *item, Panel* p )
     update_panel_geometry(p);
 }
 
+static void set_log_level( GtkWidget *cbox, Panel* p)
+{
+    configured_log_level = gtk_combo_box_get_active(GTK_COMBO_BOX(cbox));
+    if (!log_level_set_on_commandline)
+        log_level = configured_log_level;
+    ERR("panel-pref: log level configured to %d, log_level is now %d\n",
+            configured_log_level, log_level);
+}
+
 static void transparency_toggle( GtkWidget *b, Panel* p)
 {
     GtkWidget* tr = (GtkWidget*)g_object_get_data(G_OBJECT(b), "tint_clr");
@@ -1085,6 +1094,11 @@ void panel_configure( Panel* p, int sel_page )
                         &logout_cmd);
     }
 
+    w = (GtkWidget*)gtk_builder_get_object( builder, "log_level" );
+    update_opt_menu(w, configured_log_level);
+    g_signal_connect(w, "changed", G_CALLBACK(set_log_level), p);
+
+
     panel_adjust_geometry_terminology(p);
     gtk_widget_show(GTK_WIDGET(p->pref_dialog));
     w = (GtkWidget*)gtk_builder_get_object( builder, "notebook" );
@@ -1119,6 +1133,7 @@ panel_global_config_save( Panel* p, FILE *fp)
     lxpanel_put_bool(fp, "background", p->background );
     lxpanel_put_str(fp, "backgroundfile", p->background_file);
     lxpanel_put_int(fp, "iconsize", p->icon_size);
+    lxpanel_put_int(fp, "loglevel", configured_log_level);
     lxpanel_put_line(fp, "}\n");
 }
 
index 953a354..2e9153b 100644 (file)
--- a/src/dbg.c
+++ b/src/dbg.c
@@ -19,6 +19,8 @@
 #include "dbg.h"
 
 int log_level = LOG_WARN;
+bool log_level_set_on_commandline = false;
+int configured_log_level = LOG_WARN;
 
 
 
index 43009c9..50dae0f 100644 (file)
--- a/src/dbg.h
+++ b/src/dbg.h
@@ -17,6 +17,7 @@
  */
 
 #include <stdio.h>
+#include <stdbool.h>
 #include <cairo/cairo.h>
 
 #define ERR(fmt, args...) fprintf(stderr, fmt, ## args)
 return args; } while(0)
 
 enum { LOG_NONE, LOG_ERR, LOG_WARN, LOG_INFO, LOG_ALL };
+
+extern int log_level;
+extern bool log_level_set_on_commandline;
+extern int configured_log_level;
+
 #ifdef DEBUG
 
 #define ENTER          do { fprintf(stderr, "%s:%s:%-5d: ENTER\n",  __FILE__,__FUNCTION__, __LINE__); } while(0)
@@ -36,7 +42,6 @@ return args; } while(0)
 
 #else
 
-extern int log_level;
 #define ENTER         do {  } while(0)
 #define RET(args...)   return args
 #define DBG(fmt, args...)   do {  } while(0)
index c71ad35..f5c76be 100644 (file)
@@ -1252,6 +1252,10 @@ panel_parse_global(Panel *p, char **fp)
                     p->background_file = g_strdup( s.t[1] );
                 } else if (!g_ascii_strcasecmp(s.t[0], "IconSize")) {
                     p->icon_size = atoi(s.t[1]);
+                } else if (!g_ascii_strcasecmp(s.t[0], "LogLevel")) {
+                    configured_log_level = atoi(s.t[1]);
+                    if (!log_level_set_on_commandline)
+                        log_level = configured_log_level;
                 } else {
                     ERR( "lxpanel: %s - unknown var in Global section\n", s.t[0]);
                 }
@@ -1634,6 +1638,7 @@ int main(int argc, char *argv[], char *env[])
                 exit(1);
             } else {
                 log_level = atoi(argv[i]);
+                log_level_set_on_commandline = true;
             }
         } else if (!strcmp(argv[i], "--configure") || !strcmp(argv[i], "-C")) {
             config = 1;