#! /bin/sh /usr/share/dpatch/dpatch-run
## 10_foo.dpatch
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@
diff -urNad ubuntu~/common/rpackagestatus.cc ubuntu/common/rpackagestatus.cc
--- ubuntu~/common/rpackagestatus.cc	2010-02-24 12:30:23.000000000 +0100
+++ ubuntu/common/rpackagestatus.cc	2010-02-24 12:30:23.000000000 +0100
@@ -185,7 +185,8 @@
    pkgTagSection sec;
    time_t release_date = -1;
 
-   string distro = _config->Find("Synaptic::supported-label");
+   // FIXME: make this use the "labels" vector in the future
+   string distro = _config->Find("Synaptic::supported-label","Ubuntu");
    string releaseFile = pkg->getReleaseFileForOrigin(distro, release);
    if(!FileExists(releaseFile)) {
       // happens e.g. when there is no release file and is harmless
@@ -209,10 +210,26 @@
    // now calculate the time until there is support
    gmtime_r(&release_date, res);
    
-   const int support_time =_config->FindI("Synaptic::supported-month", 0);
+   int support_time =_config->FindI("Synaptic::supported-month", 18);
    if (support_time <= 0)
       return false;
 
+   // check if the package overwrites the support time, this has the
+   // format "5y", "18m" etc
+   string support_time_str = pkg->findTagFromPkgRecord("Supported");
+   size_t len = support_time_str.length();
+   if(len > 1) {
+      int factor = 1;
+      if (support_time_str[len-1] == 'y')
+	 factor = 12;
+      else if (support_time_str[len-1] == 'm')
+	 factor = 1;
+      else 
+	 cerr << "Unknown support tag: " << support_time_str  << endl;
+      // and covert to an integer (skipping the last char 'y')
+      support_time = factor * atoi(support_time_str.substr(0, len-1).c_str());
+   }
+
    res->tm_year += (support_time / 12) + ((res->tm_mon + support_time % 12) / 12);
    res->tm_mon = (res->tm_mon + support_time) % 12;
 
diff -urNad ubuntu~/gtk/gtkbuilder/window_main.ui ubuntu/gtk/gtkbuilder/window_main.ui
--- ubuntu~/gtk/gtkbuilder/window_main.ui	2010-02-24 12:30:23.000000000 +0100
+++ ubuntu/gtk/gtkbuilder/window_main.ui	2010-02-24 12:30:23.000000000 +0100
@@ -1351,8 +1351,8 @@
 			      <property name="pixels_above_lines">3</property>
 			      <property name="pixels_below_lines">3</property>
 			      <property name="pixels_inside_wrap">0</property>
-			      <property name="left_margin">3</property>
-			      <property name="right_margin">3</property>
+			      <property name="left_margin">12</property>
+			      <property name="right_margin">12</property>
 			      <property name="indent">0</property>
 			      <property name="text" translatable="yes"></property>
 			    </widget>
diff -urNad ubuntu~/gtk/rgpkgdetails.cc ubuntu/gtk/rgpkgdetails.cc
--- ubuntu~/gtk/rgpkgdetails.cc	2010-02-24 12:26:40.000000000 +0100
+++ ubuntu/gtk/rgpkgdetails.cc	2010-02-24 12:31:01.000000000 +0100
@@ -24,6 +24,8 @@
 #include "config.h"
 
 #include <cassert>
+#include <langinfo.h>
+
 #include "rgwindow.h"
 #include "rgmainwindow.h"
 #include "rgpkgdetails.h"
@@ -191,33 +193,17 @@
 				 "scale", 1.1, 
 				 NULL);
    }
+   if(gtk_text_tag_table_lookup(tag_table, "gray") == NULL) {
+      gtk_text_buffer_create_tag(buf, "gray", 
+				 "foreground", "darkgray", 
+				 NULL);
+   }
    // set summary
    s = utf8(pkg->summary());
    gtk_text_buffer_get_start_iter(buf, &it);
    gtk_text_buffer_insert(buf, &it, s, -1);
    gtk_text_buffer_get_start_iter(buf, &start);
    gtk_text_buffer_apply_tag_by_name(buf, "bold", &start, &it);
