[svn] pinentry - r239 - in trunk: . qt

svn author wk cvs at cvs.gnupg.org
Tue Oct 12 17:58:20 CEST 2010


Author: wk
Date: 2010-10-12 17:58:19 +0200 (Tue, 12 Oct 2010)
New Revision: 239

Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/autogen.sh
   trunk/qt/main.cpp
Log:
Add default-cacnel and default-ok to pinentry-qt(3)


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-09-30 15:17:08 UTC (rev 238)
+++ trunk/ChangeLog	2010-10-12 15:58:19 UTC (rev 239)
@@ -1,3 +1,9 @@
+2010-10-12  Werner Koch  <wk at g10code.com>
+
+	* qt/main.cpp (escape_accel): New.  Adapt from from qt4/.
+	(qt_cmd_handler): Implement default-ok and default-cancel.  Escape
+	accelerators.
+
 2010-09-30  Werner Koch  <wk at g10code.com>
 
 	* pinentry/pinentry.h (struct pinentry): Add CLOSE_BUTTON.

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2010-09-30 15:17:08 UTC (rev 238)
+++ trunk/NEWS	2010-10-12 15:58:19 UTC (rev 239)
@@ -7,8 +7,9 @@
    the keyboard.
 
  * The protocol options default-cancel and default-ok now work for the
-   pinnetry-gtk2.
+   pinentry-gtk2 and pinentry-qt (that is QT3).
 
+
 Noteworthy changes in version 0.8.0 (2010-03-03)
 ------------------------------------------------
 

Modified: trunk/autogen.sh
===================================================================
--- trunk/autogen.sh	2010-09-30 15:17:08 UTC (rev 238)
+++ trunk/autogen.sh	2010-10-12 15:58:19 UTC (rev 239)
@@ -140,7 +140,7 @@
         fi
     fi
 
-    ./configure --enable-maintainer-mode --prefix=${w32root} \
+    $tsdir/configure --enable-maintainer-mode --prefix=${w32root} \
                 --host=${host} --build=${build} \
                 --disable-pinentry-gtk \
                 --disable-pinentry-qt  \

Modified: trunk/qt/main.cpp
===================================================================
--- trunk/qt/main.cpp	2010-09-30 15:17:08 UTC (rev 238)
+++ trunk/qt/main.cpp	2010-10-12 15:58:19 UTC (rev 239)
@@ -39,6 +39,45 @@
 #include <pinentry-curses.h>
 #endif
 
+static QString escape_accel( const QString & s ) {
+
+  QString result;
+  result.reserve( 2 * s.length());
+
+  bool afterUnderscore = false;
+
+  for ( unsigned int i = 0, end = s.length() ; i != end ; ++i ) {
+    const QChar ch = s[i];
+    if ( ch == QChar ( '_' ) )
+      {
+        if ( afterUnderscore ) // escaped _
+          {
+            result += QChar ( '_' );
+            afterUnderscore = false;
+          }
+        else // accel
+          {
+            afterUnderscore = true;
+          }
+      }
+    else
+      {
+        if ( afterUnderscore || // accel
+             ch == QChar ( '&' ) ) // escape & from being interpreted by Qt
+          result += QChar ( '&' );
+        result += ch;
+        afterUnderscore = false;
+      }
+  }
+
+  if ( afterUnderscore )
+    // trailing single underscore: shouldn't happen, but deal with it robustly:
+    result += QChar ( '_' );
+
+  return result;
+}
+
+
 /* Hack for creating a QWidget with a "foreign" window ID */
 class ForeignWidget : public QWidget
 {
@@ -79,9 +118,16 @@
 #endif
 
       if (pe->ok)
-	pinentry.setOkText (QString::fromUtf8 (pe->ok));
+	pinentry.setOkText (escape_accel (QString::fromUtf8 (pe->ok)));
+      else if (pe->default_ok)
+	pinentry.setOkText (escape_accel (QString::fromUtf8 (pe->default_ok)));
+
       if (pe->cancel)
-	pinentry.setCancelText (QString::fromUtf8 (pe->cancel));
+	pinentry.setCancelText (escape_accel (QString::fromUtf8 (pe->cancel)));
+      else if (pe->default_cancel)
+	pinentry.setCancelText
+          (escape_accel (QString::fromUtf8 (pe->default_cancel)));
+
       if (pe->error)
 	pinentry.setError (QString::fromUtf8 (pe->error));
       if (pe->quality_bar)
@@ -113,9 +159,13 @@
     }
   else
     {
-      QString desc = QString::fromUtf8 (pe->description? pe->description :"");
-      QString ok   = QString::fromUtf8 (pe->ok ? pe->ok : "OK");
-      QString can  = QString::fromUtf8 (pe->cancel ? pe->cancel : "Cancel");
+      QString desc = QString::fromUtf8 (pe->description? pe->description : "");
+      QString ok   = escape_accel
+        (QString::fromUtf8 (pe->ok ? pe->ok :
+                            pe->default_ok ? pe->default_ok : "&OK"));
+      QString can  = escape_accel
+        (QString::fromUtf8 (pe->cancel ? pe->cancel :
+                            pe->default_cancel? pe->default_cancel: "&Cancel"));
       bool ret;
       
       ret = QMessageBox::information (parent, "", desc, ok, can );
@@ -160,7 +210,7 @@
       for (done=0,p=*new_argv,i=0; i < argc; i++)
         if (!done && !strcmp (argv[i], "--display"))
           {
-            new_argv[i] = "-display";
+            new_argv[i] = (char*)"-display";
             done = 1;
           }
         else





More information about the Gnupg-commits mailing list