1
// Copyright (C) 2006-2007 W. Pantke <gnome-color-chooser@punk-ass-bitch.org>
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.
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.
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.
22
#include <libgnome/gnome-i18n.h>
26
#include "treehandler.h"
27
#include "configloader.h"
29
#include "mainwindow.h"
30
#include "gtpexporter.h"
35
#include <sys/types.h>
42
using namespace GnomeCC;
45
#ifdef LIBXML_TREE_ENABLED
47
bool config_ok(string configfile, string dbfile, string gtkrcfile)
50
if(! (Utils::Io::check_file(gtkrcfile, true)
51
|| Utils::Io::create_file(gtkrcfile)) )
53
cerr << "cannot create/open file " << gtkrcfile << endl;
58
if(!Utils::create_include(
60
"include \".gtkrc-2.0-gnome-color-chooser\"",
61
".gtkrc-2.0-gnome-color-chooser"))
63
if(!Utils::check_include(
65
"include \".gtkrc-2.0-gnome-color-chooser\"",
66
".gtkrc-2.0-gnome-color-chooser"))
68
cerr << "unable to modify ~/.gtkrc-2.0" << endl;
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")))
79
cerr << "cannot create/open file "
81
<< string("/.gtkrc-2.0-gnome-color-chooser")
87
if(Utils::Io::check_file(configfile)
88
&& !Utils::Io::check_file(configfile, true))
90
cerr << "cannot write to config file " << configfile << endl;
95
if(!Utils::Io::check_file(dbfile))
97
cerr << "cannot open gnomecc database " << dbfile << endl;
109
int main (int argc, char *argv[])
113
setlocale(LC_ALL,"");
114
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
115
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
116
textdomain(GETTEXT_PACKAGE);
119
GnomeProgram *program;
120
program = gnome_program_init
124
// GNOME_PARAM_POPT_TABLE, cmd_options_table,
125
GNOME_PARAM_APP_DATADIR, DATADIR,
129
Gtk::Main kit(argc, argv);
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();
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;
148
if(mkdir(configpath.c_str(), (mode_t)00700) != -1)
150
if(mkdir(configpath_images.c_str(), (mode_t)00755) == -1)
152
perror(configpath_images.c_str());
158
if(!config_ok(configfile, dbfile, gtkrcfile))
162
// config has to be loaded before the glade file
163
TreeHandler* pConfig = new TreeHandler((char*)dbfile.c_str());
164
Exporter::init(pConfig);
168
// load Glade file and instantiate its widgets
169
Glib::RefPtr<Gnome::Glade::Xml> refXml;
172
cout << "Loading GUI with libglade.. " << flush;
173
refXml = Gnome::Glade::Xml::create(string(GLADEDIR) + string("/gnome-color-chooser.glade"));
175
catch(const Gnome::Glade::XmlError& ex)
177
cerr << endl << ex.what() << endl;
181
cout << "done" << endl;
182
cout << "Initializing and starting " << PACKAGE << ".. " << flush;
185
//Get the Glade-instantiated window:
186
MainWindow* pWindow = 0;
187
refXml->get_widget_derived("window1", pWindow);
190
pWindow->init(pConfig,
193
string(ICONDIR) + string("/gnome-color-chooser.svg"),
196
globalpath_profiles);
198
cout << "done" << endl;
211
cerr << "Tree support of libxml2 not compiled in\n";