53
#include <kdeversion.h>
54
54
#include <kaboutdata.h>
55
55
#include <kaction.h>
56
#if KDE_IS_VERSION(4,1,68)
56
57
#include <kactioncategory.h>
57
59
#include <kactioncollection.h>
58
60
#include <kactionmenu.h>
59
61
#include <kapplication.h>
88
90
#include <ktoolbar.h>
89
91
#include <ktoolbarpopupaction.h>
90
92
#include <ktoolinvocation.h>
93
#include <kurlcombobox.h>
91
94
#include <kwindowsystem.h>
92
95
#include <kxmlguifactory.h>
93
#include <kdeversion.h>
94
96
#include <kde_file.h>
95
97
#include <kio/copyjob.h>
96
98
#include <kdebug.h>
940
943
m_IOFileSettings->rawDecodingSettings.outputColorSpace = DRawDecoding::SRGB;
942
946
m_IOFileSettings->rawDecodingSettings.sixteenBitsImage = group.readEntry("SixteenBitsImage", false);
943
947
m_IOFileSettings->rawDecodingSettings.whiteBalance = (DRawDecoding::WhiteBalance)group.readEntry("WhiteBalance",
1224
void EditorWindow::slotUndoStateChanged(bool moreUndo, bool moreRedo, bool canSave)
1226
m_revertAction->setEnabled(canSave);
1227
m_undoAction->setEnabled(moreUndo);
1228
m_redoAction->setEnabled(moreRedo);
1229
m_saveAction->setEnabled(hasChangesToSave());
1232
m_rotatedOrFlipped = false;
1235
bool EditorWindow::hasChangesToSave()
1237
// virtual, can be extended by subclasses
1238
return m_canvas->hasChangesToSave();
1220
1241
bool EditorWindow::promptUserSave(const KUrl& url, SaveOrSaveAs saveOrSaveAs, bool allowCancel)
1222
if (m_saveAction->isEnabled())
1243
if (hasChangesToSave())
1224
1245
// if window is minimized, show it
1225
1246
if (isMinimized())
1569
1590
void EditorWindow::setupTempSaveFile(const KUrl & url)
1594
KUrl parent(url.directory(KUrl::AppendTrailingSlash));
1595
QString tempDir = parent.toLocalFile();
1572
1597
QString tempDir = url.directory(KUrl::AppendTrailingSlash);
1573
1600
// use magic file extension which tells the digikamalbums ioslave to ignore the file
1574
1601
m_savingContext->saveTempFile = new KTemporaryFile();
1575
1602
// if the destination url is on local file system, try to set the temp file
1626
1653
QStringList EditorWindow::getWritingFilters()
1629
// begin with the filtersa KImageIO supports
1656
// begin with the filters KImageIO supports
1630
1657
QString pattern = KImageIO::pattern(KImageIO::Writing);
1631
1658
QStringList writablePattern = pattern.split(QChar('\n'));
1632
1659
kDebug() << "KImageIO offered pattern: " << writablePattern;
1634
// remove "all images" type
1635
// XXX bad assumption that this is always the first type in the list
1636
writablePattern.removeFirst();
1638
1661
// append custom file types
1639
1662
writablePattern.append(QString("*.jp2|") + i18n("JPEG 2000 image"));
1640
1663
writablePattern.append(QString("*.pgf|") + i18n("Progressive Graphics File"));
1686
1709
return QString();
1689
const int endLocation = filter.indexOf(QRegExp("[|\\* ]"), asteriskLocation + 1);
1712
int endLocation = filter.indexOf(QRegExp("[|\\* ]"), asteriskLocation + 1);
1690
1713
if (endLocation < 0)
1692
kDebug() << "Could not find a valid end of the format in the filter";
1715
endLocation = filter.length();
1696
1718
kDebug() << "astriskLocation = " << asteriskLocation
1708
bool EditorWindow::selectValidSavingFormat(const QString& filterExtension, const KUrl& targetUrl)
1730
bool EditorWindow::selectValidSavingFormat(const QString& filter,
1731
const KUrl& targetUrl, const QString &autoFilter)
1711
kDebug() << "Trying to find a saving format with filterExtension = "
1712
<< filterExtension << ", targetUrl = " << targetUrl;
1734
kDebug() << "Trying to find a saving format with filter = "
1735
<< filter << ", targetUrl = " << targetUrl;
1714
1737
// build a list of valid types
1715
1738
QStringList validTypes = KImageIO::types(KImageIO::Writing);
1727
1750
kDebug() << "Writable formats: " << validTypes;
1729
// first check if the selected filter extension can be used
1731
if (!filterExtension.isEmpty() &&
1732
validTypes.contains(filterExtension, Qt::CaseInsensitive))
1734
kDebug() << "Using format from filter extension: " << filterExtension;
1735
m_savingContext->format = filterExtension;
1740
// as a second step, try to determine the desired format from the extension
1741
// of the target url
1752
// if the auto filter is used, use the format provided in the filename
1753
if (filter == autoFilter)
1743
1755
QString suffix;
1744
1756
if (targetUrl.isLocalFile())
1784
// use extension from the filter
1786
QString filterExtension = getExtensionFromFilter(filter);
1787
if (!filterExtension.isEmpty() &&
1788
validTypes.contains(filterExtension, Qt::CaseInsensitive))
1790
kDebug() << "Using format from filter extension: " << filterExtension;
1791
m_savingContext->format = filterExtension;
1770
1796
// another way to determine the format is to use the original file
1806
connect(imageFileSaveDialog, SIGNAL(filterChanged(const QString&)),
1807
options, SLOT(slotImageFileFormatChanged(const QString&)));
1809
connect(imageFileSaveDialog, SIGNAL(fileSelected(const QString &)),
1810
options, SLOT(slotImageFileSelected(const QString&)));
1831
options->setDialog(imageFileSaveDialog);
1812
1833
ImageDialogPreview *preview = new ImageDialogPreview(imageFileSaveDialog);
1813
1834
imageFileSaveDialog->setPreviewWidget(preview);
1816
1837
imageFileSaveDialog->setMode(KFile::File);
1817
1838
imageFileSaveDialog->setCaption(i18n("New Image File Name"));
1840
// restore old settings for the dialog
1819
1841
QFileInfo info(m_savingContext->srcURL.fileName());
1820
1842
KSharedConfig::Ptr config = KGlobal::config();
1821
1843
KConfigGroup group = config->group("ImageViewer Settings");
1822
QString ext = group.readEntry("LastSavedImageTypeMime", "png");
1844
const QString optionLastExtension = "LastSavedImageExtension";
1845
QString ext = group.readEntry(optionLastExtension, "png");
1823
1850
QString fileName = info.completeBaseName() + QString(".") + ext;
1825
1852
// Determine the default filter from LastSavedImageTypeMime
1826
1853
QStringList writablePattern = getWritingFilters();
1827
1854
imageFileSaveDialog->setFilter(writablePattern.join(QChar('\n')));
1828
QString initialFilter = findFilterByExtension(writablePattern, ext);
1829
if (!initialFilter.isEmpty())
1831
imageFileSaveDialog->filterWidget()->setCurrentFilter(initialFilter);
1835
kWarning() << "Could not find a filter for extension " << ext
1836
<< ". Is this really writable?";
1838
kDebug() << "Using initial filter '" << initialFilter
1839
<< "' out of all possible ones:" << writablePattern;
1856
// find the correct spelling of the auto filter
1857
// XXX bad assumption that the "all images" filter is always the first
1858
imageFileSaveDialog->filterWidget()->setCurrentFilter(writablePattern.at(0));
1859
QString autoFilter = imageFileSaveDialog->filterWidget()->currentFilter();
1860
options->setAutoFilter(autoFilter);
1840
1862
imageFileSaveDialog->setSelection(fileName);
1842
options->slotImageFileFormatChanged(ext);
1844
1864
// Start dialog and check if canceled.
1845
if ( imageFileSaveDialog->exec() != KFileDialog::Accepted )
1865
if (imageFileSaveDialog->exec() != KFileDialog::Accepted)
1848
1870
// Update file save settings in editor instance.
1849
1871
options->applySettings();
1853
1875
kDebug() << "Writing file to " << newURL;
1855
1877
// select the format to save the image with
1856
kDebug() << "filter from save dialog: " << imageFileSaveDialog->currentFilter();
1857
QString dialogExtension = getExtensionFromFilter(imageFileSaveDialog->currentFilter());
1858
kDebug() << "extracted extension from filter: " << dialogExtension;
1859
bool validFormatSet = selectValidSavingFormat(dialogExtension, newURL);
1878
bool validFormatSet = selectValidSavingFormat(imageFileSaveDialog->currentFilter(), newURL, autoFilter);
1861
1880
if (!validFormatSet)
1876
group.writeEntry("LastSavedImageTypeMime", m_savingContext->format);
1895
group.writeEntry(optionLastExtension, m_savingContext->format);
1877
1896
config->sync();
1879
1898
// if new and original URL are equal use slotSave() ------------------------------