<commit_before>/*
 * Mojito - social data store
 * Copyright (C) 2008 - 2009 Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <config.h>
#include <stdlib.h>
#include "twitter.h"
#include <twitter-glib/twitter-glib.h>
#include <mojito/mojito-item.h>
#include <mojito/mojito-set.h>
#include <mojito/mojito-utils.h>
#include <mojito/mojito-web.h>
#include <gconf/gconf-client.h>
#include <mojito/mojito-online.h>

G_DEFINE_TYPE (MojitoServiceTwitter, mojito_service_twitter, MOJITO_TYPE_SERVICE)

#define GET_PRIVATE(o) \
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), MOJITO_TYPE_SERVICE_TWITTER, MojitoServiceTwitterPrivate))

#define KEY_DIR "/apps/mojito/services/twitter"
#define KEY_USER KEY_DIR "/user"
#define KEY_PASSWORD KEY_DIR "/password"

struct _MojitoServiceTwitterPrivate {
  gboolean running;
  GConfClient *gconf;
  gchar *username, *password;

  TwitterClient *client;
  TwitterUser *user;

  gulong self_handle;

  /* GConf notify handles */
  guint username_notify_id, password_notify_id;

  MojitoSet *set;
};

static void
user_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data)
{
  MojitoService *service = MOJITO_SERVICE (user_data);
  MojitoServiceTwitter *twitter = MOJITO_SERVICE_TWITTER (service);
  MojitoServiceTwitterPrivate *priv = twitter->priv;
  const char *username = NULL, *password = NULL;

  if (g_str_equal (entry->key, KEY_USER)) {
    if (entry->value)
      username = gconf_value_get_string (entry->value);
    if (username[0] == '\0')
      username = NULL;
    priv->username = g_strdup (username);
  } else if (g_str_equal (entry->key, KEY_PASSWORD)) {
    if (entry->value)
      password = gconf_value_get_string (entry->value);
    if (password[0] == '\0')
      password = <PASSWORD>;
    priv->password = g_strdup (password);
  }

  /* Get our details. This will cause the user_received signal to be fired */
  if (priv->username && priv->password) {
    /* TODO: yes, this leaks.  Dispose cycle in twitter-glib */
    priv->user = NULL;
    twitter_client_set_user (priv->client, priv->username, priv->password);
    priv->self_handle =
      twitter_client_show_user_from_id (priv->client, priv->username);
  } else {
    /* TODO: yes, this leaks.  Dispose cycle in twitter-glib */
    priv->user = NULL;

    mojito_service_emit_capabilities_changed (service, 0);
    mojito_service_emit_refreshed (service, NULL);
  }
}

static MojitoItem *
make_item_from_status (MojitoService *service, TwitterStatus *status)
{
  MojitoItem *item;
  TwitterUser *user;<commit_msg>[twitter] Don't crash if the username or password is unset<commit_after>/*
 * Mojito - social data store
 * Copyright (C) 2008 - 2009 Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <config.h>
#include <stdlib.h>
#include "twitter.h"
#include <twitter-glib/twitter-glib.h>
#include <mojito/mojito-item.h>
#include <mojito/mojito-set.h>
#include <mojito/mojito-utils.h>
#include <mojito/mojito-web.h>
#include <gconf/gconf-client.h>
#include <mojito/mojito-online.h>

G_DEFINE_TYPE (MojitoServiceTwitter, mojito_service_twitter, MOJITO_TYPE_SERVICE)

#define GET_PRIVATE(o) \
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), MOJITO_TYPE_SERVICE_TWITTER, MojitoServiceTwitterPrivate))

#define KEY_DIR "/apps/mojito/services/twitter"
#define KEY_USER KEY_DIR "/user"
#define KEY_PASSWORD KEY_DIR "/password"

struct _MojitoServiceTwitterPrivate {
  gboolean running;
  GConfClient *gconf;
  gchar *username, *password;

  TwitterClient *client;
  TwitterUser *user;

  gulong self_handle;

  /* GConf notify handles */
  guint username_notify_id, password_notify_id;

  MojitoSet *set;
};

static void
user_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data)
{
  MojitoService *service = MOJITO_SERVICE (user_data);
  MojitoServiceTwitter *twitter = MOJITO_SERVICE_TWITTER (service);
  MojitoServiceTwitterPrivate *priv = twitter->priv;
  const char *username = NULL, *password = NULL;

  if (g_str_equal (entry->key, KEY_USER)) {
    if (entry->value)
      username = gconf_value_get_string (entry->value);
    if (username && username[0] == '\0')
      username = NULL;
    priv->username = g_strdup (username);
  } else if (g_str_equal (entry->key, KEY_PASSWORD)) {
    if (entry->value)
      password = gconf_value_get_string (entry->value);
    if (password && password[0] == '\0')
      password = <PASSWORD>;
    priv->password = g_strdup (password);
  }

  /* Get our details. This will cause the user_received signal to be fired */
  if (priv->username && priv->password) {
    /* TODO: yes, this leaks.  Dispose cycle in twitter-glib */
    priv->user = NULL;
    twitter_client_set_user (priv->client, priv->username, priv->password);
    priv->self_handle =
      twitter_client_show_user_from_id (priv->client, priv->username);
  } else {
    /* TODO: yes, this leaks.  Dispose cycle in twitter-glib */
    priv->user = NULL;

    mojito_service_emit_capabilities_changed (service, 0);
    mojito_service_emit_refreshed (service, NULL);
  }
}

static MojitoItem *
make_item_from_status (MojitoService *service, TwitterStatus *status)
{
  MojitoItem *item;
  TwitterUser *user;
{'fraction_non_alphanumeric': 0.10632404985382367, 'fraction_numerical': 0.008001230958609017, 'mean_word_length': 4.284552845528455, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4908211', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2109, 'n_words': 620}