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
|
#include <iostream>
#include <gtk/gtkstock.h>
#include <gtk/gtkradioaction.h>
#include <gtk/gtkcheckmenuitem.h>
#include <gtk/gtkfilechooser.h>
#include <gtk/gtkfilechooserdialog.h>
#include <gtk/gtkimage.h>
#include <gtk/gtkdialog.h>
#include <gtk/gtkmain.h>
#include "pp_mainwindow.h"
#include "dialogs.h"
#include "support/generaldialogs.h"
#include "support/progressbar.h"
#include "support/pathsupport.h"
#include "support/layoutrectangle.h" // For rotation enums
//#include "effects/effects_dialog.h"
#include "pixbufthumbnail/egg-pixbuf-thumbnail.h"
#include "pp_menu_image.h"
#include "config.h"
#include "gettext.h"
#define _(x) gettext(x)
#define N_(x) gettext_noop(x)
using namespace std;
// Preview widget for file chooser
static void updatepreview(GtkWidget *fc,void *ud)
{
GtkWidget *preview=GTK_WIDGET(ud);
gchar *fn=gtk_file_chooser_get_preview_filename(GTK_FILE_CHOOSER(fc));
bool active=false;
if(fn)
{
GError *err=NULL;
GdkPixbuf *pb=egg_pixbuf_get_thumbnail_for_file(fn,EGG_PIXBUF_THUMBNAIL_NORMAL,&err);
if(pb)
{
gtk_image_set_from_pixbuf(GTK_IMAGE(preview),pb);
g_object_unref(pb);
active=true;
}
}
gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(fc),active);
}
static void imagemenu_addimage(GtkAction *act,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
PhotoPrint_State *state=mw->state;
GtkWidget *sel;
sel = gtk_file_chooser_dialog_new (_("Open File"),
GTK_WINDOW(GTK_WINDOW(&mw->window)),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(sel),TRUE);
if(mw->prevfile)
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(sel),mw->prevfile);
else
{
#ifdef WIN32
char *dirname=substitute_homedir("$HOME\\My Documents\\My Pictures");
#else
char *dirname=substitute_homedir("$HOME");
#endif
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(sel),dirname);
}
g_free(mw->prevfile);
mw->prevfile=NULL;
GtkWidget *preview=gtk_image_new();
gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(sel),GTK_WIDGET(preview));
g_signal_connect(G_OBJECT(sel),"selection-changed",G_CALLBACK(updatepreview),preview);
if (gtk_dialog_run (GTK_DIALOG (sel)) == GTK_RESPONSE_ACCEPT)
{
GSList *filenames=gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(sel));
GSList *current=filenames;
if(filenames)
{
int count=0;
while(current)
{
++count;
current=g_slist_next(current);
}
ProgressBar progress(_("Adding images..."),true,GTK_WIDGET(mw));
current=filenames;
int i=0;
int lastpage=0;
while(current)
{
char *fn=(char *)current->data;
// pp_Menu *menu=PP_MENU(mw->menu);
lastpage=state->layout->AddImage(fn,ImageMenu_GetCropFlag(mw->uim),ImageMenu_GetRotation(mw->uim));
if(!(progress.DoProgress(i,count)))
break;
++i;
current=g_slist_next(current);
if(!current)
mw->prevfile=g_strdup(fn);
g_free(fn);
}
state->layout->SetCurrentPage(lastpage);
g_slist_free(filenames);
}
}
gtk_widget_destroy (sel);
pp_mainwindow_refresh(mw);
}
static void imagemenu_remove(GtkAction *act,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
Layout_ImageInfo *ii=mw->state->layout->FirstSelected();
while(ii)
{
delete ii;
ii=mw->state->layout->FirstSelected();
}
mw->state->layout->Reflow();
pp_mainwindow_refresh(mw);
}
static void imagemenu_duplicate(GtkAction *act,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
Layout_ImageInfo *ii=mw->state->layout->FirstSelected();
while(ii)
{
mw->state->layout->CopyImage(ii);
ii=mw->state->layout->NextSelected();
}
pp_mainwindow_refresh(mw);
}
static void imagemenu_duplicatetofillpage(GtkAction *act,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
int s=mw->state->layout->CountSelected();
if(s)
{
int c=mw->state->layout->FreeSlots();
if(c)
{
for(int i=0;i<c;)
{
Layout_ImageInfo *ii=mw->state->layout->FirstSelected();
while(ii && i<c)
{
mw->state->layout->CopyImage(ii);
ii=mw->state->layout->NextSelected();
++i;
}
}
}
else
ErrorMessage_Dialog(_("Page is already full!"),GTK_WIDGET(mw));
}
pp_mainwindow_refresh(mw);
}
static void imagemenu_allowcropping(GtkToggleAction *act,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
bool checked=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(act));
Layout_ImageInfo *ii=mw->state->layout->FirstSelected();
if(!ii)
mw->state->layoutdb.SetInt("AllowCropping",checked);
while(ii)
{
ii->ObtainMutexShared();
if(ii->allowcropping!=checked)
{
ii->ObtainMutex();
ii->allowcropping=checked;
ii->ReleaseMutex();
}
ii->ReleaseMutex();
ii=mw->state->layout->NextSelected();
}
pp_mainwindow_refresh(mw);
}
static void imagemenu_setmask(GtkAction *act,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
static char *prevfile=NULL;
// FIXME: Need to get existing filename...
char *mask=ImageMask_Dialog(&mw->window,*mw->state,prevfile);
if(mask)
cerr << "Selected " << mask << endl;
Layout_ImageInfo *ii=mw->state->layout->FirstSelected();
while(ii)
{
ii->ObtainMutex();
ii->SetMask(mask);
ii->ReleaseMutex();
ii=mw->state->layout->NextSelected();
}
// if(prevfile)
// free(prevfile);
prevfile=mask;
pp_mainwindow_refresh(mw);
}
static void imagemenu_setcolourprofile(GtkAction *act,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
Layout_ImageInfo *ii=mw->state->layout->FirstSelected();
ii->ObtainMutex();
SetCustomProfileDialog(&mw->window,*mw->state,ii);
ii->ReleaseMutex();
pp_mainwindow_refresh(mw);
}
static void imagemenu_radio_dispatch(GtkAction *act,GtkRadioAction *ra,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
enum PP_ROTATION rotation=PP_ROTATION(gtk_radio_action_get_current_value(ra));
Layout_ImageInfo *ii=mw->state->layout->FirstSelected();
if(!ii)
mw->state->layoutdb.SetInt("Rotation",rotation);
while(ii)
{
ii->ObtainMutexShared();
if(ii->rotation!=rotation)
{
ii->ObtainMutex();
ii->rotation=rotation;
ii->ReleaseMutex();
}
ii->ReleaseMutex();
ii=mw->state->layout->NextSelected();
}
pp_mainwindow_refresh(mw);
}
static GtkActionEntry imagemenu_entries[] = {
{ "ImageMenu", NULL, N_("_Image") },
{ "AddImage", NULL, N_("_Add Image..."), "<control>I", N_("Add images to the current layout"), G_CALLBACK(imagemenu_addimage) },
{ "RemoveImage", NULL, N_("_Remove Image"), NULL, N_("Remove selected images from the layout"), G_CALLBACK(imagemenu_remove) },
{ "DuplicateImage", NULL, N_("_Duplicate Image"), NULL, N_("Duplicate the currently selected image"), G_CALLBACK(imagemenu_duplicate) },
{ "DuplicateToFillPage", NULL, N_("_Duplicate to Fill Page"), NULL, N_("Fill the page with copies of the currently selected image"), G_CALLBACK(imagemenu_duplicatetofillpage) },
{ "Rotation", NULL, N_("_Rotation") },
{ "SetImageMask", NULL, N_("Set Image _Mask..."), NULL, N_("Set a border mask for the selected image"), G_CALLBACK(imagemenu_setmask) },
// { "Effects", NULL, N_("_Effects..."), NULL, N_("Apply effects to the selected image"), G_CALLBACK(imagemenu_seteffects) },
{ "SetColourProfile", NULL, N_("Set Colour _Profile..."), NULL, N_("Assign an ICC profile or custom rendering intent to the image"), G_CALLBACK(imagemenu_setcolourprofile) },
};
static GtkToggleActionEntry imagemenu_toggle_entries[] = {
{ "AllowCropping", NULL, N_("Allow _Cropping"), NULL, N_("Crop the selected images to fill the available space"), G_CALLBACK(imagemenu_allowcropping), FALSE }
};
static GtkRadioActionEntry imagemenu_radio_entries[] = {
{ "RotationAuto", NULL, N_("_Auto"), NULL, N_("Automatically choose rotation to fit the available space."), PP_ROTATION_AUTO },
{ "RotationNone", NULL, N_("_None"), NULL, N_("No rotation."), PP_ROTATION_NONE },
{ "Rotation90", NULL, N_("_90 Degrees"), NULL, N_("Rotate 90 degrees clockwise."), PP_ROTATION_90 },
{ "Rotation180", NULL, N_("_180 Degrees"), NULL, N_("Rotate 180 degrees."), PP_ROTATION_180 },
{ "Rotation270", NULL, N_("_270 Degrees"), NULL, N_("Rotate 90 degrees anticlockwise."), PP_ROTATION_270 }
};
static const char *imagemenu_ui_description =
"<ui>"
" <menubar name='MainMenu'>"
" <menu action='ImageMenu'>"
" <menuitem action='AddImage'/>"
" <menuitem action='RemoveImage'/>"
" <menuitem action='DuplicateImage'/>"
" <menuitem action='DuplicateToFillPage'/>"
" <separator/>"
" <menuitem action='AllowCropping'/>"
" <menu action='Rotation'>"
" <menuitem action='RotationAuto'/>"
" <menuitem action='RotationNone'/>"
" <menuitem action='Rotation90'/>"
" <menuitem action='Rotation180'/>"
" <menuitem action='Rotation270'/>"
" </menu>"
" <menuitem action='SetImageMask'/>"
//" <menuitem action='Effects'/>"
" <menuitem action='SetColourProfile'/>"
" </menu>"
" </menubar>"
" <popup>"
" <menuitem action='AddImage'/>"
" <menuitem action='RemoveImage'/>"
" <menuitem action='DuplicateImage'/>"
" <menuitem action='DuplicateToFillPage'/>"
" <separator/>"
" <menuitem action='AllowCropping'/>"
" <menu action='Rotation'>"
" <menuitem action='RotationAuto'/>"
" <menuitem action='RotationNone'/>"
" <menuitem action='Rotation90'/>"
" <menuitem action='Rotation180'/>"
" <menuitem action='Rotation270'/>"
" </menu>"
" <menuitem action='SetImageMask'/>"
//" <menuitem action='Effects'/>"
" <menuitem action='SetColourProfile'/>"
" </popup>"
"</ui>";
void BuildImageMenu(void *userdata,GtkUIManager *ui_manager)
{
GError *error=NULL;
GtkActionGroup *action_group;
action_group = gtk_action_group_new ("ImageMenuActions");
gtk_action_group_set_translation_domain(action_group,PACKAGE);
gtk_action_group_add_actions (action_group, imagemenu_entries, G_N_ELEMENTS (imagemenu_entries), userdata);
gtk_action_group_add_toggle_actions (action_group, imagemenu_toggle_entries, G_N_ELEMENTS (imagemenu_toggle_entries), userdata);
gtk_action_group_add_radio_actions (action_group, imagemenu_radio_entries, G_N_ELEMENTS (imagemenu_radio_entries), 0, G_CALLBACK(imagemenu_radio_dispatch), userdata);
gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
if (!gtk_ui_manager_add_ui_from_string (ui_manager, imagemenu_ui_description, -1, &error))
throw error->message;
pp_MainWindow *mw=(pp_MainWindow *)userdata;
bool allowcropping=mw->state->layoutdb.FindInt("AllowCropping");
enum PP_ROTATION rotation=PP_ROTATION(mw->state->layoutdb.FindInt("Rotation"));
ImageMenu_SetCropFlag(ui_manager,allowcropping);
ImageMenu_SetRotation(ui_manager,rotation);
}
bool ImageMenu_GetCropFlag(GtkUIManager *ui_manager)
{
bool result=false;
GtkAction *act=gtk_ui_manager_get_action(ui_manager,"/MainMenu/ImageMenu/AllowCropping");
if(act)
result=gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(act));
return(result);
}
void ImageMenu_SetCropFlag(GtkUIManager *ui_manager,bool active)
{
GtkAction *act=gtk_ui_manager_get_action(ui_manager,"/MainMenu/ImageMenu/AllowCropping");
if(act)
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act),active);
}
enum PP_ROTATION ImageMenu_GetRotation(GtkUIManager *ui_manager)
{
enum PP_ROTATION result=PP_ROTATION_AUTO;
GtkAction *act=gtk_ui_manager_get_action(ui_manager,"/MainMenu/ImageMenu/Rotation/RotationAuto");
if(act)
result=PP_ROTATION(gtk_radio_action_get_current_value(GTK_RADIO_ACTION(act)));
return(result);
}
void ImageMenu_SetRotation(GtkUIManager *ui_manager,enum PP_ROTATION rotation)
{
#if 0
GtkAction *act=gtk_ui_manager_get_action(ui_manager,"/MainMenu/ImageMenu/Rotation/RotationAuto");
if(act)
gtk_radio_action_set_current_value(GTK_RADIO_ACTION(act),rotation);
#else
const char *menupaths[]=
{
"/MainMenu/ImageMenu/Rotation/RotationAuto",
"/MainMenu/ImageMenu/Rotation/RotationNone",
"/MainMenu/ImageMenu/Rotation/Rotation90",
"/MainMenu/ImageMenu/Rotation/Rotation180",
"/MainMenu/ImageMenu/Rotation/Rotation270"
};
GtkWidget *w;
for(unsigned int i=0;i<(sizeof(menupaths)/sizeof(const char *));++i)
{
w=gtk_ui_manager_get_widget(ui_manager,menupaths[i]);
if(w)
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w),PP_ROTATION(i)==rotation);
}
#endif
}
void ImageMenu_SetLayoutCapabilities(GtkUIManager *ui_manager,int features)
{
struct menucapentry
{
const char *path;
int flag;
};
menucapentry tags[]={
{"/MainMenu/ImageMenu/DuplicateToFillPage",PPLAYOUT_DUPLICATE},
{"/MainMenu/ImageMenu/AllowCropping",PPLAYOUT_CROP},
{"/MainMenu/ImageMenu/Rotation/RotationAuto",PPLAYOUT_ROTATE},
{"/MainMenu/ImageMenu/Rotation/RotationNone",PPLAYOUT_ROTATE},
{"/MainMenu/ImageMenu/Rotation/Rotation90",PPLAYOUT_ROTATE},
{"/MainMenu/ImageMenu/Rotation/Rotation180",PPLAYOUT_ROTATE},
{"/MainMenu/ImageMenu/Rotation/Rotation270",PPLAYOUT_ROTATE},
{"/MainMenu/ImageMenu/SetImageMask",PPLAYOUT_MASK},
{"/MainMenu/ImageMenu/SetEffects",PPLAYOUT_EFFECTS},
{"/MainMenu/ImageMenu/SetColourProfile",PPLAYOUT_PROFILE},
{"/popup/DuplicateToFillPage",PPLAYOUT_DUPLICATE},
{"/popup/AllowCropping",PPLAYOUT_CROP},
{"/popup/Rotation/RotationAuto",PPLAYOUT_ROTATE},
{"/popup/Rotation/RotationNone",PPLAYOUT_ROTATE},
{"/popup/Rotation/Rotation90",PPLAYOUT_ROTATE},
{"/popup/Rotation/Rotation180",PPLAYOUT_ROTATE},
{"/popup/Rotation/Rotation270",PPLAYOUT_ROTATE},
{"/popup/SetImageMask",PPLAYOUT_MASK},
// {"/popup/SetEffects",PPLAYOUT_EFFECTS},
{"/popup/SetColourProfile",PPLAYOUT_PROFILE},
{NULL,0}
};
menucapentry *p=&tags[0];
while(p->flag)
{
GtkWidget *w=gtk_ui_manager_get_widget(ui_manager,p->path);
if(w)
gtk_widget_set_sensitive(w,(features&p->flag)!=0);
++p;
}
}
void ImageMenu_DoPopup(GtkUIManager *ui_manager)
{
GtkWidget *menu=gtk_ui_manager_get_widget(ui_manager,"/popup");
gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,3,gtk_get_current_event_time());
}
|