Skip to content

Commit

Permalink
Begin OAuth window
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Nov 11, 2010
1 parent af1ca36 commit 4a6af28
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ MAINTAINERCLEANFILES = \
po/[email protected] \
po/[email protected] \
po/insert-header.sin \
po/microtwitter.pot \
po/micromoko.pot \
po/quot.sed \
po/remove-potcdate.sin
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ORIGDIR=`pwd`
cd $srcdir

autoreconf -v --install || exit 1
#intltoolize -c --automake --force || exit 1
intltoolize -c --automake --force || exit 1
cd $ORIGDIR || exit $?

$srcdir/configure --enable-debug "$@"
16 changes: 14 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ AC_GNU_SOURCE
AC_PROG_CC
AC_PROG_LIBTOOL

AM_GNU_GETTEXT(external)
AM_GNU_GETTEXT_VERSION([0.12.1])
dnl Intl for gettext
IT_PROG_INTLTOOL([0.35.0])

if test "x$localedir" == x
then
localedir='${datadir}/locale'
AC_SUBST(localedir)
AM_GLIB_DEFINE_LOCALEDIR([localedir])
fi

AM_GLIB_GNU_GETTEXT
GETTEXT_PACKAGE="micromoko"
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, ["$GETTEXT_PACKAGE"], [Name of the gettext message domain])

dnl Dependencies
ELEMENTARY_REQUIRED=0.0.0
Expand Down
6 changes: 4 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AM_LDFLAGS = \
@ELEMENTARY_LIBS@ \
@GLIB_LIBS@ \
@MOKOSUITE_LIBS@ \
-lreadline -Ltwitter -ltwitter
-Ltwitter -ltwitter


bin_PROGRAMS = micromoko
Expand All @@ -24,4 +24,6 @@ micromoko_SOURCES = \
globals.h \
main.c \
timeline.c \
timeline.h
timeline.h \
auth.c \
auth.h
137 changes: 137 additions & 0 deletions src/auth.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Micromoko
* Authorization window
* Copyright (C) 2009-2010 Daniele Ricci <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <Elementary.h>
#include <mokosuite/utils/utils.h>
#include <mokosuite/ui/gui.h>

#include "globals.h"
#include "twitter/twitter.h"
#include "auth.h"

#include <glib/gi18n-lib.h>

static MokoWin* win = NULL;
static Evas_Object* btn_auth = NULL;
static Evas_Object* msg_status = NULL;
static Evas_Object* pin_entry = NULL;

static void _delete(void* mokowin, Evas_Object* obj, void* event_info)
{
// TODO che famo?
mokowin_destroy((MokoWin *)mokowin);
}

static void update_status(const char* status)
{
elm_label_label_set(msg_status, status);
}

static void _access_token(twitter_session* session, void* userdata)
{
// TODO now what?
remote_config_service_set_string(home_config, "auth", "access_token", session->access.key);
remote_config_service_set_string(home_config, "auth", "access_token_secret", session->access.secret);
}

