1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/* logview-main.c - logview main
 *
 * Copyright (C) 2005 Vincent Noel <vnoel@cox.net>
 * Copyright (C) 2008 Cosimo Cecchi <cosimoc@gnome.org>
 *
 * 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 2 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 St, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "config.h"

#include <stdlib.h>

#include <glib/gi18n.h>
#include <glib.h>

#include <ctk/ctk.h>

#include "logview-app.h"

/* log files specified on the command line */
static char **log_files = NULL;

static void
app_quit_cb (LogviewApp *app,<--- Parameter 'app' can be declared as pointer to const
             gpointer user_data)
{
  ctk_main_quit ();
}

static void
logview_show_version_and_quit (void)
{
  g_print ("%s - Version %s\n"
           "Copyright (C) 2004-2008 Vincent Noel, Cosimo Cecchi and others.\n",
           g_get_application_name (),
           VERSION);

  exit (0);
}

static GOptionContext *
create_option_context (void)
{
  GOptionContext *context;

  const GOptionEntry entries[] = {
    { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
      logview_show_version_and_quit, N_("Show the application's version"), NULL },
    { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &log_files,
      NULL, N_("[LOGFILE...]") },
    { NULL },
  };

  context = g_option_context_new (_(" - Browse and monitor logs"));
  g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_set_ignore_unknown_options (context, TRUE);
  g_option_context_add_group (context, ctk_get_option_group (TRUE));

  return context;
}

int
main (int argc, char *argv[])
{
  GError *error = NULL;
  GOptionContext *context;
  LogviewApp *app;

  bindtextdomain (GETTEXT_PACKAGE, CAFELOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  context = create_option_context ();

  g_option_context_parse (context, &argc, &argv, &error);

  if (error) {
    g_critical ("Unable to parse arguments: %s", error->message);
    g_error_free (error);
    g_option_context_free (context);

    exit (1);
  }

  g_option_context_free (context);
  g_set_application_name (_("Log Viewer"));

  app = logview_app_get ();

  if (!app) {
    g_critical ("Unable to create the user interface.");

    exit (1);
  } else {
    g_signal_connect (app, "app-quit",
                      G_CALLBACK (app_quit_cb), NULL);<--- You might need to cast the function pointer here
  }

  logview_app_initialize (app, log_files);

  g_object_set (ctk_settings_get_default (), "ctk-menu-images", TRUE, NULL);
  g_object_set (ctk_settings_get_default (), "ctk-button-images", TRUE, NULL);

  ctk_main ();

  g_object_unref (app);

  return EXIT_SUCCESS;
}