~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to utilities/imageeditor/editor/editorwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
144
144
 
145
145
const QString EditorWindow::CONFIG_GROUP_NAME = "ImageViewer Settings";
146
146
 
147
 
EditorWindow::EditorWindow(const char *name)
148
 
            : KXmlGuiWindow(0), d(new EditorWindowPriv)
 
147
EditorWindow::EditorWindow(const char* name)
 
148
    : KXmlGuiWindow(0), d(new EditorWindowPriv)
149
149
{
150
150
    setObjectName(name);
151
151
    setWindowFlags(Qt::Window);
216
216
void EditorWindow::setupContextMenu()
217
217
{
218
218
    m_contextMenu         = new DPopupMenu(this);
219
 
    KActionCollection *ac = actionCollection();
 
219
    KActionCollection* ac = actionCollection();
 
220
 
220
221
    if (ac->action("editorwindow_backward"))
 
222
    {
221
223
        m_contextMenu->addAction(ac->action("editorwindow_backward"));
 
224
    }
 
225
 
222
226
    if (ac->action("editorwindow_forward"))
 
227
    {
223
228
        m_contextMenu->addAction(ac->action("editorwindow_forward"));
 
229
    }
 
230
 
224
231
    m_contextMenu->addSeparator();
 
232
 
225
233
    if (ac->action("editorwindow_slideshow"))
 
234
    {
226
235
        m_contextMenu->addAction(ac->action("editorwindow_slideshow"));
 
236
    }
 
237
 
227
238
    if (ac->action("editorwindow_rotate_left"))
 
239
    {
228
240
        m_contextMenu->addAction(ac->action("editorwindow_rotate_left"));
 
241
    }
 
242
 
229
243
    if (ac->action("editorwindow_rotate_right"))
 
244
    {
230
245
        m_contextMenu->addAction(ac->action("editorwindow_rotate_right"));
 
246
    }
 
247
 
231
248
    if (ac->action("editorwindow_crop"))
 
249
    {
232
250
        m_contextMenu->addAction(ac->action("editorwindow_crop"));
 
251
    }
 
252
 
233
253
    m_contextMenu->addSeparator();
 
254
 
234
255
    if (ac->action("editorwindow_delete"))
 
256
    {
235
257
        m_contextMenu->addAction(ac->action("editorwindow_delete"));
 
258
    }
236
259
}
237
260
 
238
261
void EditorWindow::setupStandardConnections()
444
467
    actionCollection()->addAction("editorwindow_zoomfit2select", d->zoomFitToSelectAction);
445
468
    d->zoomFitToSelectAction->setEnabled(false);
446
469
    d->zoomFitToSelectAction->setWhatsThis(i18n("This option can be used to zoom the image to the "
447
 
                                                "current selection area."));
 
470
                                           "current selection area."));
448
471
 
449
472
    // --------------------------------------------------------
450
473
 
459
482
    d->viewUnderExpoAction = new KToggleAction(KIcon("underexposure"), i18n("Under-Exposure Indicator"), this);
460
483
    d->viewUnderExpoAction->setShortcut(KShortcut(Qt::Key_F10));
461
484
    d->viewUnderExpoAction->setWhatsThis(i18n("Set this option to display black "
462
 
                                              "overlaid on the image. This will help you to avoid "
463
 
                                              "under-exposing the image."));
 
485
                                         "overlaid on the image. This will help you to avoid "
 
486
                                         "under-exposing the image."));
464
487
    connect(d->viewUnderExpoAction, SIGNAL(triggered(bool)), this, SLOT(slotSetUnderExposureIndicator(bool)));
465
488
    actionCollection()->addAction("editorwindow_underexposure", d->viewUnderExpoAction);
466
489
 
467
490
    d->viewOverExpoAction = new KToggleAction(KIcon("overexposure"), i18n("Over-Exposure Indicator"), this);
468
491
    d->viewOverExpoAction->setShortcut(KShortcut(Qt::Key_F11));
469
492
    d->viewOverExpoAction->setWhatsThis(i18n("Set this option to display white "
470
 
                                             "overlaid on the image. This will help you to avoid "
471
 
                                             "over-exposing the image." ) );
 
493
                                        "overlaid on the image. This will help you to avoid "
 
494
                                        "over-exposing the image." ) );
472
495
    connect(d->viewOverExpoAction, SIGNAL(triggered(bool)), this, SLOT(slotSetOverExposureIndicator(bool)));
473
496
    actionCollection()->addAction("editorwindow_overexposure", d->viewOverExpoAction);
474
497
 
567
590
 
568
591
    // -- Keyboard-only actions added to <MainWindow> ------------------------------
569
592
 
570
 
    KAction *closeToolAction = new KAction(i18n("Close Tool"), this);
 
593
    KAction* closeToolAction = new KAction(i18n("Close Tool"), this);
571
594
    actionCollection()->addAction("editorwindow_closetool", closeToolAction);
572
595
    closeToolAction->setShortcut(KShortcut(Qt::Key_Escape) );
573
596
    connect(closeToolAction, SIGNAL(triggered()), this, SLOT(slotCloseTool()));
574
597
 
575
 
    KAction *altBackwardAction = new KAction(i18n("Previous Image"), this);
 
598
    KAction* altBackwardAction = new KAction(i18n("Previous Image"), this);
576
599
    actionCollection()->addAction("editorwindow_backward_shift_space", altBackwardAction);
