[svn] GpgEX - r7 - trunk/src
svn author marcus
cvs at cvs.gnupg.org
Thu Aug 30 17:49:10 CEST 2007
Author: marcus
Date: 2007-08-30 17:48:38 +0200 (Thu, 30 Aug 2007)
New Revision: 7
Modified:
trunk/src/ChangeLog
trunk/src/gpgex.cc
trunk/src/gpgex.h
Log:
2007-08-30 Marcus Brinkmann <marcus at g10code.de>
* gpgex.h (ID_CMD_HELP, ID_CMD_VERIFY_DECRYPT)
(ID_CMD_SIGN_ENCRYPT, ID_CMD_IMPORT, ID_CMD_MAX)
(ID_CMD_STR_HELP, ID_CMD_STR_VERIFY_DECRYPT)
(ID_CMD_STR_SIGN_ENCRYPT, ID_CMD_STR_IMPORT): New macros.
(class gpgex_t): New member ALL_FILES_GPG.
* gpgex.cc (gpgex_t::reset): Initialize THIS->all_files_gpg.
(gpgex_t::Initialize): Check ending of added files.
(gpgex_t::QueryContextMenu): Create a more involved dummy menu.
(gpgex_t::InvokeCommand): Show different commands being invoked.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2007-08-30 15:41:44 UTC (rev 6)
+++ trunk/src/ChangeLog 2007-08-30 15:48:38 UTC (rev 7)
@@ -1,5 +1,15 @@
2007-08-30 Marcus Brinkmann <marcus at g10code.de>
+ * gpgex.h (ID_CMD_HELP, ID_CMD_VERIFY_DECRYPT)
+ (ID_CMD_SIGN_ENCRYPT, ID_CMD_IMPORT, ID_CMD_MAX)
+ (ID_CMD_STR_HELP, ID_CMD_STR_VERIFY_DECRYPT)
+ (ID_CMD_STR_SIGN_ENCRYPT, ID_CMD_STR_IMPORT): New macros.
+ (class gpgex_t): New member ALL_FILES_GPG.
+ * gpgex.cc (gpgex_t::reset): Initialize THIS->all_files_gpg.
+ (gpgex_t::Initialize): Check ending of added files.
+ (gpgex_t::QueryContextMenu): Create a more involved dummy menu.
+ (gpgex_t::InvokeCommand): Show different commands being invoked.
+
* gpgex-class.cc (gpgex_class::init): Also register the shell
extension for directories.
(gpgex_class::deinit): Unregister shell extension for directories.
Modified: trunk/src/gpgex.cc
===================================================================
--- trunk/src/gpgex.cc 2007-08-30 15:41:44 UTC (rev 6)
+++ trunk/src/gpgex.cc 2007-08-30 15:48:38 UTC (rev 7)
@@ -41,6 +41,7 @@
gpgex_t::reset (void)
{
this->filenames.clear ();
+ this->all_files_gpg = TRUE;
}
@@ -161,6 +162,23 @@
if (len == 0)
throw std::invalid_argument ("zero-length filename");
+ /* Take a look at the ending. */
+ char *ending = strrchr (filename, '.');
+ if (ending)
+ {
+ BOOL gpg = false;
+
+ ending++;
+ if (! strcasecmp (ending, "gpg")
+ || ! strcasecmp (ending, "pgp")
+ || ! strcasecmp (ending, "asc")
+ || ! strcasecmp (ending, "sig"))
+ gpg = true;
+
+ if (gpg == false)
+ this->all_files_gpg = FALSE;
+ }
+
this->filenames.push_back (filename);
}
}
@@ -206,28 +224,90 @@
gpgex_t::QueryContextMenu (HMENU hMenu, UINT indexMenu, UINT idCmdFirst,
UINT idCmdLast, UINT uFlags)
{
- UINT next_cmd = idCmdFirst;
+ BOOL res;
TRACE_BEG5 (DEBUG_CONTEXT_MENU, "gpgex_t::QueryContextMenu", this,
"hMenu=%p, indexMenu=%u, idCmdFirst=%u, idCmdLast=%u, uFlags=%x",
hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
+ /* FIXME: Do something if idCmdLast - idCmdFirst + 1 is not big
+ enough. */
+
/* If the flags include CMF_DEFAULTONLY then nothing should be done. */
- if (! (uFlags & CMF_DEFAULTONLY))
+ if (uFlags & CMF_DEFAULTONLY)
+ return TRACE_RES (MAKE_HRESULT (SEVERITY_SUCCESS, FACILITY_NULL, 0));
+
+ /* Windows puts a separator after our entries, but not before. */
+ /* FIXME: Check error. */
+ res = InsertMenu (hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);
+ if (! res)
+ return TRACE_RES (HRESULT_FROM_WIN32 (GetLastError ()));
+
+ /* First we add the file-specific menus. */
+ if (this->all_files_gpg)
{
- BOOL res;
-
- res = InsertMenu (hMenu, indexMenu, MF_BYPOSITION,
- next_cmd++, _("GpgEX Test Item"));
+ res = InsertMenu (hMenu, indexMenu++, MF_BYPOSITION | MF_STRING,
+ idCmdFirst + ID_CMD_VERIFY_DECRYPT,
+ ID_CMD_STR_VERIFY_DECRYPT);
if (! res)
return TRACE_RES (HRESULT_FROM_WIN32 (GetLastError ()));
}
+ else
+ {
+ /* FIXME: Check error. */
+ res = InsertMenu (hMenu, indexMenu++, MF_BYPOSITION | MF_STRING,
+ idCmdFirst + ID_CMD_SIGN_ENCRYPT,
+ ID_CMD_STR_SIGN_ENCRYPT);
+ if (! res)
+ return TRACE_RES (HRESULT_FROM_WIN32 (GetLastError ()));
+ }
+ /* Now generate and add the generic command popup menu. */
+ HMENU popup;
+ UINT idx = 0;
+
+ /* FIXME: Check error. */
+ popup = CreatePopupMenu ();
+ if (popup == NULL)
+ return TRACE_RES (HRESULT_FROM_WIN32 (GetLastError ()));
+
+ res = InsertMenu (hMenu, indexMenu++, MF_BYPOSITION | MF_STRING | MF_POPUP,
+ (UINT) popup, _("More GpgEX options"));
+ if (!res)
+ {
+ DWORD last_error = GetLastError ();
+ DestroyMenu (popup);
+ return TRACE_RES (HRESULT_FROM_WIN32 (last_error));
+ }
+
+ res = InsertMenu (popup, idx++, MF_BYPOSITION | MF_STRING,
+ idCmdFirst + ID_CMD_VERIFY_DECRYPT,
+ ID_CMD_STR_VERIFY_DECRYPT);
+ // idx - 1!!!
+ // res = SetMenuItemBitmaps (hPopup, idx - 1, MF_BYPOSITION,
+ // MenuVerifyDecryptBitmap, MenuVerifyDecryptBitmap);
+
+ if (res)
+ res = InsertMenu (popup, idx++, MF_BYPOSITION | MF_STRING,
+ idCmdFirst + ID_CMD_SIGN_ENCRYPT,
+ ID_CMD_STR_SIGN_ENCRYPT);
+ if (res)
+ res = InsertMenu (popup, idx++, MF_BYPOSITION | MF_STRING,
+ idCmdFirst + ID_CMD_IMPORT, ID_CMD_STR_IMPORT);
+ if (res)
+ res = InsertMenu (hMenu, idx++, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
+ if (res)
+ res = InsertMenu (popup, idx++, MF_BYPOSITION | MF_STRING,
+ idCmdFirst + ID_CMD_HELP, ID_CMD_STR_HELP);
+
+ if (! res)
+ return TRACE_RES (HRESULT_FROM_WIN32 (GetLastError ()));
+
/* We should return a HRESULT that indicates success and the offset
to the next free command ID after the last one we used, relative
to idCmdFirst. In other words: max_used - idCmdFirst + 1. */
return TRACE_RES (MAKE_HRESULT (SEVERITY_SUCCESS, FACILITY_NULL,
- next_cmd - idCmdFirst));
+ ID_CMD_MAX + 1));
}
@@ -264,6 +344,8 @@
STDMETHODIMP
gpgex_t::InvokeCommand (LPCMINVOKECOMMANDINFO lpcmi)
{
+ string cmd;
+
TRACE_BEG1 (DEBUG_CONTEXT_MENU, "gpgex_t::GetCommandString", this,
"lpcmi=%p", lpcmi);
@@ -276,23 +358,34 @@
QueryContextMenu, ie zero based). */
switch (LOWORD (lpcmi->lpVerb))
{
- case 0:
- {
- string msg;
- unsigned int i;
-
- msg = "The selected files were:\n\n";
- for (i = 0; i < this->filenames.size (); i++)
- msg = msg + this->filenames[i] + '\n';
-
- MessageBox (lpcmi->hwnd, msg.c_str (), "GpgEX", MB_ICONINFORMATION);
- }
+ case ID_CMD_HELP:
+ cmd = "HELP";
break;
-
+ case ID_CMD_VERIFY_DECRYPT:
+ cmd = "VERIFY_DECRYPT";
+ break;
+ case ID_CMD_SIGN_ENCRYPT:
+ cmd = "SIGN_ENCRYPT";
+ break;
+ case ID_CMD_IMPORT:
+ cmd = "IMPORT";
+ break;
default:
return TRACE_RES (E_INVALIDARG);
+ break;
}
+ /* FIXME: Need to send commands to Kleopatra. */
+
+ string msg;
+ unsigned int i;
+
+ msg = "Invoked " + cmd + "on files:\n\n";
+ for (i = 0; i < this->filenames.size (); i++)
+ msg = msg + this->filenames[i] + '\n';
+
+ MessageBox (lpcmi->hwnd, msg.c_str (), "GpgEX", MB_ICONINFORMATION);
+
return TRACE_RES (S_OK);
}
Modified: trunk/src/gpgex.h
===================================================================
--- trunk/src/gpgex.h 2007-08-30 15:41:44 UTC (rev 6)
+++ trunk/src/gpgex.h 2007-08-30 15:48:38 UTC (rev 7)
@@ -30,6 +30,19 @@
#include <windows.h>
#include <shlobj.h>
+/* For context menus. */
+#define ID_CMD_HELP 0
+#define ID_CMD_VERIFY_DECRYPT 1
+#define ID_CMD_SIGN_ENCRYPT 2
+#define ID_CMD_IMPORT 3
+#define ID_CMD_MAX 3
+
+#define ID_CMD_STR_HELP _("Help on GpgEX")
+#define ID_CMD_STR_VERIFY_DECRYPT _("Decrypt and verify")
+#define ID_CMD_STR_SIGN_ENCRYPT _("Sign and encrypt")
+#define ID_CMD_STR_IMPORT _("Import keys")
+
+
/* Our shell extension interface. We use multiple inheritance to
achieve polymorphy.
@@ -83,6 +96,9 @@
/* Support for IShellExtInit. */
vector<string> filenames;
+ /* TRUE if all files in filenames are directly related to GPG. */
+ BOOL all_files_gpg;
+
/* Support for the context menu. */
public:
More information about the Gnupg-commits
mailing list