~ubuntu-branches/debian/jessie/gnome-color-chooser/jessie

« back to all changes in this revision

Viewing changes to src/main.cc

  • Committer: Bazaar Package Importer
  • Author(s): Werner Pantke
  • Date: 2008-01-11 14:09:32 UTC
  • Revision ID: james.westby@ubuntu.com-20080111140932-sdtlwa781q52bclm
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2006-2007 W. Pantke <gnome-color-chooser@punk-ass-bitch.org>
 
2
//  
 
3
// This program is free software; you can redistribute it and/or modify
 
4
// it under the terms of the GNU General Public License as published by
 
5
// the Free Software Foundation; either version 2 of the License, or
 
6
// (at your option) any later version.
 
7
// 
 
8
// This program is distributed in the hope that it will be useful,
 
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
// GNU General Public License for more details.
 
12
// 
 
13
// You should have received a copy of the GNU General Public License
 
14
// along with this program; if not, write to the Free Software 
 
15
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
16
 
 
17
 
 
18
#ifdef HAVE_CONFIG_H
 
19
#include <config.h>
 
20
#endif
 
21
 
 
22
#include <libgnome/gnome-i18n.h>
 
23
#include <gnome.h>
 
24
 
 
25
#include "utils.h"
 
26
#include "treehandler.h"
 
27
#include "configloader.h"
 
28
#include "exporter.h"
 
29
#include "mainwindow.h"
 
30
#include "gtpexporter.h"
 
31
 
 
32
#include <iostream>
 
33
#include <fstream>
 
34
 
 
35
#include <sys/types.h>
 
36
#include <sys/stat.h>
 
37
 
 
38
#include <libintl.h>
 
39
#include <locale.h>
 
40
 
 
41
using namespace std;
 
42
using namespace GnomeCC;
 
43
 
 
44
 
 
45
#ifdef LIBXML_TREE_ENABLED
 
46
 
 
47
bool config_ok(string configfile, string dbfile, string gtkrcfile)
 
48
{
 
49
 
 
50
  if(! (Utils::Io::check_file(gtkrcfile, true)
 
51
        || Utils::Io::create_file(gtkrcfile)) )
 
52
  {
 
53
    cerr << "cannot create/open file " << gtkrcfile << endl;
 
54
    return false;
 
55
  }
 
56
 
 
57
 
 
58
  if(!Utils::create_include(
 
59
        gtkrcfile,
 
60
        "include \".gtkrc-2.0-gnome-color-chooser\"",
 
61
        ".gtkrc-2.0-gnome-color-chooser"))
 
62
  {
 
63
    if(!Utils::check_include(
 
64
          gtkrcfile,
 
65
          "include \".gtkrc-2.0-gnome-color-chooser\"",
 
66
          ".gtkrc-2.0-gnome-color-chooser"))
 
67
    {
 
68
      cerr << "unable to modify ~/.gtkrc-2.0" << endl;
 
69
      return false;
 
70
    }
 
71
  }
 
72
 
 
73
 
 
74
  if(!Utils::Io::check_file(
 
75
           getenv("HOME") + string("/.gtkrc-2.0-gnome-color-chooser"), true)
 
76
     && !Utils::Io::create_file(
 
77
              getenv("HOME") + string("/.gtkrc-2.0-gnome-color-chooser")))
 
78
  {
 
79
    cerr << "cannot create/open file "
 
80
         << getenv("HOME")
 
81
         << string("/.gtkrc-2.0-gnome-color-chooser")
 
82
         << endl;
 
83
    return false;
 
84
  }
 
85
 
 
86
 
 
87
  if(Utils::Io::check_file(configfile)
 
88
        && !Utils::Io::check_file(configfile, true))
 
89
  {
 
90
    cerr << "cannot write to config file " << configfile << endl;
 
91
    return false;
 
92
  }
 
93
  
 
94
 
 
95
  if(!Utils::Io::check_file(dbfile))
 
96
  {    
 
97
    cerr << "cannot open gnomecc database " << dbfile << endl;
 
98
    return false;      
 
99
  }
 
100
 
 
101
  
 
102
  return true;
 
103
}
 
104
 
 
105
 
 
106
 
 
107
 
 
108
 
 
109
int main (int argc, char *argv[])
 
