~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/application/application.cpp

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/** @file
2
 
 * @brief  The top level class for managing the application
3
 
 */
4
 
/* Authors:
5
 
 *   Bryce W. Harrington <bryce@bryceharrington.org>
6
 
 *   Ralf Stephan <ralf@ark.in-berlin.de>
7
 
 *
8
 
 * Copyright (C) 2005 Authors
9
 
 *
10
 
 * Released under GNU GPL.  Read the file 'COPYING' for more information.
11
 
 */
12
 
 
13
 
#ifdef HAVE_CONFIG_H
14
 
# include <config.h>
15
 
#endif
16
 
 
17
 
#include <gtkmm/main.h>
18
 
 
19
 
#include "preferences.h"
20
 
#include "application.h"
21
 
#include "editor.h"
22
 
 
23
 
int sp_main_gui(int argc, char const **argv);
24
 
int sp_main_console(int argc, char const **argv);
25
 
 
26
 
static Gtk::Main *_gtk_main;
27
 
static bool _use_gui, _new_gui;
28
 
 
29
 
namespace Inkscape {
30
 
namespace NSApplication {
31
 
 
32
 
Application::Application(int argc, char **argv, bool use_gui, bool new_gui)
33
 
    : _argc(argc),
34
 
      _argv(NULL),
35
 
      _app_impl(NULL),
36
 
      _path_home(NULL)
37
 
{
38
 
    _use_gui = use_gui;
39
 
    _new_gui = new_gui;
40
 
    
41
 
    if (argv != NULL) {
42
 
        _argv = argv;   // TODO:  Is this correct?
43
 
    }
44
 
    
45
 
    if (new_gui) {
46
 
        _gtk_main = new Gtk::Main(argc, argv, true);
47
 
 
48
 
        // TODO:  Determine class by arguments
49
 
        g_warning("Creating new Editor");
50
 
        _app_impl = (AppPrototype*) Editor::create(_argc, _argv);
51
 
        
52
 
    } else if (use_gui) {
53
 
        // No op - we'll use the old interface
54
 
    } else {
55
 
        _app_impl = NULL; // = Cmdline(_argc, _argv);
56
 
    }
57
 
 
58
 
    /// \todo Install segv handler here?
59
 
    
60
 
//    Inkscape::Extension::init();
61
 
}
62
 
 
63
 
Application::~Application()
64
 
{
65
 
    g_free(_path_home);
66
 
}
67
 
 
68
 
 
69
 
/** Returns the current home directory location */
70
 
gchar const*
71
 
Application::homedir() const
72
 
{
73
 
    if ( !_path_home ) {
74
 
        _path_home = g_strdup(g_get_home_dir());
75
 
        gchar* utf8Path = g_filename_to_utf8( _path_home, -1, NULL, NULL, NULL );
76
 
        if ( utf8Path ) {
77
 
            _path_home = utf8Path;
78
 
            if ( !g_utf8_validate(_path_home, -1, NULL) ) {
79
 
                g_warning( "Home directory is non-UTF-8" );
80
 
            }
81
 
        }
82
 
    }
83
 
    if ( !_path_home && _argv != NULL) {
84
 
        gchar * path = g_path_get_dirname(_argv[0]);
85
 
        gchar * utf8Path = g_filename_to_utf8( path, -1, NULL, NULL, NULL );
86
 
        g_free(path);
87
 
        if (utf8Path) {
88
 
            _path_home = utf8Path;
89
 
            if ( !g_utf8_validate(_path_home, -1, NULL) ) {
90
 
                g_warning( "Application run directory is non-UTF-8" );
91
 
            }
92
 
        }
93
 
    }
94
 
    return _path_home;
95
 
}
96
 
 
97
 
gint
98
 
Application::run()
99
 
{
100
 
    gint result = 0;
101
 
 
102
 
    /* Note:  This if loop should be replaced by calls to the
103
 
     * various subclasses of I::A::AppPrototype.
104
 
     */
105
 
    if (_gtk_main != NULL) {
106
 
        g_assert(_app_impl != NULL);
107
 
        g_warning("Running main window");
108
 
        Gtk::Window *win = static_cast<Gtk::Window*>(_app_impl->getWindow());
109
 
        g_assert(win != NULL);
110
 
        _gtk_main->run(*win);
111
 
        result = 0;
112
 
 
113
 
    } else if (_use_gui) {
114
 
        result = sp_main_gui(_argc, (const char**)_argv);
115
 
 
116
 
    } else {
117
 
        result = sp_main_console(_argc, (const char**)_argv);
118
 
    }
119
 
 
120
 
    return result;
121
 
}
122
 
 
123
 
void
124
 
Application::exit()
125
 
{
126
 
    Inkscape::Preferences::unload();
127
 
 
128
 
    if (_gtk_main != NULL) {
129
 
        _gtk_main->quit();
130
 
    }
131
 
 
132
 
}
133
 
 
134
 
bool
135
 
Application::getUseGui()
136
 
{
137
 
    return _use_gui;
138
 
}
139
 
 
140
 
bool
141
 
Application::getNewGui()
142
 
{
143
 
    return _new_gui;
144
 
}
145
 
 
146
 
 
147
 
} // namespace NSApplication
148
 
} // namespace Inkscape
149
 
 
150
 
 
151
 
/*
152
 
  Local Variables:
153
 
  mode:c++
154
 
  c-file-style:"stroustrup"
155
 
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
156
 
  indent-tabs-mode:nil
157
 
  fill-column:99
158
 
  End:
159
 
*/
160
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :