implemented sensor logging
[psensor.git] / src / main.c
index 8b6330e..164f10a 100644 (file)
@@ -37,6 +37,7 @@
 #include "ui_sensorlist.h"
 #include "ui_color.h"
 #include "lmsensor.h"
+#include "slog.h"
 #include "ui_pref.h"
 #include "ui_graph.h"
 #include "ui_status.h"
@@ -118,23 +119,20 @@ static void print_help()
 }
 
 /*
-  Updates the size of the sensor values if different than the
-  configuration.
* Updates the size of the sensor values if different than the
* configuration.
  */
-void
+static void
 update_psensor_values_size(struct psensor **sensors, struct config *cfg)
 {
-       struct psensor **cur;
+       struct psensor **cur, *s;
 
-       cur = sensors;
-       while (*cur) {
-               struct psensor *s = *cur;
+       for (cur = sensors; *cur; cur++) {
+               s = *cur;
 
                if (s->values_max_length != cfg->sensor_values_max_length)
                        psensor_values_resize(s,
                                              cfg->sensor_values_max_length);
-
-               cur++;
        }
 }
 
@@ -168,6 +166,9 @@ static void update_measures(struct ui_psensor *ui)
 
                psensor_log_measures(sensors);
 
+               if (cfg->slog_enabled)
+                       slog_write_sensors(sensors);
+
                period = cfg->sensor_update_interval;
 
                g_mutex_unlock(ui->sensors_mutex);
@@ -325,6 +326,8 @@ static void associate_preferences(struct psensor **sensors)
                        s->name = n;
                }
 
+               s->appindicator_enabled = config_is_appindicator_enabled(s->id);
+
                sensor_cur++;
        }
 }
@@ -518,7 +521,7 @@ int main(int argc, char **argv)
                        exit(EXIT_SUCCESS);
                case 'd':
                        log_level = atoi(optarg);
-                       log_printf(LOG_INFO, _("Enables debug mode."));
+                       log_info(_("Enables debug mode."));
                        break;
                case 'n':
                        new_instance = 1;
@@ -603,16 +606,16 @@ int main(int argc, char **argv)
        ui_appindicator_init(&ui);
 #endif
 
-       /*
-        * show the window as soon as all gtk events have been processed
-        * in order to ensure that the status icon is attempted to be
-        * drawn before. If not, there is no way to detect that it is
-        * visible.
-       */
-       g_idle_add((GSourceFunc)initial_window_show, &ui);
-
        gdk_notify_startup_complete();
 
+       /*
+        * hack, did not find a cleaner solution.
+        * wait 2s to ensure that the status icon is attempted to be
+        * drawn before determining whether the main window must be
+        * show.
+        */
+       g_timeout_add(2000, (GSourceFunc)initial_window_show, &ui);
+
        /* main loop */
        gtk_main();