577
600
    altBackwardAction->setShortcut( KShortcut(Qt::SHIFT+Qt::Key_Space) );
578
601
    connect(altBackwardAction, SIGNAL(triggered()), this, SLOT(slotBackward()));
579
602
 
580
 
    KAction *applyToolAction = new KAction(i18n("Apply Tool"), this);
 
603
    KAction* applyToolAction = new KAction(i18n("Apply Tool"), this);
581
604
    actionCollection()->addAction("editorwindow_apply_enter", applyToolAction);
582
605
    applyToolAction->setShortcut( KShortcut(Qt::Key_Return) );
583
606
    connect(applyToolAction, SIGNAL(triggered()), this, SLOT(slotApplyTool()));
630
653
    d->underExposureIndicator = new QToolButton(buttonsBox);
631
654
    d->underExposureIndicator->setDefaultAction(d->viewUnderExpoAction);
632
655
    d->underExposureIndicator->setFocusPolicy(Qt::NoFocus);
633
 
//    new ButtonIconDisabler(d->underExposureIndicator);
 
656
    //    new ButtonIconDisabler(d->underExposureIndicator);
634
657
 
635
658
    d->overExposureIndicator  = new QToolButton(buttonsBox);
636
659
    d->overExposureIndicator->setDefaultAction(d->viewOverExpoAction);
637
660
    d->overExposureIndicator->setFocusPolicy(Qt::NoFocus);
638
 
//    new ButtonIconDisabler(d->overExposureIndicator);
 
661
    //    new ButtonIconDisabler(d->overExposureIndicator);
639
662
 
640
663
    d->cmViewIndicator        = new QToolButton(buttonsBox);
641
664
    d->cmViewIndicator->setDefaultAction(d->viewCMViewAction);
664
687
    bool sixteenBit = m_canvas->interface()->sixteenBit();
665
688
 
666
689
    if (!ptr || !w || !h)
 
690
    {
667
691
        return;
 
692
    }
668
693
 
669
694
    DImg image(w, h, sixteenBit, hasAlpha, ptr);
670
695
 
689
714
 
690
715
    for (int i=0; i<titles.size(); ++i)
691
716
    {
692
 
        QAction *action = m_undoAction->menu()->addAction(titles[i], d->undoSignalMapper, SLOT(map()));
 
717
        QAction* action = m_undoAction->menu()->addAction(titles[i], d->undoSignalMapper, SLOT(map()));
693
718
        d->undoSignalMapper->setMapping(action, i + 1);
694
719
    }
695
720
}
702
727
 
703
728
    for (int i=0; i<titles.size(); ++i)
704
729
    {
705
 
        QAction *action = m_redoAction->menu()->addAction(titles[i], d->redoSignalMapper, SLOT(map()));
 
730
        QAction* action = m_redoAction->menu()->addAction(titles[i], d->redoSignalMapper, SLOT(map()));
706
731
        d->redoSignalMapper->setMapping(action, i + 1);
707
732
    }
708
733
}
782
807
void EditorWindow::slotEscapePressed()
783
808
{
784
809
    if (m_fullScreen)
 
810
    {
785
811
        m_fullScreenAction->activate(QAction::Trigger);
 
812
    }
786
813
}
787
814
 
788
815
void EditorWindow::loadImagePlugins()
792
819
        d->imagepluginsActionCollection->clear();
793
820
        delete d->imagepluginsActionCollection;
794
821
    }
 
822
 
795
823
    d->imagepluginsActionCollection = new KActionCollection(this, KGlobal::mainComponent());
796
824
 
797
 
    QList<ImagePlugin *> pluginList = m_imagePluginLoader->pluginList();
 
825
    QList<ImagePlugin*> pluginList = m_imagePluginLoader->pluginList();
798
826
 
799
 
    foreach (ImagePlugin *plugin, pluginList)
 
827
    foreach (ImagePlugin* plugin, pluginList)
800
828
    {
801
829
        if (plugin)
802
830
        {
809
837
 
810
838
            if (categoryStr != QString("__INVALID__") && !categoryStr.isEmpty())
811
839
            {
812
 
                KActionCategory *category = new KActionCategory(categoryStr, d->imagepluginsActionCollection);
 
840
                KActionCategory* category = new KActionCategory(categoryStr, d->imagepluginsActionCollection);
813
841
                foreach (QAction* action, plugin->actionCollection()->actions())
814
842
                {
815
843
                    category->addAction(action->objectName(), action);
824
852
                }
825
853
#if KDE_IS_VERSION(4,1,68)
826
854
            }
 
855
 
827
856
#endif
828
857
        }
829
858
        else
844
873
        delete d->imagepluginsActionCollection;
845
874
    }
846
875
 
847
 
    QList<ImagePlugin *> pluginList = m_imagePluginLoader->pluginList();
 
876
    QList<ImagePlugin*> pluginList = m_imagePluginLoader->pluginList();
848
877
 
849
 
    foreach (ImagePlugin *plugin, pluginList)
 
878
    foreach (ImagePlugin* plugin, pluginList)
