Re: non-commit: abiword-plugins: rewrite url plug-ins

From: Kenneth J. Davis <PerditionC_at_attglobal.net>
Date: Sun Nov 28 2004 - 03:58:17 CET

Francis James Franklin wrote:

> A mixture of extensions, clean-up & fixes. I'd like to commit, but it's
> all so horribly confusing at the moment!
>
> AbiURLDict: Add Webster, Cambridge and, er, Oxford (okay, yes, I know,
> but it works for me, and I'm want to add some configuration mechanism
> for this kind of thing anyway)
>
> AbiGoogle: Add Yahoo
>
> AbiWikipedia: currently looks up English wiki, but could be worth making
> this language-sensitive.
>
> Sulking,
> Frank

Would it not be better to read the URL (and menu name) from the profile
via the plugin profile read/write APIs? This way a single URL plugin
could provide the functionality of all three of these plugins, and since
the URLs would not be hard coded, could easily be changed in the future
when/if the URL changes or someones needs it to be different to redirect
to an intranet site/proxy. For gets this is almost trivial, the only
catch is how to mark the portion of the URL that gets replaced with the
selected word. If post support is added, then this could be easily
expanded to indicate such.

Something akin to the following:

a function with a prototype like
void addToList(char * menuName, char * url);
except maybe adjusted to support UTF8 instead
of ASCII, that stores in some structure a list
of menuNames and url associated with them.

In the init/registration code:
...
XAP_PrefsScheme * prefsScheme =
prefs->getPluginScheme(szAbiPluginSchemeName);
if (prefsScheme == NULL)
{
   // manually initialize to default URLs or fail to load
   ...
}
...
bool loop=true;
do {
   UTString key;
   UTString menuName,url;
   loop = false;

   key = "menuName" + count; // eg menuName0="Google" or whatever...
   if (prefsScheme->getValue(key,menuName))
   {
     // ensure menu name not too huge and/or other validation
     if (MenuName.size() > 33)
     {
       MenuName = MenuName.substr(0, 31);
       MenuName += ".. "; // the space is on purpose
     }

     key = "url" + count; // eg url0="http://www.search.tld/?search="
     if (prefsScheme->getValue(key, url))
     {
       addToList(menuName.c_str(), url.c_str());
       loop = true; // try for another one
     }
   }
} while (loop);
...
then for each pair of menu names/urls added we
create the corresponding menu items, where the
EV_EditMethod is passed the index/key to obtain
the url, and the callback uses this instead
of a hard coded string. [I have not actually
passed extra data to a callback, but in theory
it supports it I think.]

For now the plugin can simply create the default
(same as current) URLs when the preference is not
found, and in the future offer a GUI based method
to add/edit/remove entries (in the meantime advanced
users can edit the profile).

just an idea,
Jeremy
Received on Sun Nov 28 03:59:00 2004

This archive was generated by hypermail 2.1.8 : Sun Nov 28 2004 - 03:59:00 CET