Re: Missing API and API that needs improvements



On Wed, 2006-08-23 at 22:40 +0200, Philip Van Hoof wrote:

Because not a lot people would otherwise study the proposals, I'll give
code examples of how they would look here:

> http://tinymail.org/trac/tinymail/wiki/HelpImplementingMissingAPI

TnyListIface *headers = tny_list_new ();
foreach selected header
  tny_list_iface_prepend (headers, header)
tny_folder_iface_transfer_messages (source_folder, 
	destination_folder, headers, TRUE);
g_object_unref (G_OBJECT (headers));
tny_folder_iface_expunge (source_folder);

>  http://tinymail.org/trac/tinymail/wiki/HelpRedesignGettingFolders

static void
recurse_folders (TnyFolderStoreIface *folder, query)
{
   TnyIteratorIface *iter;
   TnyListIface *folders = tny_list_iface ();

   tny_folder_store_iface_get_folders (account, folders, query);
   iter = tny_list_iface_create_iterator (folders);

   while (!tny_iterator_iface_is_done (iter))
   {
       TnyFolderStoreIface *folder = tny_iterator_iface_current (iter);
       g_print ("%s\n", tny_folder_iface_get_name (TNY_FOLDER_IFACE (folder)));
       recurse_folders (folder, query);
       g_object_unref (G_OBJECT (folder));
   }

   g_object_unref (G_OBJECT (iter));
   g_object_unref (G_OBJECT (folders));
}

int main ()
{
  g_type_init ();

  TnyPlatformFactoryIface *platfact = tny_platform_factory_get_instance ();
  TnyAccountStoreIface *account_store = tny_platform_factory_new_account_store (platfact);
  TnyListIface *accounts = tny_list_new (); TnyFolderStoryQuery *query;
  TnyStoreAccountIface *account; TnyIteratorIface *iter;
  TnyFolderStoreQueryOption options = TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED;

  options |= TNY_FOLDER_STORE_QUERY_OPTION_UNSUBSCRIBED;
  query = tny_folder_store_query_new (NULL, options);

  tny_account_store_get_accounts (account_store, accounts, 
	TNY_ACCOUNT_STORE_IFACE_STORE_ACCOUNTS);
  iter = tny_list_iface_create_iterator (accounts);
  account = tny_iterator_iface_current (iter);

  recurse_folders (account, query);

  g_object_unref (G_OBJECT (account));
  g_object_unref (G_OBJECT (iter));
  g_object_unref (G_OBJECT (accounts));
}


The idea is to use regular expressions in the tny_folder_store_query_new
method. For example if the user wants all the folders that begin with
the letter T:

TnyFolderStoryQuery *query = tny_folder_store_query_new ("^T.*$", options);

Another idea:

TnyFolderStoryQuery *query = tny_folder_store_query_new ();

options |= TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED;
options |= TNY_FOLDER_STORE_QUERY_OPTION_REGEX_ON_NAME;
tny_folder_store_query_add (query, "^T.*$", options);
options |= TNY_FOLDER_STORE_QUERY_OPTION_REGEX_ON_SUBJECT_HEADERS;
tny_folder_store_query_add (query, "^Re:.*$", options);

This would be a query for all folders that begin with T and have
subjects that start with "Re:". But that last might be total overkill
(I'm not sure about it yet).


-- 
Philip Van Hoof, software developer at x-tend 
home: me at pvanhoof dot be 
gnome: pvanhoof at gnome dot org 
work: vanhoof at x-tend dot be 
http://www.pvanhoof.be - http://www.x-tend.be




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]