Commits

jjacky committed 32e23ef

Remove/alter last notifications when marking packages/news

When marking watched (AUR) packages/news, the corresponding last notification will be removed (if nothing remains unread/unmarked), or altered to inform that running checks again is required (also, the button is gone).

Also fix a bug in marking watched (AUR) packages, where garbage could end up as new version number.

  • Participants
  • Parent commits 88ae570

Comments (0)

Files changed (5)

     
     debug ("showing notif: %s", notif->summary);
     notification = new_notification (notif->summary, notif->text);
-    if (notif->type & CHECK_UPGRADES)
+    if (!notif->data)
+    {
+        /* no data means the notification was modified afterwards, as news/packages
+         * have been marked read. No more data/action button, just a simple
+         * notification (where text explains to re-do checks to be up to date) */
+    }
+    else if (notif->type & CHECK_UPGRADES)
     {
         if (   config->check_pacman_conflict
             && is_pacman_conflicting ((alpm_list_t *) notif->data))
                                         "mark_watched",
                                         "Mark packages...",
                                         (NotifyActionCallback) action_watched,
-                                        notif->data,
+                                        notif,
                                         NULL);
     }
     else if (notif->type & CHECK_WATCHED_AUR)
                                         "mark_watched_aur",
                                         "Mark packages...",
                                         (NotifyActionCallback) action_watched_aur,
-                                        notif->data,
+                                        notif,
                                         NULL);
     }
     else if (notif->type & CHECK_NEWS)
                                         "mark_news",
                                         "Show news...",
                                         (NotifyActionCallback) action_news,
