static void
fetch_oauth_info_cb(GObject* source,
    GAsyncResult* res, gpointer udata)
{
    GtTwitchLoginDlg* self = GT_TWITCH_LOGIN_DLG(udata);
    GError* err = NULL;

    GtOAuthInfo* oauth_info = gt_twitch_fetch_oauth_info_finish(main_app->twitch, res, &err);

    if (err)
    {
        GtkWindow* win = gtk_window_get_transient_for(GTK_WINDOW(self));

        g_assert(GT_IS_WIN(win));

        gt_win_show_error_message(GT_WIN(win), _("Unable to fetch user info"),
            "Unable to fetch user info because: %s", err->message);

        g_error_free(err);
    }
    else
    {
        MESSAGEF("Successfully got username '%s' and id '%s'", oauth_info->user_name, oauth_info->user_id);

        gt_app_set_oauth_info(main_app, oauth_info);

        gt_win_show_info_message(GT_WIN(gtk_window_get_transient_for(GTK_WINDOW(self))),
            _("Successfully logged in to Twitch!"));
    }

    gtk_widget_destroy(GTK_WIDGET(self));
}
Пример #2
0
static void
show_about_cb(GSimpleAction* action,
              GVariant* par,
              gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);
    GtkWidget* about_dlg = NULL;

    const char* authors[] = {"Vincent Szolnoky", NULL};
    const char* contributors[] = {"Dimitrios Christidis", NULL};

    about_dlg = gtk_about_dialog_new();

    g_object_set(about_dlg,
                 "version", GT_VERSION,
                 "program-name", "GNOME Twitch",
                 "authors", &authors,
                 "license-type", GTK_LICENSE_GPL_3_0,
                 "copyright", "Copyright © 2015 Vincent Szolnoky",
                 "comments", _("Enjoy Twitch on your GNU/Linux desktop"),
                 "logo-icon-name", "gnome-twitch",
                 "website", "https://github.com/vinszent/gnome-twitch",
                 "website-label", "GitHub",
                 // Translators: Put your details here :)
                 "translator-credits", _("translator-credits"),
                 NULL);

    gtk_about_dialog_add_credit_section(GTK_ABOUT_DIALOG(about_dlg), _("Contributors"), contributors);
    gtk_window_set_transient_for(GTK_WINDOW(about_dlg), GTK_WINDOW(self));

    gtk_dialog_run(GTK_DIALOG(about_dlg));
    gtk_widget_destroy(about_dlg);
}
Пример #3
0
static void
get_property (GObject*    obj,
              guint       prop,
              GValue*     val,
              GParamSpec* pspec)
{
    GtWin* self = GT_WIN(obj);
    GtWinPrivate* priv = gt_win_get_instance_private(self);

    switch (prop)
    {
        case PROP_CHANNELS_VIEW:
            g_value_set_object(val, priv->channels_view);
            break;
        case PROP_GAMES_VIEW:
            g_value_set_object(val, priv->games_view);
            break;
        case PROP_FULLSCREEN:
            g_value_set_boolean(val, priv->fullscreen);
            break;
        case PROP_VISIBLE_VIEW:
            g_value_set_object(val, gtk_stack_get_visible_child(GTK_STACK(priv->browse_stack)));
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop, pspec);
    }
}
Пример #4
0
static void
show_twitch_login_cb(GSimpleAction* action,
                     GVariant* par,
                     gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);
    gchar* oauth_token;
    gchar* user_name;

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

    if (oauth_token && user_name &&
        strlen(oauth_token) > 0 && strlen(user_name) > 0)
    {
        gt_win_ask_question(self, _("Already logged into Twitch, refresh login?"),
                            G_CALLBACK(refresh_login_cb), self);
    }
    else
    {
        GtTwitchLoginDlg* dlg = gt_twitch_login_dlg_new(GTK_WINDOW(self));

        gtk_window_present(GTK_WINDOW(dlg));
    }
}
Пример #5
0
static void
show_settings_cb(GSimpleAction* action,
                 GVariant* par,
                 gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);

    if (!priv->settings_dlg)
    {
        priv->settings_dlg = gt_settings_dlg_new(self);
        g_object_add_weak_pointer(G_OBJECT(priv->settings_dlg), (gpointer *) &priv->settings_dlg);
    }

    if (par)
    {
        GEnumClass* eclass = g_type_class_ref(GT_TYPE_SETTINGS_DLG_VIEW);
        GEnumValue* eval = g_enum_get_value_by_nick(eclass, g_variant_get_string(par, NULL));

        gt_settings_dlg_set_view(priv->settings_dlg, eval->value);

        g_simple_action_set_state(action, par);

        g_type_class_unref(eclass);
    }

    gtk_window_present(GTK_WINDOW(priv->settings_dlg));
}
Пример #6
0
static void
show_view_default_cb(GSimpleAction* action,
                     GVariant* arg,
                     gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);

    if (gtk_stack_get_visible_child(GTK_STACK(priv->browse_stack)) == priv->channels_view)
        gt_channels_view_show_type(GT_CHANNELS_VIEW(priv->channels_view), GT_CHANNELS_CONTAINER_TYPE_TOP);
    else if (gtk_stack_get_visible_child(GTK_STACK(priv->browse_stack)) == priv->games_view)
        gt_games_view_show_type(GT_GAMES_VIEW(priv->games_view), GT_GAMES_CONTAINER_TYPE_TOP);
}
Пример #7
0
static gboolean
key_press_cb(GtkWidget* widget,
             GdkEventKey* evt,
             gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);
    GdkModifierType modifiers = gtk_accelerator_get_default_mod_mask();
    gboolean playing;
    GAction *action;

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

    if (MAIN_VISIBLE_CHILD == GTK_WIDGET(self->player))
    {
        if (evt->keyval == GDK_KEY_Escape)
        {
            if (priv->fullscreen)
                g_object_set(self, "fullscreen", FALSE, NULL);
            else
            {
                action = g_action_map_lookup_action(G_ACTION_MAP(self), "close_player");
                g_action_activate(action, NULL);
            }
        }
        else if (evt->keyval == GDK_KEY_f)
        {
            g_object_set(self, "fullscreen", !priv->fullscreen, NULL);
        }
    }
    else
    {
        if (evt->keyval == GDK_KEY_Escape)
            gt_browse_header_bar_stop_search(GT_BROWSE_HEADER_BAR(priv->browse_header_bar));
        else if (evt->keyval == GDK_KEY_f && (evt->state & modifiers) == GDK_CONTROL_MASK)
            gt_browse_header_bar_toggle_search(GT_BROWSE_HEADER_BAR(priv->browse_header_bar));
        else
        {
            GtkWidget* view = gtk_stack_get_visible_child(GTK_STACK(priv->browse_stack));

            if (view == priv->channels_view)
                gt_channels_view_handle_event(GT_CHANNELS_VIEW(priv->channels_view), (GdkEvent*) evt);
            else if (view == priv->games_view)
                gt_games_view_handle_event(GT_GAMES_VIEW(priv->games_view), (GdkEvent*) evt);
            else if (view == priv->follows_view)
                gt_follows_view_handle_event(GT_FOLLOWS_VIEW(priv->follows_view), (GdkEvent* )evt);
        }
    }

    return FALSE;
}
Пример #8
0
static void
close_player_cb(GSimpleAction* action,
                GVariant* arg,
                gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);

    gt_player_close_channel(GT_PLAYER(self->player));

    gtk_stack_set_visible_child_name(GTK_STACK(priv->header_stack),
                                     "browse");
    gtk_stack_set_visible_child_name(GTK_STACK(priv->main_stack),
                                     "browse");
}
Пример #9
0
static void
refresh_login_cb(GtkInfoBar* info_bar,
                 gint res,
                 gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);

    switch (res)
    {
        case GTK_RESPONSE_YES:
            gtk_window_present(GTK_WINDOW(gt_twitch_login_dlg_new(GTK_WINDOW(self))));
            break;
    }
}
Пример #10
0
static gboolean
delete_cb(GtkWidget* widget,
          GdkEvent* evt,
          gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);
    int width;
    int height;

    gtk_window_get_size(GTK_WINDOW(self), &width, &height);

    g_settings_set_int(main_app->settings, "window-width", width);
    g_settings_set_int(main_app->settings, "window-height", height);

    return FALSE;
}
Пример #11
0
void
gt_player_open_channel(GtPlayer* self, GtChannel* chan)
{
    gchar* status;
    gchar* name;
    gchar* display_name;
    gchar* token;
    gchar* sig;
    GtTwitchStreamData* stream_data;
    GVariant* default_quality;
    GtTwitchStreamQuality _default_quality;
    GAction* quality_action;
    GtWin* win;

    g_object_set(self, "open-channel", chan, NULL);

    g_object_get(chan, 
                 "display-name", &display_name,
                 "name", &name,
                 "status", &status,
                 NULL);

    default_quality = g_settings_get_value(main_app->settings, "default-quality");
    _default_quality = g_settings_get_enum(main_app->settings, "default-quality");

    g_message("{GtPlayer} Opening channel '%s' with quality '%d'", name, _default_quality);

    win = GT_WIN(gtk_widget_get_toplevel(GTK_WIDGET(self)));
    quality_action = g_action_map_lookup_action(G_ACTION_MAP(win), "player_set_quality");
    g_action_change_state(quality_action, default_quality);

    gt_twitch_stream_access_token(main_app->twitch, name, &token, &sig);
    stream_data = gt_twitch_stream_by_quality(main_app->twitch,
                                              name,
                                              _default_quality,
                                              token, sig);

    GT_PLAYER_GET_IFACE(self)->set_uri(self, stream_data->url);
    GT_PLAYER_GET_IFACE(self)->play(self);

    gt_twitch_stream_data_free(stream_data);
    g_free(name);
    g_free(status);
    g_free(token);
    g_free(sig);
}
Пример #12
0
static void
set_property(GObject*      obj,
             guint         prop,
             const GValue* val,
             GParamSpec*   pspec)
{
    GtWin* self = GT_WIN(obj);
    GtWinPrivate* priv = gt_win_get_instance_private(self);

    switch (prop)
    {
        case PROP_VISIBLE_VIEW:
            // Do nothing
            break;
        case PROP_FULLSCREEN:
            priv->fullscreen = g_value_get_boolean(val);
            update_fullscreen(self);
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop, pspec);
    }
}
Пример #13
0
static void
refresh_view_cb(GSimpleAction* action,
                GVariant* arg,
                gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);
    GtkWidget* visible_child = gtk_stack_get_visible_child(GTK_STACK(priv->browse_stack));

    if (visible_child == priv->channels_view)
        gt_channels_view_refresh(GT_CHANNELS_VIEW(priv->channels_view));
    else if (visible_child == priv->games_view)
        gt_games_view_refresh(GT_GAMES_VIEW(priv->games_view));
    else if (visible_child == priv->follows_view)
    {
        //TODO: Quick hack, turn this into a proper refresh function
        if (gt_app_credentials_valid(main_app))
            gt_follows_manager_load_from_twitch(main_app->fav_mgr);
        else
            gt_follows_manager_load_from_file(main_app->fav_mgr);
    }
}
Пример #14
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);
}
Пример #15
0
static void
close_info_bar_cb(GtkInfoBar* bar,
                  gint res,
                  gpointer udata)
{
    GtWin* self = GT_WIN(udata);
    GtWinPrivate* priv = gt_win_get_instance_private(self);

    if (priv->cur_info_data)
    {
        if (priv->cur_info_data->cb)
        {
            g_signal_handlers_disconnect_by_func(priv->info_bar,
                                                 priv->cur_info_data->cb,
                                                 priv->cur_info_data->udata);
        }

        g_free(priv->cur_info_data->msg);
        g_free(priv->cur_info_data);
    }

    show_info_bar(self);
}