1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
|
/* $Id: gallery.c,v 1.17 1999/07/03 20:17:09 scottf Exp $
*
* gPhoto - free digital camera utility - http://www.gphoto.org/
HTML Gallery Engine for generating a web gallery of your images
from within gPhoto. Can be used with any camera library, or even
with "browse directory" to create your html gallery...
Gallery tags:
GALLERY_NAME
GALLERY_INDEX
DATE
THUMBNAIL
THUMBNAIL_FILENAME
THUMBNAIL_NUMBER
PICTURE
PICTURE_FILENAME
PICTURE_NUMBER
PICTURE_NEXT
PICTURE_PREVIOUS
* Copyright (C) 1999 Scott Fritzinger <scottf@scs.unr.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Log: gallery.c,v $
* Revision 1.17 1999/07/03 20:17:09 scottf
* rehashed the confirmation of overwrite to be more modular.
* fixed small gallery bugs. this is a good release candidate.
*
* Revision 1.16 1999/07/02 19:53:29 scottf
* fixing saveselectedtodisk bug
*
* Revision 1.15 1999/07/01 22:26:22 scottf
* fixed up the html gallery dialog
* fixed up the live Camera dialog
*
* Revision 1.14 1999/07/01 20:02:05 scottf
* added several misc things
*
* Revision 1.13 1999/07/01 16:22:22 scottf
* renamed "struct ImageInfo" to "struct ImageMembers" to avoid confusion
* added "free_imagemembers(struct ImageMembers *im)" to util.c to centralize
* removing the image related widgets and images.
* initialized all the ImageMembers members to NULL
* fixed the core dump after retrieving 2 or 3 concurrent indexes.
*
* Revision 1.12 1999/06/30 00:13:16 scottf
* updated the "get blank index" icon to be a little more consistent
* added gtk_directory_selection_new() and related functions
* (possible new GTK widget?)
* updated priority to go back to min priority when execute_program is
* called
* other misc fixes.
*
* Revision 1.11 1999/06/29 19:51:02 scottf
* label rewording
* added check for "%s" in the post-process command-line
* fixed some gallery issues so that the $PWD is displayed in the label
* removed the ugly scrollbars in the directory file_selection boxes.
* other misc fixes as well. (good day! :)
*
* Revision 1.10 1999/06/29 01:55:36 scottf
* source code tidying. moved browse_ callbacks to callbacks.c but left
* url_send_browse in util (could be very handy).
* also removed some toolbar icons (plug-ins) just to try to remove a little
* clutter.
*
* Revision 1.9 1999/06/21 18:26:43 ole
* Removed deactivate_button(browse_button);
*
* Revision 1.8 1999/06/21 18:04:12 ole
* 1999-06-21 Ole Aamot <oleaa@ifi.uio.no>
*
* * callbacks.c: changed activate_button(..) a bit
* * developer_dialog.c: added a clickable webpage button. :o)
* * gallery.c: added browse_gallery();
* * main.c: added browse_gphoto();
* * menu.c: added menu-links to www.gphoto.org (loads in a BROWSER)
* * toolbar.c: added/changed icons (by tigert) for the plugins
* * util.c: added url_send_browser(..), and browse_* web routines.
*
* Revision 1.7 1999/06/19 15:32:57 ole
* Generated SUPPORTED from http://www.gphoto.org/cameras.php3
*
* Revision 1.6 1999/06/15 19:44:32 scottf
* various updates to headers and sources
* added constrain proportions to resize
*
* Revision 1.5 1999/06/15 16:05:04 scottf
* removed the #ifdef's for gtk < 1.2
* windows show in middle of screen now instead of random places :)
*
* Revision 1.4 1999/06/10 19:53:32 scottf
* Updated the functions wrappers to check for errors everywhere
* Updated the gallery to display an error if the thumbnails can't
* be saved.
* Updated so that now, the last directory you selected is the one
* "working directory" in most fileselection boxes
* (reduces mouse clicks :)
*
* Revision 1.3 1999/06/10 16:38:54 scottf
* Updated the callbacks.h file
* FIxed the gallery numbering bug (again)
* Little fixes here and there
*
* Revision 1.2 1999/06/08 19:08:10 scottf
* Fixed several gallery.c bugs, and improved it a bit.
* Added free_image and save_image to util.c
*
* Revision 1.1.1.1 1999/05/27 18:32:07 scottf
* gPhoto- digital camera utility
*
* Revision 1.11 1999/05/08 13:31:10 ole
* Changed paths from /usr/share/... to /usr/local/share/...
*
* Revision for Debian
*
* Changed paths from /usr/local/share to /usr/share
*
*/
#include "main.h"
#include "gphoto.h"
#include "util.h"
#include "callbacks.h"
#include "gallery.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/dir.h>
extern GtkWidget *index_window;
/* extern GtkWidget *browse_button; */
extern struct ImageMembers Thumbnails;
extern struct ImageMembers Images;
extern struct _Camera *Camera;
extern char *filesel_cwd;
/* initialize some tags */
char gallery_name[256];
char gallery_index[128];
char date[32];
char thumbnail[256];
char thumbnail_filename[128];
char thumbnail_number[5];
char picture[256];
char picture_filename[128];
char picture_number[5];
char picture_next[128];
char picture_previous[128];
void gallery_change_dir(GtkWidget *widget, GtkWidget *label) {
GtkWidget *filesel;
filesel = gtk_directory_selection_new("Select an Output Directory...");
gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_CENTER);
gtk_widget_show(filesel);
if (wait_for_hide(filesel,
GTK_FILE_SELECTION(filesel)->ok_button,
GTK_FILE_SELECTION(filesel)->cancel_button) == 0) {
return;
}
gtk_label_set(GTK_LABEL(label), strdup(
gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel))));
gtk_object_set_data(GTK_OBJECT(label), "dir", strdup(
gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel))));
sprintf(filesel_cwd, "%s", gtk_file_selection_get_filename(
GTK_FILE_SELECTION(filesel)));
gtk_widget_destroy(filesel);
}
void gallery_parse_tags(char *dest, char *source) {
/* Returns 0 if it could not create destination file.
* Returns 1 if everything went OK.
*/
char fname[1024];
sprintf(fname,
"sed 's/#GALLERY_NAME#/%s/; \
s/#GALLERY_INDEX#/%s/; \
s/#DATE#/%s/; \
s/#THUMBNAIL#/%s/; \
s/#THUMBNAIL_FILENAME#/%s/; \
s/#THUMBNAIL_NUMBER#/%s/; \
s/#PICTURE#/%s/; \
s/#PICTURE_FILENAME#/%s/; \
s/#PICTURE_NUMBER#/%s/; \
s/#PICTURE_NEXT#/%s/; \
s/#PICTURE_PREVIOUS#/%s/;' %s >> %s",
gallery_name, gallery_index, date, thumbnail, thumbnail_filename,
thumbnail_number, picture, picture_filename, picture_number,
picture_next, picture_previous, source, dest);
system(fname);
}
void gallery_main() {
DIR *dir, *testdir;
struct dirent *file;
time_t loctime;
int i=0, j=0, num_selected = 0;
char outputdir[1024], theme[32];
char filename[1024], filename2[1024], cp[1024], error[32], statmsg[128];
struct Image *im;
GList *dlist;
GtkWidget *dialog, *list, *list_item, *scrwin, *obutton, *cbutton;
GtkWidget *netscape;
GtkWidget *galentry;
GtkWidget *label, *dirlabel, *dirbutton, *hbox, *hseparator;
struct ImageMembers *node = &Thumbnails;
if (Thumbnails.next == NULL) {
error_dialog(
"Please retrieve the index first,
and select the images to include
in the gallery by clicking on them.
Then, re-run the HTML Gallery.");
return;
}
/* Create the file selection to change directory */
i = 0;
while (node->next != NULL) {
node = node->next;
if (GTK_TOGGLE_BUTTON(node->button)->active)
num_selected++;
}
if (num_selected == 0) {
error_dialog(
"You need to select images to add\nto the gallery.");
return;
}
dialog = gtk_dialog_new();
gtk_container_border_width(GTK_CONTAINER(dialog), 5);
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
hbox = gtk_hbox_new(FALSE, 5);
gtk_widget_show(hbox);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox,
FALSE, FALSE, 0);
label = gtk_label_new("Gallery Name:");
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
galentry = gtk_entry_new();
gtk_widget_show(galentry);
gtk_box_pack_start_defaults(GTK_BOX(hbox), galentry);
hseparator = gtk_hseparator_new();
gtk_widget_show(hseparator);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hseparator,
FALSE, FALSE, 0);
label = gtk_label_new("Theme:");
gtk_widget_show(label);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label,
FALSE, FALSE, 0);
list = gtk_list_new();
gtk_widget_show(list);
gtk_list_set_selection_mode (GTK_LIST(list),GTK_SELECTION_SINGLE);
dir = opendir("/usr/share/gphoto/gallery");
if (dir == NULL) {
error_dialog(
"HTML gallery themes do not exist at
/usr/share/gphoto/gallery
Please install/move gallery themes there.");
return;
}
file = readdir(dir);
while (file != NULL) {
sprintf(filename, "/usr/share/gphoto/gallery/%s",
file->d_name);
testdir = opendir(filename);
if ((strcmp(file->d_name, ".") != 0) &&
(strcmp(file->d_name, "..") != 0) &&
(testdir != NULL)) {
closedir(testdir);
list_item = gtk_list_item_new_with_label(file->d_name);
gtk_widget_show(list_item);
gtk_container_add(GTK_CONTAINER(list), list_item);
gtk_object_set_data(GTK_OBJECT(list_item),"theme",
file->d_name);
}
file = readdir(dir);
}
hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_show(hbox);
gtk_widget_set_usize(hbox, 400, 200);
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),hbox);
scrwin = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_show(scrwin);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrwin), list);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(index_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start_defaults(GTK_BOX(hbox),scrwin);
hseparator = gtk_hseparator_new();
gtk_widget_show(hseparator);
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hseparator);
hbox = gtk_hbox_new(FALSE, 5);
gtk_widget_show(hbox);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox,
FALSE, FALSE, 0);
label = gtk_label_new("Output Directory:");
gtk_widget_show(label);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
dirlabel = gtk_label_new(filesel_cwd);
gtk_widget_show(dirlabel);
gtk_label_set_justify(GTK_LABEL(dirlabel), GTK_JUSTIFY_LEFT);
gtk_box_pack_start_defaults(GTK_BOX(hbox), dirlabel);
gtk_object_set_data(GTK_OBJECT(dirlabel), "dir", filesel_cwd);
dirbutton = gtk_button_new_with_label("Change...");
gtk_widget_show(dirbutton);
gtk_signal_connect(GTK_OBJECT(dirbutton), "clicked",
GTK_SIGNAL_FUNC(gallery_change_dir),dirlabel);
gtk_box_pack_end(GTK_BOX(hbox), dirbutton, FALSE, FALSE, 0);
netscape = gtk_check_button_new_with_label(
"View in \"netscape\" when finished");
gtk_widget_show(netscape);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), netscape, FALSE, FALSE,0);
obutton = gtk_button_new_with_label("Create");
gtk_widget_show(obutton);
GTK_WIDGET_SET_FLAGS (obutton, GTK_CAN_DEFAULT);
gtk_box_pack_start_defaults(
GTK_BOX(GTK_DIALOG(dialog)->action_area), obutton);
cbutton = gtk_button_new_with_label("Cancel");
gtk_widget_show(cbutton);
GTK_WIDGET_SET_FLAGS (cbutton, GTK_CAN_DEFAULT);
gtk_box_pack_start_defaults(
GTK_BOX(GTK_DIALOG(dialog)->action_area), cbutton);
gtk_widget_show(dialog);
gtk_widget_grab_default(obutton);
/* wait until the dialog is closed */
if (wait_for_hide(dialog, obutton, cbutton) == 0) {
if (GTK_IS_OBJECT(dialog))
gtk_widget_destroy(dialog);
return;
}
dlist = GTK_LIST(list)->selection;
if (!dlist) {
error_dialog("You must select a theme!");
if (GTK_IS_OBJECT(dialog))
gtk_widget_destroy(dialog);
return;
}
strcpy(cp, "");
sprintf(theme, "%s",(char*)gtk_object_get_data(GTK_OBJECT(dlist->data),
"theme"));
sprintf(gallery_name,"%s",
gtk_entry_get_text(GTK_ENTRY(galentry)));
strcpy(gallery_index, "index.html");
loctime = time(&loctime);
sprintf(date, "%s", ctime(&loctime));
date[24] = '\0';
sprintf(outputdir,"%s",
(char*)gtk_object_get_data(GTK_OBJECT(dirlabel),"dir"));
sprintf(filename, "/usr/share/gphoto/gallery/%s",
theme);
dir = opendir(filename);
file = readdir(dir);
while (file != NULL) {
if ((strcmp(file->d_name, "index_top.html") != 0 ) &&
(strcmp(file->d_name, "index_bottom.html") != 0 ) &&
(strcmp(file->d_name, "picture.html") != 0 ) &&
(strcmp(file->d_name, "thumbnail.html") != 0 ) &&
(strcmp(file->d_name, ".") != 0 ) &&
(strcmp(file->d_name, "..") != 0 )) {
sprintf(filename2, "%s%s", outputdir, file->d_name);
if (confirm_overwrite(filename2)) {
sprintf(cp, "cp %s/%s %s", filename, file->d_name,
outputdir);
system(cp);
}
}
file = readdir(dir);
}
closedir(dir);
sprintf(filename, "%sindex.html", outputdir);
if (!confirm_overwrite(filename)) {
if (GTK_IS_OBJECT(dialog))
gtk_widget_destroy(dialog);
return;
}
sprintf(cp, "echo \" \" > %s", filename);
system(cp);
sprintf(filename2,
"/usr/share/gphoto/gallery/%s/index_top.html",
theme);
gallery_parse_tags(filename, filename2);
sprintf(cp, "echo \"<table border=1><tr>\" >> %s", filename);
system(cp);
node = &Thumbnails;
while (node->next != NULL) {
node = node->next;
sprintf(filename, "%sindex.html", outputdir);
if (GTK_TOGGLE_BUTTON(node->button)->active) {
if ((i%5==0) && (i!=0)) {
sprintf(cp, "echo \"</tr><tr>\" >> %s",
filename);
system(cp);
}
/* Get the current thumbnail */
sprintf(cp, "Getting Thumbnail #%i...", j+1);
update_status(cp);
if ((im = (*Camera->get_picture)(j+1, 1))==0) {
sprintf(error, "Could not retrieve #%i",
j+1);
error_dialog(error);
sprintf(thumbnail, "Not Available");
sprintf(thumbnail_filename, "");
sprintf(thumbnail_number, "%03i", i+1);
} else {
sprintf(thumbnail,
"<a href=\"picture-%03i.html\"><img src=\"thumbnail-%03i.%s\"><\\/a>",
i+1, i+1, im->image_type);
sprintf(thumbnail_filename, "thumbnail-%03i.%s",
i+1, im->image_type);
sprintf(thumbnail_number, "%03i", i+1);
sprintf(filename2, "%s%s", outputdir,
thumbnail_filename);
if (!confirm_overwrite(filename2)) {
if (GTK_IS_OBJECT(dialog))
gtk_widget_destroy(dialog);
return;
}
save_image(filename2, im);
free_image(im);
}
/* Get the current image */
sprintf(cp, "Getting Image #%i...", j+1);
update_status(cp);
if ((im = (*Camera->get_picture)(j+1, 0))==0) {
sprintf(error, "Could not retrieve #%i", j+1);
error_dialog(error);
sprintf(picture, "Not Available");
sprintf(picture_filename, "");
sprintf(picture_number, "%03i", i+1);}
else {
sprintf(picture, "<img src=\"picture-%03i.%s\">",
i+1, im->image_type);
sprintf(picture_filename, "picture-%03i.%s",
i+1, im->image_type);
sprintf(picture_number, "%03i", i+1);
sprintf(filename2, "%s%s", outputdir,
picture_filename);
if (!confirm_overwrite(filename2)) {
if (GTK_IS_OBJECT(dialog))
gtk_widget_destroy(dialog);
return;
}
save_image(filename2, im);
free_image(im);
}
if (i+1 == num_selected)
strcpy(picture_next, gallery_index);
else
sprintf(picture_next, "picture-%03i.html",
i+2);
if (i == 0)
strcpy(picture_previous, gallery_index);
else
sprintf(picture_previous, "picture-%03i.html",
i);
sprintf(cp, "echo \"<td>\" >> %s", filename);
system(cp);
sprintf(filename2,
"/usr/share/gphoto/gallery/%s/thumbnail.html",
theme);
gallery_parse_tags(filename, filename2);
sprintf(cp, "echo \"</td>\" >> %s", filename);
system(cp);
sprintf(filename, "%spicture-%03i.html",
outputdir, i+1);
if (!confirm_overwrite(filename)) {
if (GTK_IS_OBJECT(dialog))
gtk_widget_destroy(dialog);
return;
}
sprintf(cp, "echo \" \" > %s", filename);
system(cp);
sprintf(filename2,
"/usr/share/gphoto/gallery/%s/picture.html",
theme);
gallery_parse_tags(filename, filename2);
i++;
}
j++;
}
sprintf(filename, "%sindex.html", outputdir);
sprintf(cp, "echo \"</tr></table>\" >> %s", filename);
system(cp);
sprintf(filename2,
"/usr/share/gphoto/gallery/%s/index_bottom.html",
theme);
gallery_parse_tags(filename, filename2);
if (GTK_TOGGLE_BUTTON(netscape)->active) {
sprintf(statmsg, "Loaded file:%sindex.html in %s", filesel_cwd, BROWSER);
browse_gallery();}
else {
sprintf(statmsg, "Gallery saved in: %s", outputdir);
}
if (GTK_IS_OBJECT(dialog))
gtk_widget_destroy(dialog);
update_status(statmsg);
}
|