~ubuntu-branches/ubuntu/maverick/digikam/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Luka Renko
  • Date: 2009-12-22 21:38:14 UTC
  • mfrom: (1.2.26 upstream)
  • Revision ID: james.westby@ubuntu.com-20091222213814-dtgz0u1068y5rql7
Tags: 2:1.0.0-1ubuntu1
* Merge with Debian, remaining changes:
  - Export .pot name and copy to plugins in debian/rules
  - Build-depend on libkipi7-dev, libkexiv2-8-dev and 
    libkdcraw8-dev (KDE 4.3 -> 4.4)
* Build-depend on liblqr-1-0-dev: now in main (LP: #493508)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 *
23
23
 * ============================================================ */
24
24
 
25
 
//#include "editorwindow.h"
26
25
#include "editorwindow_p.h"
27
26
#include "editorwindow.moc"
28
27
 
51
50
 
52
51
// KDE includes
53
52
 
 
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>
 
58
#endif
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>
937
939
        }
938
940
    }
939
941
    else
 
942
    {
940
943
        m_IOFileSettings->rawDecodingSettings.outputColorSpace = DRawDecoding::SRGB;
 
944
    }
941
945
 
942
946
    m_IOFileSettings->rawDecodingSettings.sixteenBitsImage        = group.readEntry("SixteenBitsImage", false);
943
947
    m_IOFileSettings->rawDecodingSettings.whiteBalance            = (DRawDecoding::WhiteBalance)group.readEntry("WhiteBalance",
1217
1221
 
1218
1222
}
1219
1223
 
 
1224
void EditorWindow::slotUndoStateChanged(bool moreUndo, bool moreRedo, bool canSave)
 
1225
{
 
1226
    m_revertAction->setEnabled(canSave);
 
1227
    m_undoAction->setEnabled(moreUndo);
 
1228
    m_redoAction->setEnabled(moreRedo);
 
1229
    m_saveAction->setEnabled(hasChangesToSave());
 
1230
 
 
1231
    if (!moreUndo)
 
1232
        m_rotatedOrFlipped = false;
 
1233
}
 
1234
 
 
1235
bool EditorWindow::hasChangesToSave()
 
1236
{
 
1237
    // virtual, can be extended by subclasses
 
1238
    return m_canvas->hasChangesToSave();
 
1239
}
 
1240
 
