| 1 | // ePDFView - A lightweight PDF Viewer. |
|---|
| 2 | // Copyright (C) 2006 Emma's Software. |
|---|
| 3 | // |
|---|
| 4 | // This program is free software; you can redistribute it and/or modify |
|---|
| 5 | // it under the terms of the GNU General Public License as published by |
|---|
| 6 | // the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | // (at your option) any later version. |
|---|
| 8 | // |
|---|
| 9 | // This program is distributed in the hope that it will be useful, |
|---|
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | // GNU General Public License for more details. |
|---|
| 13 | // |
|---|
| 14 | // You should have received a copy of the GNU General Public License |
|---|
| 15 | // along with this program; if not, write to the Free Software |
|---|
| 16 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 | |
|---|
| 18 | #include <config.h> |
|---|
| 19 | #include <stdlib.h> |
|---|
| 20 | #include <gettext.h> |
|---|
| 21 | #include <locale.h> |
|---|
| 22 | #include <gtk/gtk.h> |
|---|
| 23 | #include "epdfview.h" |
|---|
| 24 | #include <MainView.h> |
|---|
| 25 | |
|---|
| 26 | using namespace ePDFView; |
|---|
| 27 | |
|---|
| 28 | struct LoadFileInfo |
|---|
| 29 | { |
|---|
| 30 | gchar *fileName; |
|---|
| 31 | MainPter *mainPter; |
|---|
| 32 | PDFDocument *document; |
|---|
| 33 | }; |
|---|
| 34 | |
|---|
| 35 | static int |
|---|
| 36 | loadFileFromCommandLine (gpointer data) |
|---|
| 37 | { |
|---|
| 38 | LoadFileInfo *info = static_cast<LoadFileInfo *> (data); |
|---|
| 39 | |
|---|
| 40 | info->mainPter->setOpenState (info->fileName, FALSE); |
|---|
| 41 | info->document->load (info->fileName, NULL); |
|---|
| 42 | |
|---|
| 43 | g_free (info->fileName); |
|---|
| 44 | delete info; |
|---|
| 45 | |
|---|
| 46 | return FALSE; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | int |
|---|
| 50 | main (int argc, char **argv) |
|---|
| 51 | { |
|---|
| 52 | // Enable NLS. |
|---|
| 53 | setlocale (LC_ALL, ""); |
|---|
| 54 | bindtextdomain (PACKAGE, LOCALEDIR); |
|---|
| 55 | bind_textdomain_codeset (PACKAGE, "UTF-8"); |
|---|
| 56 | textdomain (PACKAGE); |
|---|
| 57 | // Create the command line options context. |
|---|
| 58 | GOptionContext *optionContext = |
|---|
| 59 | g_option_context_new (_("[FILE] - view PDF documents")); |
|---|
| 60 | g_option_context_add_group (optionContext, gtk_get_option_group (TRUE)); |
|---|
| 61 | GError *error = NULL; |
|---|
| 62 | if ( !g_option_context_parse (optionContext, &argc, &argv, &error) ) |
|---|
| 63 | { |
|---|
| 64 | g_critical ("Error parsing command line options: %s\n", error->message); |
|---|
| 65 | g_error_free (error); |
|---|
| 66 | exit (EXIT_FAILURE); |
|---|
| 67 | } |
|---|
| 68 | // Initialise the working thread. |
|---|
| 69 | IJob::init (); |
|---|
| 70 | // Initialise the GTK library. |
|---|
| 71 | gtk_init (&argc, &argv); |
|---|
| 72 | g_set_application_name (_("PDF Viewer")); |
|---|
| 73 | // Create the main presenter. |
|---|
| 74 | PDFDocument *document = new PDFDocument; |
|---|
| 75 | MainPter *mainPter = new MainPter (document); |
|---|
| 76 | // Create the main view. |
|---|
| 77 | MainView *mainView = new MainView (mainPter); |
|---|
| 78 | // Let know to the presenter which is its view. |
|---|
| 79 | mainPter->setView (mainView); |
|---|
| 80 | // Now check if we have additional parameters. Any additional parameter |
|---|
| 81 | // will be a file name to open. |
|---|
| 82 | if ( argc > 1 ) |
|---|
| 83 | { |
|---|
| 84 | LoadFileInfo *info = new LoadFileInfo; |
|---|
| 85 | info->mainPter = mainPter; |
|---|
| 86 | info->document = document; |
|---|
| 87 | info->fileName = g_strdup (argv[1]); |
|---|
| 88 | g_idle_add (loadFileFromCommandLine, info); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | gtk_main(); |
|---|
| 92 | |
|---|
| 93 | // There's no need for us to delete the main view, as it's |
|---|
| 94 | // the presenter's responsibility. |
|---|
| 95 | delete mainPter; |
|---|
| 96 | |
|---|
| 97 | // Save the configuration. |
|---|
| 98 | Config::getConfig().save (); |
|---|
| 99 | |
|---|
| 100 | g_option_context_free (optionContext); |
|---|
| 101 | |
|---|
| 102 | // All done!. |
|---|
| 103 | return EXIT_SUCCESS; |
|---|
| 104 | } |
|---|