-   // set emblems 
-   GdkPixbuf *pixbuf = RGPackageStatus::pkgStatus.getSupportedPix(pkg);
-   if(pixbuf != NULL) {
-      // insert space
-      gtk_text_buffer_insert(buf, &it, " ", 1);
-      // make image
-      emblem = gtk_image_new_from_pixbuf(pixbuf);
-      gtk_image_set_pixel_size(GTK_IMAGE(emblem), 16);
-      // set eventbox and tooltip
-      GtkWidget *event = gtk_event_box_new();
-      GtkStyle *style = gtk_widget_get_style(textview);
-      gtk_widget_modify_bg(event, GTK_STATE_NORMAL, 
-			   &style->base[GTK_STATE_NORMAL]);
-      gtk_container_add(GTK_CONTAINER(event), emblem);
-      gtk_tooltips_set_tip(tips, event, _("This application is supported by the distribution"), "");
-      // create anchor
-      GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(buf, &it);
-      gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(textview), event, anchor);
-      gtk_widget_show_all(event);
-   }
-
    // add button to get screenshot
    gtk_text_buffer_insert(buf, &it, "\n", 1);
    GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(buf, &it);
@@ -237,6 +223,58 @@
    s = utf8(pkg->description());
    gtk_text_buffer_insert(buf, &it, s, -1);
    
+   // now check if we have a support time
+   gchar *maint_str = NULL;
+   struct tm end_time;
+   if(pkg->label() == "Ubuntu" && pkg->origin() == "Ubuntu") {
+      gchar *old_lctime = g_strdup(setlocale(LC_TIME, NULL));
+      gchar *new_lctime = g_strdup(setlocale(LC_MESSAGES, NULL));
+      if(RGPackageStatus::pkgStatus.maintenanceEndTime(pkg, &end_time)) {
+         setlocale(LC_TIME, new_lctime);
+ 	 if (pkg->component() == "main")
+ 	    maint_str = g_strdup_printf(_("\n\n"
+ 	    "Canonical provides critical updates for %s "
+ 	    "until %s %i."), 
+ 	    pkg->name(), 
+ 	    nl_langinfo(MON_1+end_time.tm_mon), 
+ 	    end_time.tm_year + 1900);
+ 	 else if (pkg->component() == "restricted")
+ 	    maint_str = g_strdup_printf(_("\n\n"
+ 	    "Canonical provides critical updates "
+ 	    "supplied by the developers of %s "
+ 	    "until %s %i."),
+ 	    pkg->name(), 
+ 	    nl_langinfo(MON_1+end_time.tm_mon), 
+ 	    end_time.tm_year + 1900);
+      } else {
+ 	 if (pkg->component() == "main")
+ 	    maint_str = g_strdup_printf(_("\n\n"
+ 	    "Canonical provides critical updates for %s."),
+ 	    pkg->name());
+ 	 else if (pkg->component() == "restricted")
+ 	    maint_str = g_strdup_printf(_("\n\n"
+ 	    "Canonical provides critical updates "
+ 	    "supplied by the developers of %s."),
+ 	    pkg->name());
+ 	 else if (pkg->component() == "universe" ||
+ 	 pkg->component() == "multiverse") 
+ 	    maint_str = g_strdup_printf(_("\n\n"
+ 	    "Canonical does not provide "
+ 	    "updates for %s. "
+ 	    "Some updates may be provided "
+ 	    "by the Ubuntu community."),
+ 	    pkg->name());
+      }
+      // Restore old locale settings
+      setlocale(LC_TIME, old_lctime);
+      g_free(old_lctime);
+      g_free(new_lctime);
+   }
+   if(maint_str)
+      gtk_text_buffer_insert_with_tags_by_name(buf, 
+      &it, maint_str, -1, 
+      "gray", NULL);
+   g_free(maint_str);
 
    // build dependency lists
    vector<DepInformation> deps;
diff -urNad ubuntu~/tests/test_rpackage.cc ubuntu/tests/test_rpackage.cc
--- ubuntu~/tests/test_rpackage.cc	2010-02-24 12:26:40.000000000 +0100
+++ ubuntu/tests/test_rpackage.cc	2010-02-24 12:30:23.000000000 +0100
@@ -17,6 +17,7 @@
    RPackage *pkg = lister->getPackage("eog");
    cerr << "pkg: " << pkg->name() << endl;
    cerr << "Bugs: " << pkg->findTagFromPkgRecord("Bugs") << endl;
+   cerr << "Supported: " << pkg->findTagFromPkgRecord("Supported") << endl;
 
    vector<DepInformation> deps = pkg->enumDeps();
    for(unsigned int i=0;i<deps.size();i++) {
@@ -37,4 +38,10 @@
       s = all[i]->getRawRecord();
    }
    cerr << "iterating each record: " << float(clock()-now)/CLOCKS_PER_SEC << endl;
+   // read supported info
+   cerr << "Checking for supported info:" << endl;
+   for(int i=0;i<all.size();i++) {
+      if(all[i]->findTagFromPkgRecord("Supported").empty() == false)
+	 cerr << "pkg: " << all[i]->name() << " has support info" << endl;
+   }
 }