-                                        notif->data,
+                                        notif,
                                         NULL);
     }
     /* we use a callback on "closed" to unref it, because when there's an action
 
 void
 action_watched (NotifyNotification *notification, char *action _UNUSED_,
-    alpm_list_t *packages)
+    notif_t *notif)
 {
     notify_notification_close (notification, NULL);
-    watched_update (packages, FALSE);
+    if (notif->data)
+    {
+        watched_update ((alpm_list_t *) notif->data, FALSE);
+    }
+    else
+    {
+        show_error ("Unable to mark watched packages",
+            "Watched packages have changed, "
+                "you need to run the checks again to be up-to-date.",
+            NULL);
+    }
 }
 
 void
 action_watched_aur (NotifyNotification *notification, char *action _UNUSED_,
-    alpm_list_t *packages)
+    notif_t *notif)
 {
     notify_notification_close (notification, NULL);
-    watched_update (packages, TRUE);
+    if (notif->data)
+    {
+        watched_update ((alpm_list_t *) notif->data, TRUE);
+    }
+    else
+    {
+        show_error ("Unable to mark watched AUR packages",
+            "Watched AUR packages have changed, "
+                "you need to run the checks again to be up-to-date.",
+            NULL);
+    }
 }
 
 void
 action_news (NotifyNotification *notification, char *action _UNUSED_,
-    gchar *xml_news)
+    notif_t *notif)
 {
     GError *error = NULL;
     
     notify_notification_close (notification, NULL);
-    set_kalpm_busy (TRUE);
-    if (!news_show (xml_news, TRUE, &error))
+    if (notif->data)
     {
-        show_error ("Unable to show the news", error->message, NULL);
-        g_clear_error (&error);
+        set_kalpm_busy (TRUE);
+        if (!news_show ((gchar *) notif->data, TRUE, &error))
+        {
+            show_error ("Unable to show the news", error->message, NULL);
+            g_clear_error (&error);
+        }
+    }
+    else
+    {
+        show_error ("Unable to show unread news",
+            "Read news have changed, you need to run the checks again to be up-to-date.",
+            NULL);
     }
 }
 
 {
     alpm_list_t *i;
     
+    /* in case e.g. the menu was shown (sensitive) before an auto-check started */
+    if (kalpm_state.is_busy)
+    {
+        return;
+    }
+    
     if (!config->last_notifs)
     {
         notif_t notif;
         
         notif.type = 0;
-        notif.summary = "No notifications to show.";
+        notif.summary = (gchar *) "No notifications to show.";
         notif.text = NULL;
         notif.data = NULL;
         
 action_upgrade (NotifyNotification *notification, const char *action, gchar *_cmdline);
 
 void
-action_watched (NotifyNotification *notification, char *action, alpm_list_t *packages);
+action_watched (NotifyNotification *notification, char *action, notif_t *notif);
 
 void
-action_watched_aur (NotifyNotification *notification, char *action, alpm_list_t *packages);
+action_watched_aur (NotifyNotification *notification, char *action, notif_t *notif);
 
 void
-action_news (NotifyNotification *notification, char *action, gchar *xml_news);
+action_news (NotifyNotification *notification, char *action, notif_t *notif);
 
 void
 notification_closed_cb (NotifyNotification *notification, gpointer data);
 #include "util.h"
 #ifndef DISABLE_GUI
 #include "util-gtk.h"
+#include "gui.h" /* show_notif() */
 #endif
 
 enum {
             FREELIST (config->news_read);
             config->news_read = news_read;
             
+            /* we go and change the last_notifs. if nb_unread = 0 we can
+             * simply remove it, else we change it to ask to run the checks again
+             * to be up to date */
+            for (i = config->last_notifs; i; i = alpm_list_next (i))
+            {
+                notif_t *notif = i->data;
+                if (notif->type & CHECK_NEWS)
+                {
+                    if (nb_unread == 0)
+                    {
+                        config->last_notifs = alpm_list_remove_item (config->last_notifs, i);
+                        free_notif (notif);
+                    }
+                    else
+                    {
+                        free (notif->data);
+                        notif->data = NULL;
+                        free (notif->text);
+                        notif->text = strdup ("Read news have changed, "
+                            "you need to run the checks again to be up-to-date.");
+                    }
+                    break;
+                }
+            }
             set_kalpm_nb (CHECK_NEWS, nb_unread);
             saved = TRUE;
         }
 #include "kalu-updater.h"
 #include "kupdater.h"
 #include "conf.h"
+#include "gui.h" /* show_notif() */
 
 /* split of pctg of each step in the global progress of the sysupgrade */
 #define PCTG_DOWNLOAD           0.42
 static void
 updater_sysupgrade_cb (KaluUpdater *kupdater _UNUSED_, const gchar *errmsg)
 {
+    alpm_list_t *i;
+    
     gtk_widget_set_sensitive (updater->btn_close, TRUE);
     
     if (errmsg != NULL)
     
     /* update nb of upgrades in state (used in kalu's systray icon tooltip) */
     set_kalpm_nb (CHECK_UPGRADES, 0);
+    /* we go and change the last_notifs, to remove the notif about packages */
+    for (i = config->last_notifs; i; i = alpm_list_next (i))
+    {
+        notif_t *notif = i->data;
+        if (notif->type & CHECK_UPGRADES)
+        {
+            config->last_notifs = alpm_list_remove_item (config->last_notifs, i);
+            free_notif (notif);
+            break;
+        }
+    }
     
     if (NULL != updater->cmdline_post)
     {
         GError      *error = NULL;
         size_t       count = alpm_list_count (updater->cmdline_post);
-        alpm_list_t *cmdlines = NULL, *i;
+        alpm_list_t *cmdlines = NULL;
         
         if (count == 1)
         {
 #include "watched.h"
 #include "util.h"
 #include "util-gtk.h"
+#include "gui.h" /* show_notif() */
 
 enum {
     WCOL_UPD,
 static void
 monitor_response_cb (GtkWidget *dialog, gint response, alpm_list_t *updates)
 {
+    alpm_list_t *new_watched = g_object_get_data (G_OBJECT (dialog), "new-watched");
+    
     gtk_widget_destroy (dialog);
-    
     if (response == GTK_RESPONSE_YES)
     {
         GtkTreeModel *model;
         }
     }
     
+    /* free duplicate list */
+    FREELIST (new_watched);
     alpm_list_free (updates);
 }
 
                                   "No, keep the list as is.", NULL,
                                   window_manage);
             g_object_set_data (G_OBJECT (dialog), "is-aur", GINT_TO_POINTER (is_aur));
+            /* send new_watched so it can be free-d it (alongside updates) when
+             * the window gets destroyed */
+            g_object_set_data (G_OBJECT (dialog), "new-watched", (gpointer) new_watched);
             g_signal_connect (G_OBJECT (dialog), "response",
                               G_CALLBACK (monitor_response_cb), (gpointer) updates);
             gtk_widget_show (dialog);
         }
         else
         {
+            /* free duplicate list */
+            FREELIST (new_watched);
             alpm_list_free (updates);
         }
         
         /* done */
-        set_kalpm_nb ((is_aur) ? CHECK_WATCHED_AUR : CHECK_WATCHED, nb_watched);
+        check_t type = (is_aur) ? CHECK_WATCHED_AUR : CHECK_WATCHED;
+        /* we go and change the last_notifs. if nb_watched = 0 we can
+         * simply remove it, else we change it to ask to run the checks again
+         * to be up to date */
+        for (i = config->last_notifs; i; i = alpm_list_next (i))
+        {
+            notif_t *notif = i->data;
+            if (notif->type & type)
+            {
+                if (nb_watched == 0)
+                {
+                    config->last_notifs = alpm_list_remove_item (config->last_notifs, i);
+                    free_notif (notif);
+                }
+                else
+                {
+                    FREE_PACKAGE_LIST (notif->data);
+                    free (notif->text);
+                    notif->text = strdup (
+                        (is_aur)
+                        ? "Watched AUR packages have changed, "
+                            "you need to run the checks again to be up-to-date."
+                        : "Watched packages have changed, "
+                            "you need to run the checks again to be up-to-date."
+                        );
+                }
+                break;
+            }
+        }
+        set_kalpm_nb (type, nb_watched);
         gtk_widget_destroy (window_notif);
     }
     else
     {
         gtk_widget_show (window_notif);
         show_error ("Unable to save changes to disk", NULL, GTK_WINDOW (window_notif));
+        /* free duplicate list */
+        FREELIST (new_watched);
+        alpm_list_free (updates);
     }
-    
-    /* free duplicate list */
-    FREELIST (new_watched);
 }
 
 static void