1220
1241
bool EditorWindow::promptUserSave(const KUrl& url, SaveOrSaveAs saveOrSaveAs, bool allowCancel)
1221
1242
{
1222
 
    if (m_saveAction->isEnabled())
 
1243
    if (hasChangesToSave())
1223
1244
    {
1224
1245
        // if window is minimized, show it
1225
1246
        if (isMinimized())
1569
1590
void EditorWindow::setupTempSaveFile(const KUrl & url)
1570
1591
{
1571
1592
 
 
1593
#ifdef _WIN32
 
1594
    KUrl parent(url.directory(KUrl::AppendTrailingSlash)); 
 
1595
    QString tempDir = parent.toLocalFile();
 
1596
#else
1572
1597
    QString tempDir = url.directory(KUrl::AppendTrailingSlash);
 
1598
#endif
 
1599
 
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()
1627
1654
{
1628
1655
 
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;
1633
1660
 
1634
 
    // remove "all images" type
1635
 
    // XXX bad assumption that this is always the first type in the list
1636
 
    writablePattern.removeFirst();
1637
 
 
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();
1687
1710
    }
1688
1711
 
1689
 
    const int endLocation = filter.indexOf(QRegExp("[|\\* ]"), asteriskLocation + 1);
 
1712
    int endLocation = filter.indexOf(QRegExp("[|\\* ]"), asteriskLocation + 1);
1690
1713
    if (endLocation < 0)
1691
1714
    {
1692
 
        kDebug() << "Could not find a valid end of the format in the filter";
1693
 
        return QString();
 
1715
        endLocation = filter.length();
1694
1716
    }
1695
1717
 
1696
1718
    kDebug() << "astriskLocation = " << asteriskLocation
1705
1727
 
1706
1728
}
1707
1729
 
1708
 
bool EditorWindow::selectValidSavingFormat(const QString& filterExtension, const KUrl& targetUrl)
 
1730
bool EditorWindow::selectValidSavingFormat(const QString& filter,
 
1731
                const KUrl& targetUrl, const QString &autoFilter)
1709
1732
{
1710
1733
 
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;
1713
1736
 
1714
1737
    // build a list of valid types
1715
1738
    QStringList validTypes = KImageIO::types(KImageIO::Writing);
1726
1749
 
1727
1750
    kDebug() << "Writable formats: " << validTypes;
1728
1751
 
1729
 
    // first check if the selected filter extension can be used
1730
 
    {
1731
 
        if (!filterExtension.isEmpty() &&
1732
 
            validTypes.contains(filterExtension, Qt::CaseInsensitive))
1733
 
        {
1734
 
            kDebug() << "Using format from filter extension: " << filterExtension;
1735
 
            m_savingContext->format = filterExtension;
1736
 
            return true;
1737
 
        }
1738
 
    }
1739
 
 
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)
1742
1754
    {
1743
1755
        QString suffix;
1744
1756
        if (targetUrl.isLocalFile())
1766
1778
            return true;
1767
1779
        }
1768
1780
    }
 
1781
    else
 
1782
    {
 
1783
 
 
1784
        // use extension from the filter
 
1785
 
 
1786
        QString filterExtension = getExtensionFromFilter(filter);
 
1787
        if (!filterExtension.isEmpty() &&
 
1788
            validTypes.contains(filterExtension, Qt::CaseInsensitive))
 
1789
        {
 
1790
            kDebug() << "Using format from filter extension: " << filterExtension;
 
1791
            m_savingContext->format = filterExtension;
 
1792
            return true;
 
1793
        }
 
1794
    }
1769
1795
 
1770
1796
    // another way to determine the format is to use the original file
1771
1797
    {
1802
1828
                                                       QString(),
1803
1829
                                                       this,
1804
1830
                                                       options);
1805
 
 
1806
 
    connect(imageFileSaveDialog, SIGNAL(filterChanged(const QString&)),
1807
 
            options, SLOT(slotImageFileFormatChanged(const QString&)));
1808
 
 
1809
 
    connect(imageFileSaveDialog, SIGNAL(fileSelected(const QString &)),
1810
 
            options, SLOT(slotImageFileSelected(const QString&)));
 
1831
    options->setDialog(imageFileSaveDialog);
1811
1832
 
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"));
1818
1839
 
 
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");
 
1846
    if (ext.isEmpty())
 
1847
    {
 
1848
        ext = "png";
 
1849
    }
1823
1850
    QString fileName          = info.completeBaseName() + QString(".") + ext;
1824
1851
 
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())
1830
 
    {
1831
 
        imageFileSaveDialog->filterWidget()->setCurrentFilter(initialFilter);
1832
 
    }
1833
 
    else
1834
 
    {
1835
 
        kWarning() << "Could not find a filter for extension " << ext
1836
 
                   << ". Is this really writable?";
1837
 
    }
1838
 
    kDebug() << "Using initial filter '" << initialFilter
1839
 
             << "' out of all possible ones:" << writablePattern;
 
1855
 
 
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);
 
1861
 
1840
1862
    imageFileSaveDialog->setSelection(fileName);
1841
1863
 
1842
 
    options->slotImageFileFormatChanged(ext);
1843
 
 
1844
1864
    // Start dialog and check if canceled.
1845
 
    if ( imageFileSaveDialog->exec() != KFileDialog::Accepted )
 
1865
    if (imageFileSaveDialog->exec() != KFileDialog::Accepted)
 
1866
    {
1846
1867
       return false;
 
1868
    }
1847
1869
 
1848
1870
    // Update file save settings in editor instance.
1849
1871
    options->applySettings();
1853
1875
    kDebug() << "Writing file to " << newURL;
1854
1876
 
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);
1860
1879
 
1861
1880
    if (!validFormatSet)
1862
1881
    {
1873
1892
        return false;
1874
1893
    }
1875
1894
 
1876
 
    group.writeEntry("LastSavedImageTypeMime", m_savingContext->format);
 
1895
    group.writeEntry(optionLastExtension, m_savingContext->format);
1877
1896
    config->sync();
1878
1897
 
1879
1898
    // if new and original URL are equal use slotSave() ------------------------------