static bool _pin_response(void* userdata)
{
// remove auth button
evas_object_del(btn_auth);
btn_auth = NULL;

pin_entry = elm_entry_add(win->win);
evas_object_size_hint_weight_set(pin_entry, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(pin_entry, EVAS_HINT_FILL, 0.5);

elm_box_pack_before(win->win, pin_entry, msg_status);
evas_object_show(pin_entry);

update_status(_("Paste PIN code above."));
return FALSE;
}

static void _request_token(twitter_session* session, void* userdata)
{
update_status(_("Starting browser..."));

// access token for pin :)
char* cmd = g_strdup_printf("xdg-open \"%s%s?oauth_token=%s\"",
TWITTER_BASE_URI, TWITTER_AUTHORIZE_FUNC, session->request.key);
system(cmd);
g_free(cmd);

ecore_timer_add(5, _pin_response, NULL);
//twitter_session_oauth_access_token(session, pin, _access_token, userdata);
// TODO swich UI to pin request :)
}

static void _authorize(void* data, Evas_Object* obj, void* event_info)
{
// start authentication
elm_object_disabled_set(obj, TRUE);
update_status(_("Requesting token..."));
twitter_session_oauth_request_token(global_session, _request_token, NULL);
}

void auth_win(void)
{
if (!win) {
win = mokowin_new("micromoko_auth", TRUE);
if (win == NULL) {
EINA_LOG_ERR("cannot create authorization window.");
return;
}

win->delete_callback = _delete;

elm_win_title_set(win->win, _("Authorization"));

mokowin_create_vbox(win, FALSE);
mokowin_set_title(win, _("Authorization"));

//mokowin_menu_enable(win);
//mokowin_menu_set(win, make_menu());

// big auth button :D
btn_auth = elm_button_add(win->win);
elm_button_label_set(btn_auth, _("Authorize to Twitter"));
evas_object_size_hint_weight_set(btn_auth, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(btn_auth, EVAS_HINT_FILL, 0.5);
evas_object_smart_callback_add(btn_auth, "clicked", _authorize, NULL);

mokowin_pack_end(win, btn_auth, FALSE);
evas_object_show(btn_auth);

// label/status
msg_status = elm_label_add(win->win);
elm_label_label_set(msg_status, _("Click the button to authorize."));
evas_object_size_hint_weight_set(msg_status, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(msg_status, 0.5, 0.5);

mokowin_pack_end(win, msg_status, FALSE);
evas_object_show(msg_status);

// TEST
evas_object_resize(win->win, 480, 640);
}

mokowin_activate(win);
}
28 changes: 28 additions & 0 deletions src/auth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Micromoko
* Authorization window
* Copyright (C) 2009-2010 Daniele Ricci <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef __AUTH_H
#define __AUTH_H


void auth_win(void);


#endif /* __AUTH_H */
3 changes: 3 additions & 0 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <stdlib.h>
#include <mokosuite/utils/remote-config-service.h>

#include "twitter/twitter.h"

// default log domain
#undef EINA_LOG_DOMAIN_DEFAULT
#define EINA_LOG_DOMAIN_DEFAULT _log_dom
Expand All @@ -45,6 +47,7 @@ extern int _log_dom;
#define MICROMOKO_DATADIR DATADIR "/micromoko"

extern RemoteConfigService* home_config;
extern twitter_session* global_session;

void get_screen_size(int *w, int *h);

Expand Down
50 changes: 19 additions & 31 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@
#include <glib.h>
#include <dbus/dbus-glib-bindings.h>

// TEST
#include <readline/readline.h>
#include <readline/history.h>

#include "globals.h"
#include "twitter/twitter.h"
#include "auth.h"

#define MICROMOKO_NAME "org.mokosuite.micromoko"
#define MICROMOKO_CONFIG_PATH MOKOSUITE_DBUS_PATH "/Micromoko/Config"
Expand All @@ -40,25 +37,8 @@
int _log_dom = -1;

RemoteConfigService* home_config = NULL;
twitter_session* global_session = NULL;

static void _access_token(twitter_session* session, void* userdata)
{
// TODO now what?
remote_config_service_set_string(home_config, "auth", "access_token", session->access.key);
remote_config_service_set_string(home_config, "auth", "access_token_secret", session->access.secret);
}

static void _request_token(twitter_session* session, void* userdata)
{
// TODO access token for pin :)
char* cmd = g_strdup_printf("xdg-open \"%s%s?oauth_token=%s\"",
TWITTER_BASE_URI, TWITTER_AUTHORIZE_FUNC, session->request.key);
system(cmd);
g_free(cmd);

char* pin = readline("PIN: ");
twitter_session_oauth_access_token(session, pin, _access_token, userdata);
}

int main(int argc, char* argv[])
{
Expand Down Expand Up @@ -98,25 +78,33 @@ int main(int argc, char* argv[])
elm_theme_extension_add(NULL, MICROMOKO_DATADIR "/theme.edj");
// TODO additional themes

// TODO public timeline or last open window?

// TEST twitter test :)
// twitter session
// TODO read consumer token from configuration?
oauth_token consumer = {
"dY49wvIY7386ET15vCRVQ",
"D8wKnvbTQqxJmxBC0JyHVY6LpHdpTBbJwyISlrUg8"
};
twitter_session* sess = twitter_session_new(&consumer);
global_session = twitter_session_new(&consumer);

// if not yet authenticated, open twitter authorization window
oauth_token access_token = {NULL, NULL};
remote_config_service_get_string(home_config, "auth", "access_token", &access_token.key);
remote_config_service_get_string(home_config, "auth", "access_token_secret", &access_token.secret);
if (access_token.key != NULL)
twitter_session_set_access_token(sess, &access_token);
else
twitter_session_oauth_request_token(sess, _request_token, NULL);

// access token is present, go to last open window
if (access_token.key != NULL && strlen(access_token.key) && access_token.secret == NULL && strlen(access_token.secret)) {
// TODO last open window
EINA_LOG_DBG("open last window");
}

// TEST twitter test
// no access token, authorization needed
else {
// auth window
EINA_LOG_DBG("open auth window");
auth_win();
}

// TODO public timeline or last open window?

elm_run();
elm_shutdown();
Expand Down
2 changes: 1 addition & 1 deletion src/timeline.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* MicroTwitter
* Micromoko
* Generic timeline window
* Copyright (C) 2009-2010 Daniele Ricci <[email protected]>
*
Expand Down
2 changes: 1 addition & 1 deletion src/timeline.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* MicroTwitter
* Micromoko
* Generic timeline window
* Copyright (C) 2009-2010 Daniele Ricci <[email protected]>
*
Expand Down

0 comments on commit 4a6af28

Please sign in to comment.