static void
channel_favourited_cb(GObject* source,
                      GParamSpec* pspec,
                      gpointer udata)
{
    GtFavouritesManager* self = GT_FAVOURITES_MANAGER(udata);
    GtFavouritesManagerPrivate* priv = gt_favourites_manager_get_instance_private(self);
    GtChannel* chan = GT_CHANNEL(source);

    gboolean favourited;

    g_object_get(chan, "favourited", &favourited, NULL);

    if (favourited)
    {
        self->favourite_channels = g_list_append(self->favourite_channels, chan);
//        g_signal_connect(chan, "notify::online", G_CALLBACK(channel_online_cb), self);
        g_object_ref(chan);

        if (gt_app_credentials_valid(main_app))
            gt_twitch_follow_channel(main_app->twitch, gt_channel_get_name(chan)); //TODO: Error handling
//            gt_twitch_follow_channel_async(main_app->twitch, gt_channel_get_name(chan), NULL, NULL); //TODO: Error handling

        g_message("{GtChannel} Favourited '%s' (%p)", gt_channel_get_name(chan), chan);

        g_signal_emit(self, sigs[SIG_CHANNEL_FAVOURITED], 0, chan);
    }
    else
    {
        GList* found = g_list_find_custom(self->favourite_channels, chan, (GCompareFunc) gt_channel_compare);
        // Should never return null;

        g_assert_nonnull(found);

//        g_signal_handlers_disconnect_by_func(found->data, channel_online_cb, self);

        if (gt_app_credentials_valid(main_app))
            gt_twitch_unfollow_channel_async(main_app->twitch, gt_channel_get_name(chan), NULL, NULL); //TODO: Error handling
//            gt_twitch_unfollow_channel(main_app->twitch, gt_channel_get_name(chan)); //TODO: Error handling

        g_message("{GtChannel} Unfavourited '%s' (%p)", gt_channel_get_name(chan), chan);

        g_signal_emit(self, sigs[SIG_CHANNEL_UNFAVOURITED], 0, found->data);

        g_clear_object(&found->data);
        self->favourite_channels = g_list_delete_link(self->favourite_channels, found);
    }
}
static void
move_local_favourites_cb(GtkInfoBar* bar,
                         gint res,
                         gpointer udata)
{
    GtFavouritesManager* self = GT_FAVOURITES_MANAGER(udata);
    gchar* fp = FAV_CHANNELS_FILE;
    gchar* new_fp = g_strconcat(fp, ".bak", NULL);

    if (res == GTK_RESPONSE_YES)
    {
        JsonParser* parse = json_parser_new();
        JsonNode* root;
        JsonArray* jarr;
        gchar* fp = FAV_CHANNELS_FILE;
        GError* err = NULL;

        gt_channel_free_list(self->favourite_channels);
        self->favourite_channels = NULL;
        g_signal_emit(self, sigs[SIG_FINISHED_LOADING_FAVOURITES], 0); //TODO: Add a LOADING_FAVOURITES signal

        json_parser_load_from_file(parse, fp, &err);

        if (err)
        {
            g_warning("{GtFavouritesManager} Error move local favourite channels to twitch '%s'", err->message);
            return;
        }

        root = json_parser_get_root(parse);
        jarr = json_node_get_array(root);

        for (GList* l = json_array_get_elements(jarr); l != NULL; l = l->next)
        {
            GtChannel* chan = GT_CHANNEL(json_gobject_deserialize(GT_TYPE_CHANNEL, l->data));
            //TODO: Error handling
            gt_twitch_follow_channel_async(main_app->twitch, gt_channel_get_name(chan), NULL, NULL);
            g_object_unref(chan);
        }

        g_object_unref(parse);
        g_free(fp);

        gt_favourites_manager_load_from_twitch(self);
    }

    g_rename(fp, new_fp);

    g_free(fp);
    g_free(new_fp);
}
static void
credentials_set_cb(GObject* source,
                   GParamSpec* pspec,
                   gpointer udata)
{
    GtTwitchChatView* self = GT_TWITCH_CHAT_VIEW(udata);
    GtTwitchChatViewPrivate* priv = gt_twitch_chat_view_get_instance_private(self);
    gchar* user_name;
    gchar* oauth_token;

    g_object_get(main_app,
                 "user-name", &user_name,
                 "oauth-token", &oauth_token,
                 NULL);

    if (!user_name || !oauth_token ||
        strlen(user_name) < 1 || strlen(oauth_token) < 1)
    {
        gt_twitch_chat_client_disconnect(priv->chat);
        gtk_text_buffer_set_text(priv->chat_buffer, "", -1);

        gtk_stack_set_visible_child_name(GTK_STACK(priv->main_stack), "loginview");

        priv->joined_channel = FALSE;
    }
    else
    {
        GtChannel* open_chan = NULL;

        g_object_get(GT_WIN_TOPLEVEL(self)->player, "open-channel", &open_chan, NULL);

        gt_twitch_chat_client_connect(priv->chat, oauth_token, user_name);
        gtk_stack_set_visible_child_name(GTK_STACK(priv->main_stack), "chatview");

        if (open_chan && !priv->joined_channel)
        {
            gt_twitch_chat_client_join(priv->chat, gt_channel_get_name(open_chan));
            g_object_unref(open_chan);
        }
    }

    g_free(user_name);
    g_free(oauth_token);
}
Exemple #4
0
static void
show_channel_info_cb(GSimpleAction* action,
                     GVariant* arg,
                     gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);
    GtTwitchChannelInfoDlg* dlg = gt_twitch_channel_info_dlg_new(GTK_WINDOW(self));
    GtChannel* channel;
    const gchar* name;

    g_object_get(self->player, "channel", &channel, NULL);

    name = gt_channel_get_name(channel);

    g_message("{GtWin} Showing channel info for '%s'", name);

    gtk_window_present(GTK_WINDOW(dlg));

    gt_twitch_channel_info_dlg_load_channel(dlg, name);

    g_object_unref(channel);
}