110
{
 
111
 
 
112
#ifdef ENABLE_NLS
 
113
  setlocale(LC_ALL,"");
 
114
  bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 
115
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 
116
  textdomain(GETTEXT_PACKAGE);
 
117
#endif
 
118
 
 
119
  GnomeProgram *program;
 
120
  program = gnome_program_init
 
121
                (PACKAGE, VERSION,
 
122
                 LIBGNOMEUI_MODULE,
 
123
                 argc, argv,
 
124
//                 GNOME_PARAM_POPT_TABLE, cmd_options_table,
 
125
                 GNOME_PARAM_APP_DATADIR, DATADIR,
 
126
                 GNOME_PARAM_NONE);
 
127
 
 
128
 
 
129
  Gtk::Main kit(argc, argv);
 
130
 
 
131
 
 
132
  string configfile = string(getenv("HOME")).append("/.gnome-color-chooser/config.xml");
 
133
  string configpath = string(getenv("HOME")).append("/.gnome-color-chooser/");
 
134
  string configpath_images = configpath + string("images/");
 
135
  string globalpath_engines = DATADIR + string("/gtk-engines/");
 
136
  string globalpath_profiles = string(DBDIR).append("/profiles/");
 
137
  string dbfile = string(DBDIR).append("/gnome-color-chooser.db");
 
138
  string gtkrcfile = string(getenv("HOME")).append("/.gtkrc-2.0").c_str();
 
139
 
 
140
 
 
141
  cout << "Welcome to " << PACKAGE << " version " << VERSION
 
142
       << " for " << YOUR_OS << endl << endl;
 
143
  //   << "[Datadir: " << DATADIR << "]" << endl
 
144
  //   << "[Localedir: " << LOCALEDIR << "]" << endl
 
145
  //   << "[Gettext Package: " << GETTEXT_PACKAGE << "]" << endl << endl;
 
146
 
 
147
 
 
148
  if(mkdir(configpath.c_str(), (mode_t)00700) != -1)
 
149
  {
 
150
    if(mkdir(configpath_images.c_str(), (mode_t)00755) == -1)
 
151
    {
 
152
      perror(configpath_images.c_str());
 
153
      return 1;
 
154
    }
 
155
  }
 
156
 
 
157
 
 
158
  if(!config_ok(configfile, dbfile, gtkrcfile))
 
159
    return 1;
 
160
 
 
161
 
 
162
  // config has to be loaded before the glade file
 
163
  TreeHandler* pConfig = new TreeHandler((char*)dbfile.c_str());
 
164
  Exporter::init(pConfig);
 
165
 
 
166
 
 
167
 
 
168
  // load Glade file and instantiate its widgets
 
169
  Glib::RefPtr<Gnome::Glade::Xml> refXml;
 
170
  try
 
171
  {
 
172
    cout << "Loading GUI with libglade.. " << flush;
 
173
    refXml = Gnome::Glade::Xml::create(string(GLADEDIR) + string("/gnome-color-chooser.glade"));
 
174
  }
 
175
  catch(const Gnome::Glade::XmlError& ex)
 
176
  {
 
177
    cerr << endl << ex.what() << endl;
 
178
    return 1;
 
179
  }
 
180
 
 
181
  cout << "done" << endl;
 
182
  cout << "Initializing and starting " << PACKAGE << ".. " << flush;
 
183
 
 
184
 
 
185
  //Get the Glade-instantiated window:
 
186
  MainWindow* pWindow = 0;
 
187
  refXml->get_widget_derived("window1", pWindow);
 
188
  if(pWindow)
 
189
  {
 
190
    pWindow->init(pConfig,
 
191
                  configfile,
 
192
                  VERSION,
 
193
                  string(ICONDIR) + string("/gnome-color-chooser.svg"),
 
194
                  configpath_images,
 
195
                  globalpath_engines,
 
196
                  globalpath_profiles);
 
197
                  
 
198
    cout << "done" << endl;
 
199
 
 
200
    kit.run(*pWindow);
 
201
  }
 
202
 
 
203
  delete pWindow;
 
204
  delete pConfig;
 
205
 
 
206
  return 0;
 
207
}
 
208
 
 
209
#else
 
210
int main(void) {
 
211
    cerr << "Tree support of libxml2 not compiled in\n";
 
212
    exit(1);
 
213
}
 
214
#endif
 
215