|
Packit |
79f644 |
/*
|
|
Packit |
79f644 |
* Copyright © 2016 – 2017 Red Hat, Inc.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
79f644 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
79f644 |
* License as published by the Free Software Foundation; either
|
|
Packit |
79f644 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
79f644 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
79f644 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
79f644 |
* Lesser General Public License for more details.
|
|
Packit |
79f644 |
*
|
|
Packit |
79f644 |
* You should have received a copy of the GNU Lesser General
|
|
Packit |
79f644 |
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
79f644 |
*/
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include <locale.h>
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#include <glib.h>
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
#define GOA_API_IS_SUBJECT_TO_CHANGE
|
|
Packit |
79f644 |
#define GOA_BACKEND_API_IS_SUBJECT_TO_CHANGE
|
|
Packit |
79f644 |
#include <goabackend/goabackend.h>
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static struct
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GoaProviderFeatures feature;
|
|
Packit |
79f644 |
const gchar *key;
|
|
Packit |
79f644 |
} provider_features_info[] = {
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_MAIL,
|
|
Packit |
79f644 |
.key = "MailEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_CALENDAR,
|
|
Packit |
79f644 |
.key = "CalendarEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_CONTACTS,
|
|
Packit |
79f644 |
.key = "ContactsEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_CHAT,
|
|
Packit |
79f644 |
.key = "ChatEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_DOCUMENTS,
|
|
Packit |
79f644 |
.key = "DocumentsEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_MUSIC,
|
|
Packit |
79f644 |
.key = "MusicEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_PHOTOS,
|
|
Packit |
79f644 |
.key = "PhotosEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_FILES,
|
|
Packit |
79f644 |
.key = "FilesEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_TICKETING,
|
|
Packit |
79f644 |
.key = "TicketingEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_TODO,
|
|
Packit |
79f644 |
.key = "TodoEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_READ_LATER,
|
|
Packit |
79f644 |
.key = "ReadLaterEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_PRINTERS,
|
|
Packit |
79f644 |
.key = "PrintersEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_MAPS,
|
|
Packit |
79f644 |
.key = "MapsEnabled"
|
|
Packit |
79f644 |
},
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
.feature = GOA_PROVIDER_FEATURE_INVALID,
|
|
Packit |
79f644 |
.key = NULL
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
};
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
static void
|
|
Packit |
79f644 |
get_all (GObject *source_object, GAsyncResult *res, gpointer user_data)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GError *error;
|
|
Packit |
79f644 |
GList *providers = NULL;
|
|
Packit |
79f644 |
GList *l;
|
|
Packit |
79f644 |
GMainLoop *loop = (GMainLoop *) user_data;
|
|
Packit |
79f644 |
GKeyFile *key_file = NULL;
|
|
Packit |
79f644 |
gchar *key_file_data = NULL;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
error = NULL;
|
|
Packit |
79f644 |
if (!goa_provider_get_all_finish (&providers, res, &error))
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_warning ("Unable to get list of providers: %s", error->message);
|
|
Packit |
79f644 |
g_error_free (error);
|
|
Packit |
79f644 |
goto out;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
key_file = g_key_file_new ();
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
for (l = providers; l != NULL; l=l->next)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GoaProvider *provider = GOA_PROVIDER (l->data);
|
|
Packit |
79f644 |
GoaProviderFeatures features;
|
|
Packit |
79f644 |
const gchar *type;
|
|
Packit |
79f644 |
gchar *group;
|
|
Packit |
79f644 |
gchar *name;
|
|
Packit |
79f644 |
guint i;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
features = goa_provider_get_provider_features (provider);
|
|
Packit |
79f644 |
if (features == GOA_PROVIDER_FEATURE_INVALID)
|
|
Packit |
79f644 |
continue;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
type = goa_provider_get_provider_type (provider);
|
|
Packit |
79f644 |
group = g_strconcat ("Provider ", type, NULL);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
name = goa_provider_get_provider_name (provider, NULL);
|
|
Packit |
79f644 |
g_key_file_set_string (key_file, group, "ProviderName", name);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
for (i = 0; provider_features_info[i].key != NULL; i++)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
if ((features & provider_features_info[i].feature) != 0)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
const gchar *key = provider_features_info[i].key;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* The IMAP/SMTP provider uses Enabled instead of
|
|
Packit |
79f644 |
* MailEnabled. We should probably fix it for consistency.
|
|
Packit |
79f644 |
*/
|
|
Packit |
79f644 |
if (g_strcmp0 (type, "imap_smtp") == 0 && g_strcmp0 (key, "MailEnabled") == 0)
|
|
Packit |
79f644 |
key = "Enabled";
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_key_file_set_boolean (key_file, group, key, TRUE);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_free (group);
|
|
Packit |
79f644 |
g_free (name);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
error = NULL;
|
|
Packit |
79f644 |
key_file_data = g_key_file_to_data (key_file, NULL, &error);
|
|
Packit |
79f644 |
if (error != NULL)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
g_warning ("Unable to serialize key file: %s", error->message);
|
|
Packit |
79f644 |
g_error_free (error);
|
|
Packit |
79f644 |
goto out;
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_print ("%s", key_file_data);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
out:
|
|
Packit |
79f644 |
g_clear_pointer (&key_file, (GDestroyNotify) g_key_file_unref);
|
|
Packit |
79f644 |
g_free (key_file_data);
|
|
Packit |
79f644 |
g_list_free_full (providers, g_object_unref);
|
|
Packit |
79f644 |
g_main_loop_quit (loop);
|
|
Packit |
79f644 |
}
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
gint
|
|
Packit |
79f644 |
main (void)
|
|
Packit |
79f644 |
{
|
|
Packit |
79f644 |
GMainLoop *loop;
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
setlocale (LC_ALL, "");
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
/* Workaround https://bugzilla.gnome.org/show_bug.cgi?id=674885. */
|
|
Packit |
79f644 |
g_type_ensure (G_TYPE_DBUS_CONNECTION);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
loop = g_main_loop_new (NULL, FALSE);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
goa_provider_get_all (get_all, loop);
|
|
Packit |
79f644 |
g_main_loop_run (loop);
|
|
Packit |
79f644 |
|
|
Packit |
79f644 |
g_main_loop_unref (loop);
|
|
Packit |
79f644 |
return 0;
|
|
Packit |
79f644 |
}
|