850
879
    {
851
880
        if (plugin)
852
881
        {
878
907
 
879
908
    // Restore Auto zoom action
880
909
    bool autoZoom = group.readEntry(d->configAutoZoomEntry, true);
 
910
 
881
911
    if (autoZoom)
 
912
    {
882
913
        d->zoomFitToWindowAction->activate(QAction::Trigger);
 
914
    }
883
915
 
884
916
    slotSetUnderExposureIndicator(group.readEntry(d->configUnderExposureIndicatorEntry, false));
885
917
    slotSetOverExposureIndicator(group.readEntry(d->configOverExposureIndicatorEntry, false));
920
952
    // -- RAW images decoding settings ------------------------------------------------------
921
953
 
922
954
    m_IOFileSettings->useRAWImport = group.readEntry(d->configUseRawImportToolEntry, false);
923
 
    m_IOFileSettings->rawDecodingSettings.readSettings(group);
 
955
    m_IOFileSettings->rawDecodingSettings.rawPrm.readSettings(group);
924
956
 
925
957
    // -- Color Management settings ---------------------------------------------------------
926
958
 
931
963
    {
932
964
        if (d->ICCSettings->defaultUncalibratedBehavior & ICCSettingsContainer::AutomaticColors)
933
965
        {
934
 
            m_IOFileSettings->rawDecodingSettings.outputColorSpace = DRawDecoding::CUSTOMOUTPUTCS;
935
 
            m_IOFileSettings->rawDecodingSettings.outputProfile    = d->ICCSettings->workspaceProfile;
 
966
            m_IOFileSettings->rawDecodingSettings.rawPrm.outputColorSpace = RawDecodingSettings::CUSTOMOUTPUTCS;
 
967
            m_IOFileSettings->rawDecodingSettings.rawPrm.outputProfile    = d->ICCSettings->workspaceProfile;
936
968
        }
937
969
        else
938
970
        {
939
 
            m_IOFileSettings->rawDecodingSettings.outputColorSpace = DRawDecoding::RAWCOLOR;
 
971
            m_IOFileSettings->rawDecodingSettings.rawPrm.outputColorSpace = RawDecodingSettings::RAWCOLOR;
940
972
        }
941
973
    }
942
974
    else
943
975
    {
944
 
        m_IOFileSettings->rawDecodingSettings.outputColorSpace = DRawDecoding::SRGB;
 
976
        m_IOFileSettings->rawDecodingSettings.rawPrm.outputColorSpace = RawDecodingSettings::SRGB;
945
977
    }
946
978
 
947
979
    d->toolIface->updateICCSettings();
973
1005
 
974
1006
    group.writeEntry(d->configAutoZoomEntry, d->zoomFitToWindowAction->isChecked());
975
1007
    m_splitter->saveState(group);
 
1008
 
976
1009
    if (m_vSplitter)
 
1010
    {
977
1011
        group.writeEntry(d->configVerticalSplitterStateEntry, m_vSplitter->saveState().toBase64());
 
1012
    }
978
1013
 
979
1014
    group.writeEntry("Show Thumbbar", thumbBar()->shouldBeVisible());
980
1015
    group.writeEntry(d->configFullScreenEntry, m_fullScreenAction->isChecked());
1029
1064
        m_redoAction->setEnabled(val);
1030
1065
    }
1031
1066
 
1032
 
    QList<ImagePlugin *> pluginList = m_imagePluginLoader->pluginList();
 
1067
    QList<ImagePlugin*> pluginList = m_imagePluginLoader->pluginList();
1033
1068
 
1034
 
    foreach (ImagePlugin *plugin, pluginList)
 
1069
    foreach (ImagePlugin* plugin, pluginList)
1035
1070
    {
1036
1071
        if (plugin)
1037
1072
        {
1054
1089
 
1055
1090
        if (d->removeFullScreenButton)
1056
1091
        {
1057
 
            QList<KToolBar *> toolbars = toolBars();
1058
 
            foreach(KToolBar *toolbar, toolbars)
 
1092
            QList<KToolBar*> toolbars = toolBars();
 
1093
            foreach (KToolBar* toolbar, toolbars)
1059
1094
            {
1060
1095
                // name is set in ui.rc XML file
1061
1096
                if (toolbar->objectName() == "ToolBar")
1085
1120
        {
1086
1121
            showToolBars();
1087
1122
 
1088
 
            QList<KToolBar *> toolbars = toolBars();
1089
 
            KToolBar *mainToolbar = 0;
1090
 
            foreach(KToolBar *toolbar, toolbars)
 
1123
            QList<KToolBar*> toolbars = toolBars();
 
1124
            KToolBar* mainToolbar = 0;
 
1125
            foreach (KToolBar* toolbar, toolbars)
1091
1126
            {
1092
1127
                if (toolbar->objectName() == "ToolBar")
1093
1128
                {
1142
1177
        QFileInfo fi(m_canvas->currentImageFilePath());
1143
1178
        QString warnMsg(i18n("About to overwrite file \"%1\"\nAre you sure?", fi.fileName()));
1144
1179
        return (KMessageBox::warningContinueCancel(this,
1145
 
                                                   warnMsg,
1146
 
                                                   i18n("Warning"),
1147
 
                                                   KGuiItem(i18n("Overwrite")),
1148
 
                                                   KStandardGuiItem::cancel(),
1149
 
                                                   QString("editorWindowSaveOverwrite"))
 
1180
                warnMsg,
 
1181
                i18n("Warning"),
 
1182
                KGuiItem(i18n("Overwrite")),
 
1183
                KStandardGuiItem::cancel(),
 
1184
                QString("editorWindowSaveOverwrite"))
1150
1185
                ==  KMessageBox::Continue);
1151
1186
 
1152
1187
    }
1166
1201
    m_saveAction->setEnabled(hasChangesToSave());
1167
1202
 
1168
1203
    if (!moreUndo)
 
1204
    {
1169
1205
        m_rotatedOrFlipped = false;
 
1206
    }
1170
1207
}
1171
1208
 
1172
1209
bool EditorWindow::hasChangesToSave()
1193
1230
        int result;
1194
1231
        QString boxMessage = i18n("The image '%1' has been modified.\n"
1195
1232
                                  "Do you want to save it?", url.fileName());
 
1233
 
1196
1234
        if (allowCancel)
1197
1235
        {
1198
1236
            result = KMessageBox::warningYesNoCancel(this,
1199
 
                                  boxMessage,
1200
 
                                  QString(),
1201
 
                                  KStandardGuiItem::save(),
1202
 
                                  KStandardGuiItem::discard());
 
1237
                     boxMessage,
 
1238
                     QString(),
 
1239
                     KStandardGuiItem::save(),
 
1240
                     KStandardGuiItem::discard());
1203
1241
        }
1204
1242
        else
1205
1243
        {
1206
1244
            result = KMessageBox::warningYesNo(this,
1207
 
                                  boxMessage,
1208
 
                                  QString(),
1209
 
                                  KStandardGuiItem::save(),
1210
 
                                  KStandardGuiItem::discard());
 
1245
                                               boxMessage,
 
1246
                                               QString(),
 
1247
                                               KStandardGuiItem::save(),
 
1248
                                               KStandardGuiItem::discard());
1211
1249
        }
1212
1250
 
1213
1251
        if (result == KMessageBox::Yes)
1217
1255
            switch (saveOrSaveAs)
1218
1256
            {
1219
1257
                case AskIfNeeded:
 
1258
 
1220
1259
                    if (m_canvas->isReadOnly())
 
1260
                    {
1221
1261
                        saving = saveAs();
 
1262
                    }
1222
1263
                    else if (promptForOverWrite())
 
1264
                    {
1223
1265
                        saving = save();
 
1266
                    }
 
1267
 
1224
1268
                    break;
1225
1269
                case OverwriteWithoutAsking:
 
1270
 
1226
1271
                    if (m_canvas->isReadOnly())
 
1272
                    {
1227
1273
                        saving = saveAs();
 
1274
                    }
1228
1275
                    else
 
1276
                    {
1229
1277
                        saving = save();
 
1278
                    }
 
1279
 
1230
1280
                    break;
1231
1281
                case AlwaysSaveAs:
1232
1282
                    saving = saveAs();
1266
1316
{
1267
1317
    // avoid reentrancy - return false means we have reentered the loop already.
1268
1318
    if (m_savingContext->synchronizingState == SavingContextContainer::SynchronousSaving)
 
1319
    {
1269
1320
        return false;
 
1321
    }
1270
1322
 
1271
1323
    if (m_savingContext->savingState != SavingContextContainer::SavingStateNone)
1272
1324
    {
1278
1330
        enterWaitingLoop();
1279
1331
        m_savingContext->synchronizingState = SavingContextContainer::NormalSaving;
1280
1332
    }
 
1333
 
1281
1334
    return true;
1282
1335
}
1283
1336
 
1299
1352
    d->copyAction->setEnabled(val);
1300
1353
 
1301
1354
    QList<ImagePlugin*> pluginList = m_imagePluginLoader->pluginList();
1302
 
    foreach (ImagePlugin *plugin, pluginList)
 
1355
    foreach (ImagePlugin* plugin, pluginList)
1303
1356
    {
1304
1357
        if (plugin)
1305
1358
        {
1313
1366
 
1314
1367
    // Update status bar
1315
1368
    if (val)
 
1369
    {
1316
1370
        setToolInfoMessage(QString("(%1, %2) (%3 x %4)").arg(sel.x()).arg(sel.y()).arg(sel.width()).arg(sel.height()));
 
1371
    }
1317
1372
    else
 
1373
    {
1318
1374
        setToolInfoMessage(i18n("No selection"));
 
1375
    }
1319
1376
}
1320
1377
 
1321
1378
void EditorWindow::hideToolBars()
1322
1379
{
1323
 
    QList<KToolBar *> toolbars = toolBars();
1324
 
    foreach(KToolBar *toolbar, toolbars)
 
1380
    QList<KToolBar*> toolbars = toolBars();
 
1381
    foreach (KToolBar* toolbar, toolbars)
1325
1382
    {
1326
1383
        toolbar->hide();
1327
1384
    }
1329
1386
 
1330
1387
void EditorWindow::showToolBars()
1331
1388
{
1332
 
    QList<KToolBar *> toolbars = toolBars();
1333
 
    foreach(KToolBar *toolbar, toolbars)
 
1389
    QList<KToolBar*> toolbars = toolBars();
 
1390
    foreach (KToolBar* toolbar, toolbars)
1334
1391
    {
1335
1392
        toolbar->show();
1336
1393
    }
1367
1424
    m_animLogo->stop();
1368
1425
 
1369
1426
    if (success)
 
1427
    {
1370
1428
        colorManage();
 
1429
    }
1371
1430
}
1372
1431
 
1373
1432
void EditorWindow::colorManage()
1374
1433
{
1375
1434
    if (!d->ICCSettings->enableCM)
 
1435
    {
1376
1436
        return;
 
1437
    }
1377
1438
 
1378
1439
    DImg image = m_canvas->currentImage();
 
1440
 
1379
1441
    if (image.isNull())
 
1442
    {
1380
1443
        return;
 
1444
    }
1381
1445
 
1382
1446
    if (!IccManager::needsPostLoadingManagement(image))
 
1447
    {
1383
1448
        return;
 
1449
    }
1384
1450
 
1385
1451
    IccManager manager(image, m_canvas->currentImageFilePath());
 
1452
 
1386
1453
    if (!manager.hasValidWorkspace())
1387
1454
    {
1388
1455
        QString message = i18n("Cannot open the specified working space profile (\"%1\"). "
1416
1483
void EditorWindow::slotSave()
1417
1484
{
1418
1485
    if (m_canvas->isReadOnly())
 
1486
    {
1419
1487
        saveAs();
 
1488
    }
1420
1489
    else if (promptForOverWrite())
 
1490
    {
1421
1491
        save();
 
1492
    }
1422
1493
}
1423
1494
 
1424
1495
void EditorWindow::slotSavingStarted(const QString& /*filename*/)
1451
1522
    finishSaving(true);
1452
1523
 
1453
1524
    if (m_savingContext->executedOperation == SavingContextContainer::SavingStateSave)
 
1525
    {
1454
1526
        saveIsComplete();
 
1527
    }
1455
1528
    else
 
1529
    {
1456
1530
        saveAsIsComplete();
 
1531
    }
1457
1532
 
1458
1533
    // Take all actions necessary to update information and re-enable sidebar
1459
1534
    slotChanged();
1479
1554
                                              m_savingContext->destinationURL.fileName(),
1480
1555
                                              m_savingContext->destinationURL.toLocalFile()));
1481
1556
            }
 
1557
 
1482
1558
            finishSaving(false);
1483
1559
            return;
1484
1560
        }
1489
1565
    else
1490
1566
    {
1491
1567
        kWarning() << "Why was slotSavingFinished called "
1492
 
                                  << "if we did not want to save a file?";
 
1568
                   << "if we did not want to save a file?";
1493
1569
    }
1494
1570
}
1495
1571
 
1505
1581
 
1506
1582
    // Exit of internal Qt event loop to unlock promptUserSave() method.
1507
1583
    if (m_savingContext->synchronizingState == SavingContextContainer::SynchronousSaving)
 
1584
    {
1508
1585
        quitWaitingLoop();
 
1586
    }
1509
1587
 
1510
1588
    // Enable actions as appropriate after saving
1511
1589
    toggleActions(true);
1521
1599
    }
1522
1600
}
1523
1601
 
1524
 
void EditorWindow::setupTempSaveFile(const KUrl & url)
 
1602
void EditorWindow::setupTempSaveFile(const KUrl& url)
1525
1603
{
1526
1604
#ifdef _WIN32
1527
1605
    KUrl parent(url.directory(KUrl::AppendTrailingSlash));
1532
1610
 
1533
1611
    // use magic file extension which tells the digikamalbums ioslave to ignore the file
1534
1612
    m_savingContext->saveTempFile = new KTemporaryFile();
 
1613
 
1535
1614
    // if the destination url is on local file system, try to set the temp file
1536
1615
    // location to the destination folder, otherwise use a local default
1537
1616
    if (url.isLocalFile())
1538
1617
    {
1539
1618
        m_savingContext->saveTempFile->setPrefix(tempDir);
1540
1619
    }
 
1620
 
1541
1621
    m_savingContext->saveTempFile->setSuffix(".digikamtempfile.tmp");
1542
1622
    m_savingContext->saveTempFile->setAutoRemove(false);
1543
1623
    m_savingContext->saveTempFile->open();
1561
1641
 
1562
1642
    // avoid any reentrancy. Should be impossible anyway since actions will be disabled.
1563
1643
    if (m_savingContext->savingState != SavingContextContainer::SavingStateNone)
 
1644
    {
1564
1645
        return;
 
1646
    }
1565
1647
 
1566
1648
    if (!checkPermissions(url))
 
1649
    {
1567
1650
        return;
 
1651
    }
1568
1652
 
1569
1653
    setupTempSaveFile(url);
1570
1654
 
1629
1713
 
1630
1714
    // find locations of interesting characters in the filter string
1631
1715
    const int asteriskLocation = filter.indexOf('*');
 
1716
 
1632
1717
    if (asteriskLocation < 0)
1633
1718
    {
1634
1719
        kDebug() << "Could not find a * in the filter";
1636
1721
    }
1637
1722
 
1638
1723
    int endLocation = filter.indexOf(QRegExp("[|\\* ]"), asteriskLocation + 1);
 
1724
 
1639
1725
    if (endLocation < 0)
1640
1726
    {
1641
1727
        endLocation = filter.length();
1653
1739
}
1654
1740
 
1655
1741
bool EditorWindow::selectValidSavingFormat(const QString& filter,
1656
 
                                           const KUrl& targetUrl, const QString &autoFilter)
 
1742
        const KUrl& targetUrl, const QString& autoFilter)
1657
1743
{
1658
1744
    kDebug() << "Trying to find a saving format with filter = "
1659
1745
             << filter << ", targetUrl = " << targetUrl;
1677
1763
    if (filter == autoFilter)
1678
1764
    {
1679
1765
        QString suffix;
 
1766
 
1680
1767
        if (targetUrl.isLocalFile())
1681
1768
        {
1682
1769
            // for local files QFileInfo can be used
1689
1776
            // for remote files string manipulation is needed unfortunately
1690
1777
            QString fileName = targetUrl.fileName();
1691
1778
            const int periodLocation = fileName.lastIndexOf('.');
 
1779
 
1692
1780
            if (periodLocation >= 0)
1693
1781
            {
1694
1782
                suffix = fileName.right(fileName.size() - periodLocation - 1);
1695
1783
            }
 
1784
 
1696
1785
            kDebug() << "Possible format from remote file: " << suffix;
1697
1786
        }
 
1787
 
1698
1788
        if (!suffix.isEmpty() && validTypes.contains(suffix, Qt::CaseInsensitive))
1699
1789
        {
1700
1790
            kDebug() << "Using format from target url " << suffix;
1707
1797
        // use extension from the filter
1708
1798
 
1709
1799
        QString filterExtension = getExtensionFromFilter(filter);
 
1800
 
1710
1801
        if (!filterExtension.isEmpty() &&
1711
1802
            validTypes.contains(filterExtension, Qt::CaseInsensitive))
1712
1803
        {
1719
1810
    // another way to determine the format is to use the original file
1720
1811
    {
1721
1812
        QString originalFormat(QImageReader::imageFormat(
1722
 
                        m_savingContext->srcURL.toLocalFile()));
 
1813
                                   m_savingContext->srcURL.toLocalFile()));
 
1814
 
1723
1815
        if (validTypes.contains(originalFormat, Qt::CaseInsensitive))
1724
1816
        {
1725
1817
            kDebug() << "Using format from original file: " << originalFormat;
1738
1830
    kDebug() << "startSavingAs called";
1739
1831
 
1740
1832
    if (m_savingContext->savingState != SavingContextContainer::SavingStateNone)
 
1833
    {
1741
1834
        return false;
 
1835
    }
1742
1836
 
1743
1837
    m_savingContext->srcURL = url;
1744
1838
 
1745
1839
    // prepare the save dialog
1746
 
    FileSaveOptionsBox *options      = new FileSaveOptionsBox();
 
1840
    FileSaveOptionsBox* options      = new FileSaveOptionsBox();
1747
1841
    QPointer<KFileDialog> imageFileSaveDialog
1748
 
                                     = new KFileDialog(m_savingContext->srcURL.isLocalFile() ?
1749
 
                                                       m_savingContext->srcURL : KUrl(QDir::homePath()),
1750
 
                                                       QString(),
1751
 
                                                       this,
1752
 
                                                       options);
 
1842
    = new KFileDialog(m_savingContext->srcURL.isLocalFile() ?
 
1843
                      m_savingContext->srcURL : KUrl(QDir::homePath()),
 
1844
                      QString(),
 
1845
                      this,
 
1846
                      options);
1753
1847
    options->setDialog(imageFileSaveDialog);
1754
1848
 
1755
 
    ImageDialogPreview *preview = new ImageDialogPreview(imageFileSaveDialog);
 
1849
    ImageDialogPreview* preview = new ImageDialogPreview(imageFileSaveDialog);
1756
1850
    imageFileSaveDialog->setPreviewWidget(preview);
1757
1851
    imageFileSaveDialog->setOperationMode(KFileDialog::Saving);
1758
1852
    imageFileSaveDialog->setMode(KFile::File);
1764
1858
    KConfigGroup group        = config->group(CONFIG_GROUP_NAME);
1765
1859
    const QString optionLastExtension = "LastSavedImageExtension";
1766
1860
    QString ext               = group.readEntry(optionLastExtension, "png");
 
1861
 
1767
1862
    if (ext.isEmpty())
1768
1863
    {
1769
1864
        ext = "png";
1770
1865
    }
 
1866
 
1771
1867
    QString fileName          = info.completeBaseName() + QString(".") + ext;
1772
1868
 
1773
1869
    // Determine the default filter from LastSavedImageTypeMime
1784
1880
 
1785
1881
    // Start dialog and check if canceled.
1786
1882
    int result;
 
1883
 
1787
1884
    if (d->currentWindowModalDialog)
1788
1885
    {
1789
1886
        // go application-modal - we will create utter confusion if descending into more than one window-modal dialog
1797
1894
        result = imageFileSaveDialog->exec();
1798
1895
        d->currentWindowModalDialog = 0;
1799
1896
    }
 
1897
 
1800
1898
    if (result != KFileDialog::Accepted || !imageFileSaveDialog)
1801
1899
    {
1802
 
       return false;
 
1900
        return false;
1803
1901
    }
1804
1902
 
1805
1903
    KUrl newURL = imageFileSaveDialog->selectedUrl();
1810
1908
 
1811
1909
    const QString configShowImageSettingsDialog="ShowImageSettingsDialog";
1812
1910
    bool showDialog = group.readEntry(configShowImageSettingsDialog, true);
1813
 
    if (showDialog && options->discoverFormat(newURL.fileName(), DImg::NONE)!=DImg::NONE) {
1814
 
        FileSaveOptionsDlg *fileSaveOptionsDialog   = new FileSaveOptionsDlg(this, options);
 
1911
 
 
1912
    if (showDialog && options->discoverFormat(newURL.fileName(), DImg::NONE)!=DImg::NONE)
 
1913
    {
 
1914
        FileSaveOptionsDlg* fileSaveOptionsDialog   = new FileSaveOptionsDlg(this, options);
1815
1915
        options->slotImageFileFormatChanged(newURL.fileName());
1816
1916
 
1817
1917
        if (d->currentWindowModalDialog)
1827
1927
            result = fileSaveOptionsDialog->exec();
1828
1928
            d->currentWindowModalDialog = 0;
1829
1929
        }
 
1930
 
1830
1931
        if (result != KFileDialog::Accepted || !fileSaveOptionsDialog)
1831
1932
        {
1832
1933
            return false;
1833
1934
        }
1834
1935
    }
 
1936
 
1835
1937
#endif
1836
1938
 
1837
1939
    // Update file save settings in editor instance.
1875
1977
 
1876
1978
    QFileInfo fi(newURL.toLocalFile());
1877
1979
    m_savingContext->destinationExisted = fi.exists();
 
1980
 
1878
1981
    if ( m_savingContext->destinationExisted )
1879
1982
    {
1880
1983
        int result =
1881
1984
 
1882
1985
            KMessageBox::warningYesNo( this, i18n("A file named \"%1\" already "
1883
 
                                                  "exists. Are you sure you want "
1884
 
                                                  "to overwrite it?",
1885
 
                                                  newURL.fileName()),
 
1986
                                       "exists. Are you sure you want "
 
1987
                                       "to overwrite it?",
 
1988
                                       newURL.fileName()),
1886
1989
                                       i18n("Overwrite File?"),
1887
1990
                                       KStandardGuiItem::overwrite(),
1888
1991
                                       KStandardGuiItem::cancel() );
1889
1992
 
1890
1993
        if (result != KMessageBox::Yes)
 
1994
        {
1891
1995
            return false;
 
1996
        }
1892
1997
 
1893
1998
        // There will be two message boxes if the file is not writable.
1894
1999
        // This may be controversial, and it may be changed, but it was a deliberate decision.
1895
2000
        if (!checkPermissions(newURL))
 
2001
        {
1896
2002
            return false;
 
2003
        }
1897
2004
    }
1898
2005
 
1899
2006
    // Now do the actual saving -----------------------------------------------------
1922
2029
 
1923
2030
    if (fi.exists() && !fi.isWritable())
1924
2031
    {
1925
 
       int result =
 
2032
        int result =
1926
2033
 
1927
2034
            KMessageBox::warningYesNo( this, i18n("You do not have write permissions "
1928
 
                                                  "for the file named \"%1\". "
1929
 
                                                  "Are you sure you want "
1930
 
                                                  "to overwrite it?",
1931
 
                                                  url.fileName()),
 
2035
                                       "for the file named \"%1\". "
 
2036
                                       "Are you sure you want "
 
2037
                                       "to overwrite it?",
 
2038
                                       url.fileName()),
1932
2039
                                       i18n("Overwrite File?"),
1933
2040
                                       KStandardGuiItem::overwrite(),
1934
2041
                                       KStandardGuiItem::cancel() );
1935
2042
 
1936
2043
        if (result != KMessageBox::Yes)
 
2044
        {
1937
2045
            return false;
 
2046
        }
1938
2047
    }
1939
2048
 
1940
2049
    return true;
1951
2060
 
1952
2061
        // check that we're not replacing a symlink
1953
2062
        QFileInfo info(fileName);
 
2063
 
1954
2064
        if (info.isSymLink())
1955
2065
        {
1956
2066
            fileName = info.symLinkTarget();
1974
2084
        if (m_savingContext->destinationExisted)
1975
2085
        {
1976
2086
            struct stat stbuf;
 
2087
 
1977
2088
            if (::stat(dstFileName, &stbuf) == 0)
1978
2089
            {
1979
2090
                filePermissions = stbuf.st_mode;
1980
2091
            }
1981
2092
        }
 
2093
 
1982
2094
#endif
1983
2095
        // rename tmp file to dest
1984
2096
        int ret;
1990
2102
#else
1991
2103
        // KDE 4.2.x or 4.1.x
1992
2104
        ret = KDE_rename(QFile::encodeName(m_savingContext->saveTempFileName),
1993
 
                          dstFileName);
 
2105
                         dstFileName);
1994
2106
#endif
 
2107
 
1995
2108
        if (ret != 0)
1996
2109
        {
1997
2110
            KMessageBox::error(this, i18n("Failed to overwrite original file"),
2001
2114
        }
2002
2115
 
2003
2116
#ifndef _WIN32
 
2117
 
2004
2118
        // restore permissions
2005
2119
        if (::chmod(dstFileName, filePermissions) != 0)
2006
2120
        {
2007
2121
            kWarning() << "Failed to restore file permissions for file " << dstFileName;
2008
2122
        }
 
2123
 
2009
2124
#endif
2010
2125
        movingSaveFileFinished(true);
2011
2126
        return;
2016
2131
 
2017
2132
        kDebug() << "moving a remote file via KIO";
2018
2133
 
2019
 
        KIO::CopyJob *moveJob = KIO::move(KUrl(
2020
 
                        m_savingContext->saveTempFileName),
2021
 
                        m_savingContext->destinationURL);
 
2134
        KIO::CopyJob* moveJob = KIO::move(KUrl(
 
2135
                                              m_savingContext->saveTempFileName),
 
2136
                                          m_savingContext->destinationURL);
2022
2137
        connect(moveJob, SIGNAL(result(KJob*)),
2023
2138
                this, SLOT(slotKioMoveFinished(KJob*)));
2024
2139
    }
2025
2140
}
2026
2141
 
2027
 
void EditorWindow::slotKioMoveFinished(KJob *job)
 
2142
void EditorWindow::slotKioMoveFinished(KJob* job)
2028
2143
{
2029
2144
    if (job->error())
2030
2145
    {
2057
2172
{
2058
2173
    d->viewCMViewAction->blockSignals(true);
2059
2174
    bool cmv = false;
 
2175
 
2060
2176
    if (d->ICCSettings->enableCM)
2061
2177
    {
2062
2178
        cmv = !d->ICCSettings->useManagedView;
2073
2189
void EditorWindow::setColorManagedViewIndicatorToolTip(bool available, bool cmv)
2074
2190
{
2075
2191
    QString tooltip;
 
2192
 
2076
2193
    if (available)
2077
2194
    {
2078
2195
        if (cmv)
 
2196
        {
2079
2197
            tooltip = i18n("Color-Managed View is enabled.");
 
2198
        }
2080
2199
        else
 
2200
        {
2081
2201
            tooltip = i18n("Color-Managed View is disabled.");
 
2202
        }
2082
2203
    }
2083
2204
    else
2084
2205
    {
2085
2206
        tooltip = i18n("Color Management is not configured, so the Color-Managed View is not available.");
2086
2207
    }
 
2208
 
2087
2209
    d->cmViewIndicator->setToolTip(tooltip);
2088
2210
}
2089
2211
 
2115
2237
void EditorWindow::setUnderExposureToolTip(bool on)
2116
2238
{
2117
2239
    d->underExposureIndicator->setToolTip(
2118
 
                   on ? i18n("Under-Exposure indicator is enabled")
2119
 
                      : i18n("Under-Exposure indicator is disabled"));
 
2240
        on ? i18n("Under-Exposure indicator is enabled")
 
2241
        : i18n("Under-Exposure indicator is disabled"));
2120
2242
}
2121
2243
 
2122
2244
void EditorWindow::slotSetOverExposureIndicator(bool on)
2130
2252
void EditorWindow::setOverExposureToolTip(bool on)
2131
2253
{
2132
2254
    d->overExposureIndicator->setToolTip(
2133
 
                   on ? i18n("Over-Exposure indicator is enabled")
2134
 
                      : i18n("Over-Exposure indicator is disabled"));
 
2255
        on ? i18n("Over-Exposure indicator is enabled")
 
2256
        : i18n("Over-Exposure indicator is disabled"));
2135
2257
}
2136
2258
 
2137
2259
void EditorWindow::slotDonateMoney()
2170
2292
 
2171
2293
void EditorWindow::slotRawCameraList()
2172
2294
{
2173
 
    RawCameraDlg *dlg = new RawCameraDlg(kapp->activeWindow());
 
2295
    RawCameraDlg* dlg = new RawCameraDlg(kapp->activeWindow());
2174
2296
    dlg->show();
2175
2297
}
2176
2298
 
2178
2300
{
2179
2301
    QStringList themes(ThemeEngine::instance()->themeNames());
2180
2302
    int index = themes.indexOf(ThemeEngine::instance()->getCurrentThemeName());
 
2303
 
2181
2304
    if (index == -1)
 
2305
    {
2182
2306
        index = themes.indexOf(i18n("Default"));
 
2307
    }
2183
2308
 
2184
2309
    m_themeMenuAction->setCurrentItem(index);
2185
2310
 
2187
2312
    KConfigGroup group        = config->group(CONFIG_GROUP_NAME);
2188
2313
 
2189
2314
    if (!group.readEntry(d->configUseThemeBackgroundColorEntry, true))
 
2315
    {
2190
2316
        m_bgColor = group.readEntry(d->configBackgroundColorEntry, QColor(Qt::black));
 
2317
    }
2191
2318
    else
 
2319
    {
2192
2320
        m_bgColor = ThemeEngine::instance()->baseColor();
 
2321
    }
2193
2322
 
2194
2323
    m_canvas->setBackgroundColor(m_bgColor);
2195
2324
}
2206
2335
        rightSideBar()->restore(QList<QWidget*>() << thumbBar(), d->fullscreenSizeBackup);
2207
2336
 
2208
2337
        if (m_fullScreenHideThumbBar)
 
2338
        {
2209
2339
            thumbBar()->restoreVisibility();
 
2340
        }
2210
2341
    }
2211
2342
    else
2212
2343
    {
2215
2346
        rightSideBar()->backup(QList<QWidget*>() << thumbBar(), &d->fullscreenSizeBackup);
2216
2347
 
2217
2348
        if (m_fullScreenHideThumbBar)
2218
 
                thumbBar()->hide();
 
2349
        {
 
2350
            thumbBar()->hide();
 
2351
        }
2219
2352
    }
2220
2353
}
2221
2354
 
2222
2355
void EditorWindow::slotComponentsInfo()
2223
2356
{
2224
 
    LibsInfoDlg *dlg = new LibsInfoDlg(this);
 
2357
    LibsInfoDlg* dlg = new LibsInfoDlg(this);
2225
2358
    dlg->show();
2226
2359
}
2227
2360
 
2253
2386
void EditorWindow::slotCloseTool()
2254
2387
{
2255
2388
    if (d->toolIface)
 
2389
    {
2256
2390
        d->toolIface->slotCloseTool();
 
2391
    }
2257
2392
}
2258
2393
 
2259
2394
void EditorWindow::slotApplyTool()
2260
2395
{
2261
2396
    if (d->toolIface)
 
2397
    {
2262
2398
        d->toolIface->slotApplyTool();
 
2399
    }
2263
2400
}
2264
2401
 
2265
2402
void EditorWindow::setPreviewModeMask(int mask)