2
* This file is part of the apvlv package
4
* Copyright (C) 2008 Alf.
6
* Contact: Alf <naihe2010@gmail.com>
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public License
10
* as published by the Free Software Foundation; either version 2.0 of
11
* the License, or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public
19
* License along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
/* @CFILE ApvlvUtil.cpp
25
* Author: Alf <naihe2010@gmail.com>
27
/* @date Created: 2008/09/30 00:00:00 Alf */
29
#include "ApvlvUtil.hpp"
48
string helppdf = "~\\Startup.pdf";
49
string iniexam = "~\\apvlvrc.example";
50
string iconreg = "~\\reg.png";
51
string icondir = "~\\dir.png";
52
string iconpdf = "~\\pdf.png";
53
string inifile = "~\\_apvlvrc";
54
string sessionfile = "~\\_apvlvinfo";
56
string helppdf = string (DOCDIR) + "/Startup.pdf";
57
string iniexam = string (DOCDIR) + "/apvlvrc.example";
58
string iconreg = string (DOCDIR) + "/reg.png";
59
string icondir = string (DOCDIR) + "/dir.png";
60
string iconpdf = string (DOCDIR) + "/pdf.png";
61
string inifile = "~/.apvlvrc";
62
string sessionfile = "~/.apvlvinfo";
65
// Converts the path given to a absolute path.
66
// Warning: The string is returned a new allocated buffer, NEED TO BE g_free
68
absolutepath (const char *path)
73
char abpath[PATH_MAX];
76
if (g_path_is_absolute (path))
78
return g_strdup (path);
84
gchar *home = g_win32_get_package_installation_directory_of_module (NULL);
86
char *home = getenv ("HOME");
88
g_snprintf (abpath, sizeof abpath, "%s%s",
95
GetCurrentDirectoryA (sizeof abpath, abpath);
96
strcat (abpath, "\\");
97
strcat (abpath, path);
99
realpath (path, abpath);
103
return g_strdup (abpath);
108
filecpy (const char *dst, const char *src)
111
gchar *s = absolutepath (src);
112
gchar *d = absolutepath (dst);
115
gboolean ret = g_file_get_contents (s, &content, NULL, NULL);
118
ret = g_file_set_contents (d, content, -1, NULL);
129
// replace a widget with a new widget
130
// return the parent widget
132
replace_widget (GtkWidget *owid, GtkWidget *nwid)
134
GtkWidget *parent = gtk_widget_get_parent (owid);
135
debug ("parent: %p, owid: %p, nwid: %p", parent, owid, nwid);
136
gtk_container_remove (GTK_CONTAINER (parent), owid);
137
gtk_container_add (GTK_CONTAINER (parent), nwid);
138
gtk_widget_show_all (parent);
142
// get a PopplerDocument from a given file
143
// return the pointer
145
file_to_popplerdoc (const char *filename)
147
static gchar *mRawdata = NULL;
148
static guint mRawdatasize = 0;
153
|| g_file_test (filename, G_FILE_TEST_IS_REGULAR) == FALSE
154
|| (wfilename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL)) == NULL
157
errp ("filename error: %s", filename? filename: "No name");
163
int rt = stat (wfilename, &sbuf);
166
errp ("Can't stat the PDF file: %s.", filename);
169
filelen = sbuf.st_size;
172
&& mRawdatasize < filelen)
178
if (mRawdata == NULL)
180
mRawdata = new char[filelen];
181
mRawdatasize = filelen;
184
ifstream ifs (wfilename, ios::binary);
187
ifs.read (mRawdata, filelen);
193
PopplerDocument *doc = poppler_document_new_from_data (mRawdata, filelen, NULL, NULL);
196
// && POPPLER_ERROR == POPPLER_ERROR_ENCRYPTED) /* fix this later */
200
gtk_message_dialog_new (NULL,
201
GTK_DIALOG_DESTROY_WITH_PARENT,
202
GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL,
203
"Maybe this PDF file is encrypted, please input a password:");
205
GtkWidget *entry = gtk_entry_new ();
206
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dia)->vbox), entry, TRUE, TRUE, 10);
207
gtk_widget_show (entry);
209
int ret = gtk_dialog_run (GTK_DIALOG (dia));
210
if (ret == GTK_RESPONSE_OK)
212
gchar *ans = (gchar *) gtk_entry_get_text (GTK_ENTRY (entry));
215
doc = poppler_document_new_from_data (mRawdata, filelen, ans, NULL);
219
gtk_widget_destroy (dia);
226
logv (const char *level, const char *file, int line, const char *func, const char *ms, ...)
228
char p[0x1000], temp[0x100];
231
g_snprintf (temp, sizeof temp, "[%s] %s: %d: %s(): ",
232
level, file, line, func);
235
vsnprintf (p, sizeof p, ms, vap);
238
cerr << temp << p << endl;