~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to src/release.c

  • Committer: mvo
  • Date: 2004-11-02 00:58:06 UTC
  • Revision ID: gustavo@niemeyer.net-20041102005806-9118e041eaa0ebc8
* inital checkin

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef HAVE_CONFIG_H
2
 
#include "config.h"
3
 
#endif
4
 
 
5
 
#include <glib.h>
6
 
#include <glib-object.h>
7
 
 
8
 
#include <sys/types.h>
9
 
#include <sys/wait.h>
10
 
#include <time.h>
11
 
 
12
 
#include "update-notifier.h"
13
 
 
14
 
extern gboolean DEVEL_RELEASE;
15
 
 
16
 
static inline void
17
 
g_debug_release(const char *msg, ...)
18
 
{
19
 
   va_list va;
20
 
   va_start(va, msg);
21
 
   g_logv("release",G_LOG_LEVEL_DEBUG, msg, va);
22
 
   va_end(va);
23
 
}
24
 
 
25
 
// actually show the notification 
26
 
static gboolean
27
 
check_new_release(gpointer user_data)
28
 
{
29
 
   g_debug_release ("check_new_release");
30
 
 
31
 
   GError *error = NULL;
32
 
   GConfClient *client = (GConfClient*)user_data;
33
 
   
34
 
   time_t now = time(NULL);
35
 
   time_t last_check = gconf_client_get_int(client, GCONF_KEY_LAST_RELEASE_CHECK, &error);
36
 
   if ( error != NULL ) {
37
 
      g_warning ("could not get %s", GCONF_KEY_LAST_RELEASE_CHECK);
38
 
      return FALSE;
39
 
   }
40
 
 
41
 
   // test if we need to run
42
 
   if ( (last_check + RELEASE_UPGRADE_CHECK_WAIT) > now ) {
43
 
      g_debug_release ("release upgrade check not needed (%i > %i)", last_check + RELEASE_UPGRADE_CHECK_WAIT, now);
44
 
      return TRUE;
45
 
   }
46
 
 
47
 
   // run the checker
48
 
   gchar *argv[10] = { RELEASE_UPGRADE_CHECKER, };
49
 
   if (DEVEL_RELEASE) {
50
 
      g_debug_release ("running the release upgrade checker %s in devel mode", RELEASE_UPGRADE_CHECKER);
51
 
      argv[1] = "--devel-release";
52
 
      argv[2] = NULL;
53
 
   } else {
54
 
      g_debug_release ("running the release upgrade checker %s", RELEASE_UPGRADE_CHECKER);
55
 
      argv[1] = NULL;
56
 
   }
57
 
   g_spawn_async ("/", argv, NULL, 0, NULL, NULL, NULL, NULL);
58
 
 
59
 
   // and update the timestamp so we don't check again too soon
60
 
   gconf_client_set_int(client, GCONF_KEY_LAST_RELEASE_CHECK, now, NULL);
61
 
 
62
 
   return TRUE;
63
 
}
64
 
 
65
 
gboolean
66
 
release_checker_init (UpgradeNotifier *un)
67
 
{
68
 
   g_debug_release ("release_checker_init");
69
 
 
70
 
   GConfClient *client = gconf_client_get_default();
71
 
   
72
 
   // check once at startup
73
 
   check_new_release (client);
74
 
   // release upgrades happen not that frequently, we use two timers
75
 
   // check every 10 min if 48h are reached and then run 
76
 
   // "check-release-upgrade-gtk" again
77
 
   g_timeout_add_seconds (60*10, check_new_release, client);
78
 
 
79
 
   return TRUE;
80
 
}