Cut unnecessary MilkTask class.
[milk] / src / milk-dialogs.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License as
4  * published by the Free Software Foundation; either version 2 of the
5  * License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  * General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public
13  * License along with this program; if not, write to the
14  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
15  * Boston, MA  02110-1301  USA
16  *
17  * Authors: Travis Reitter <treitter@gmail.com>
18  */
19
20 #include <config.h>
21
22 #include <glib.h>
23 #include <glib/gi18n.h>
24 #include <gtk/gtk.h>
25 #include <hildon/hildon.h>
26 #include <hildon-uri.h>
27
28 #include "milk-dialogs.h"
29 #include "milk-main-window.h"
30
31 typedef struct {
32         const char *uri;
33         GtkWidget  *finish_button;
34 } LinkClickedClosure;
35
36 static void
37 link_clicked_cb (GtkButton          *link,
38                  LinkClickedClosure *closure)
39 {
40         gtk_widget_set_sensitive (closure->finish_button, TRUE);
41
42         hildon_uri_open (closure->uri, NULL, NULL);
43
44         g_free (closure);
45 }
46
47 static void
48 finish_button_clicked_cb (GtkButton *finish_button,
49                           GtkDialog *dialog)
50 {
51         gtk_dialog_response (dialog, GTK_RESPONSE_OK);
52 }
53
54 GtkDialog*
55 milk_dialogs_auth_prompt (GtkWindow  *parent,
56                           const char *uri)
57 {
58         HildonDialog *dialog;
59         GtkWidget *label;
60         GtkWidget *link;
61         GtkWidget *finish_button;
62         LinkClickedClosure *closure;
63
64         if (!parent)
65                 parent = GTK_WINDOW (milk_main_window_get_default ());
66         
67         dialog = HILDON_DIALOG (hildon_dialog_new ());
68         gtk_window_set_title (GTK_WINDOW (dialog),
69                         _("Log in to Remember The Milk"));
70         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
71
72         label = gtk_label_new (_("Log in, then tap Finish"));
73         gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), label);
74
75         finish_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,
76                         HILDON_BUTTON_ARRANGEMENT_VERTICAL, _("Finish"), NULL);
77         gtk_widget_set_sensitive (finish_button, FALSE);
78         g_signal_connect (finish_button, "clicked",
79                         G_CALLBACK (finish_button_clicked_cb), dialog);
80
81         link = gtk_link_button_new_with_label (uri, _("Log in"));
82         closure = g_new0 (LinkClickedClosure, 1);
83         closure->uri = uri;
84         closure->finish_button = finish_button;
85         g_signal_connect (link, "clicked", G_CALLBACK (link_clicked_cb),
86                         closure);
87
88         gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area),
89                         link);
90         gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area),
91                         finish_button);
92
93         gtk_widget_show_all (GTK_WIDGET (dialog));
94
95         return GTK_DIALOG (dialog);
96 }