Merge lp:~ds3/ubuntu/oneiric/synaptic/fix-for-63974 into lp:ubuntu/oneiric/synaptic

Proposed by Douglas Schneider
Status: Needs review
Proposed branch: lp:~ds3/ubuntu/oneiric/synaptic/fix-for-63974
Merge into: lp:ubuntu/oneiric/synaptic
Diff against target: 71 lines (+26/-4) (has conflicts)
2 files modified
debian/changelog (+10/-0)
gtk/rgmainwindow.cc (+16/-4)
Text conflict in debian/changelog
To merge this branch: bzr merge lp:~ds3/ubuntu/oneiric/synaptic/fix-for-63974
Reviewer Review Type Date Requested Status
Colin Watson Needs Fixing
Review via email: mp+74038@code.launchpad.net

Description of the change

gtk/rgmainwindow.cc was modified to make it so that when a user tries to delete a package that is (likely) essential to the os - bash for example - the warning is now given with the offending packages name. This makes it easy for a user to know which packages they should not be deleting if they try to delete many packages at the same time and some are essential.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Thanks for your patch.

This will break translations. You can't assemble strings at run-time like this and have the result be translatable (because different languages will need to assemble the string in different orders); what you need to do instead is translate a format string and then substitute the package name into that. Awkwardly, RUserDialog::confirm only takes a single string rather than a format string plus arguments, and that looks like a pain to change, but you can just substitute it manually.

Annoyingly, vanilla C++ lacks a way to deal with format strings, aside from the C sprintf/snprintf functions which require deciding on a maximum size for the translated string (even if you dodge buffer overflow issues). I would suggest '#define _GNU_SOURCE 1' at the top of the file and then you can use asprintf. The result would then look something like this (untested):

  char *warning_fmt = _("Removing the %s package may render the "
                        "system usable.\n"
                        "Are you sure you want to do that?")
  char *warning;

  if (asprintf(&warning, warning_fmt, pkg->name()) < 0) {
     perror("asprintf");
     return;
  }
  bool confirmed = _userDialog->confirm(warning, false);
  free(warning);
  if (!confirmed)
     return;

(Not very C++ish, but hopefully Michael will have a look at this at some point and see if he can suggest anything neater!)

review: Needs Fixing
115. By Douglas Schneider

Updated the warning for deleting a required package to use memory allocation.
(LP: #63974)

Revision history for this message
Douglas Schneider (ds3) wrote :

The translations need to be updated for the new warning message on line 1887 of gtk/rgmainwindow.cc.

Unmerged revisions

115. By Douglas Schneider

Updated the warning for deleting a required package to use memory allocation.
(LP: #63974)

114. By Douglas Schneider

updated the change log

113. By Douglas Schneider

changed the warning message for deleting an important package to supply the packages name

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-10-05 21:37:39 +0000
3+++ debian/changelog 2011-12-22 18:18:25 +0000
4@@ -1,3 +1,4 @@
5+<<<<<<< TREE
6 synaptic (0.75.2ubuntu8) oneiric; urgency=low
7
8 * debian/source_synaptic.py: add in an apport package hook (LP: #863792)
9@@ -18,6 +19,15 @@
10
11 -- Michael Terry <mterry@ubuntu.com> Mon, 26 Sep 2011 12:13:46 -0400
12
13+=======
14+synaptic (0.75.2ubuntu7) oneiric; urgency=low
15+
16+ * Changed the warning message when about to delete an important package
17+ to give the name of the offending package. (LP: #63974)
18+
19+ -- Doug Schneider <ds3@ualberta.ca> Sun, 04 Sep 2011 21:08:18 -0600
20+
21+>>>>>>> MERGE-SOURCE
22 synaptic (0.75.2ubuntu6) oneiric; urgency=low
23
24 * Fix missing policy file (again!) (LP: #828315)
25
26=== modified file 'gtk/rgmainwindow.cc'
27--- gtk/rgmainwindow.cc 2011-03-04 12:29:46 +0000
28+++ gtk/rgmainwindow.cc 2011-12-22 18:18:25 +0000
29@@ -37,6 +37,7 @@
30 #include <fstream>
31 #include <sstream>
32 #include <time.h>
33+#include <string.h>
34
35 #include <sys/types.h>
36 #include <sys/stat.h>
37@@ -85,6 +86,9 @@
38 // include it here because depcache.h hates us if we have it before
39 #include <gdk/gdkx.h>
40
41+// define this to get access to asprintf
42+#define _GNU_SOURCE 1
43+
44
45 enum { WHAT_IT_DEPENDS_ON,
46 WHAT_DEPENDS_ON_IT,
47@@ -1880,12 +1884,20 @@
48 void RGMainWindow::pkgRemoveHelper(RPackage *pkg, bool purge, bool withDeps)
49 {
50 if (pkg->getFlags() & RPackage::FImportant) {
51- if (!_userDialog->confirm(_("Removing this package may render the "
52- "system unusable.\n"
53- "Are you sure you want to do that?"),
54- false)) {
55+ char *warning_fmt = _( "Removing the %s package may render the "
56+ "system unusable.\n"
57+ "Are you sure you want to do that?");
58+
59+ char *warning;
60+ if(asprintf(&warning, warning_fmt, pkg->name()) < 0) {
61+ perror("asprintf");
62 return;
63 }
64+
65+ bool confirmed = _userDialog->confirm(warning, false);
66+ free(warning);
67+ if (!confirmed)
68+ return;
69 }
70 if (!withDeps)
71 pkg->setRemove(purge);

Subscribers

People subscribed via source and target branches