]> git.sesse.net Git - kdenlive/commitdiff
Better feedback when opening archived project
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 10 May 2011 20:51:55 +0000 (20:51 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 10 May 2011 20:51:55 +0000 (20:51 +0000)
svn path=/trunk/kdenlive/; revision=5585

src/archivewidget.cpp
src/archivewidget.h
src/widgets/archivewidget_ui.ui

index 1641e6d3765193361be5d07af53ca0324a060658..4d9477f1ad66f4713559362a6115d372aecda5d8 100644 (file)
@@ -183,30 +183,10 @@ ArchiveWidget::ArchiveWidget(const KUrl &url, QWidget * parent):
     m_extractUrl(url)
 {
     //setAttribute(Qt::WA_DeleteOnClose);
-    m_extractArchive = new KTar(url.path());
-    m_extractArchive->open( QIODevice::ReadOnly );
 
-    // Check that it is a kdenlive project archive
-    bool isProjectArchive = false;
-    QStringList files = m_extractArchive->directory()->entries();
-    for (int i = 0; i < files.count(); i++) {
-        if (files.at(i).endsWith(".kdenlive")) {
-            m_projectName = files.at(i);
-            isProjectArchive = true;
-            break;
-        }
-    }
-
-    if (!isProjectArchive) {
-        KMessageBox::sorry(kapp->activeWindow(), i18n("%1 is not an archived Kdenlive project", url.path(), i18n("Cannot open file")));
-        m_extractArchive->close();
-        hide();
-        //HACK: find a better way to terminate the dialog
-        QTimer::singleShot(50, this, SLOT(reject()));
-        return;
-    }
     setupUi(this);
     connect(this, SIGNAL(extractingFinished()), this, SLOT(slotExtractingFinished()));
+    connect(this, SIGNAL(showMessage(const QString &, const QString &)), this, SLOT(slotDisplayMessage(const QString &, const QString &)));
     
     compressed_archive->setHidden(true);
     project_files->setHidden(true);
@@ -216,6 +196,9 @@ ArchiveWidget::ArchiveWidget(const KUrl &url, QWidget * parent):
     archive_url->setUrl(KUrl(QDir::homePath()));
     buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Extract"));
     connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotStartExtracting()));
+    buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
+    adjustSize();
+    m_archiveThread = QtConcurrent::run(this, &ArchiveWidget::openArchiveForExtraction);
 }
 
 
@@ -224,6 +207,42 @@ ArchiveWidget::~ArchiveWidget()
     if (m_extractArchive) delete m_extractArchive;
 }
 
+void ArchiveWidget::slotDisplayMessage(const QString &icon, const QString &text)
+{
+    icon_info->setPixmap(KIcon(icon).pixmap(16, 16));
+    text_info->setText(text);
+}
+
+void ArchiveWidget::openArchiveForExtraction()
+{
+    emit showMessage("system-run", i18n("Opening archive..."));
+    m_extractArchive = new KTar(m_extractUrl.path());
+    if (!m_extractArchive->isOpen() && !m_extractArchive->open( QIODevice::ReadOnly )) {
+        emit showMessage("dialog-close", i18n("Cannot open archive file:\n %1", m_extractUrl.path()));
+        groupBox->setEnabled(false);
+        return;
+    }
+
+    // Check that it is a kdenlive project archive
+    bool isProjectArchive = false;
+    QStringList files = m_extractArchive->directory()->entries();
+    for (int i = 0; i < files.count(); i++) {
+        if (files.at(i).endsWith(".kdenlive")) {
+            m_projectName = files.at(i);
+            isProjectArchive = true;
+            break;
+        }
+    }
+
+    if (!isProjectArchive) {
+        emit showMessage("dialog-close", i18n("File %1\n is not an archived Kdenlive project", m_extractUrl.path()));
+        groupBox->setEnabled(false);
+        return;
+    }
+    buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
+    emit showMessage("dialog-ok", i18n("Ready"));
+}
+
 void ArchiveWidget::done ( int r )
 {
     if (closeAccepted()) QDialog::done(r);
@@ -325,13 +344,11 @@ void ArchiveWidget::slotCheckSpace()
     if (freeSize > m_requestedSize) {
         // everything is ok
         buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
-        icon_info->setPixmap(KIcon("dialog-ok").pixmap(16, 16));
-        text_info->setText(i18n("Available space on drive: %1", KIO::convertSize(freeSize)));
+        slotDisplayMessage("dialog-ok", i18n("Available space on drive: %1", KIO::convertSize(freeSize)));
     }
     else {
         buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
-        icon_info->setPixmap(KIcon("dialog-close").pixmap(16, 16));
-        text_info->setText(i18n("Not enough space on drive, free space: %1", KIO::convertSize(freeSize)));
+        slotDisplayMessage("dialog-close", i18n("Not enough space on drive, free space: %1", KIO::convertSize(freeSize)));
     }
 }
 
@@ -352,8 +369,7 @@ bool ArchiveWidget::slotStartArchiving(bool firstPass)
         m_replacementList.clear();
         m_foldersList.clear();
         m_filesList.clear();
-        icon_info->setPixmap(KIcon("system-run").pixmap(16, 16));
-        text_info->setText(i18n("Archiving..."));
+        slotDisplayMessage("system-run", i18n("Archiving..."));
         repaint();
         archive_url->setEnabled(false);
         compressed_archive->setEnabled(false);
@@ -462,19 +478,16 @@ void ArchiveWidget::slotArchivingFinished(KJob *job)
             // Archiving finished
             progressBar->setValue(100);
             if (processProjectFile()) {
-                icon_info->setPixmap(KIcon("dialog-ok").pixmap(16, 16));
-                text_info->setText(i18n("Project was successfully archived."));
+                slotDisplayMessage("dialog-ok", i18n("Project was successfully archived."));
             }
             else {
-                icon_info->setPixmap(KIcon("dialog-close").pixmap(16, 16));
-                text_info->setText(i18n("There was an error processing project file"));
+                slotDisplayMessage("dialog-close", i18n("There was an error processing project file"));
             }
         } else processProjectFile();
     }
     else {
         m_copyJob = NULL;
-        icon_info->setPixmap(KIcon("dialog-close").pixmap(16, 16));
-        text_info->setText(i18n("There was an error while copying the files: %1", job->errorString()));
+        slotDisplayMessage("dialog-close", i18n("There was an error while copying the files: %1", job->errorString()));
     }
     if (!compressed_archive->isChecked()) {
         buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Archive"));
@@ -655,12 +668,10 @@ void ArchiveWidget::createArchive()
 void ArchiveWidget::slotArchivingFinished(bool result)
 {
     if (result) {
-        icon_info->setPixmap(KIcon("dialog-ok").pixmap(16, 16));
-        text_info->setText(i18n("Project was successfully archived."));
+        slotDisplayMessage("dialog-ok", i18n("Project was successfully archived."));
     }
     else {
-        icon_info->setPixmap(KIcon("dialog-close").pixmap(16, 16));
-        text_info->setText(i18n("There was an error processing project file"));
+        slotDisplayMessage("dialog-close", i18n("There was an error processing project file"));
     }
     progressBar->setValue(100);
     buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Archive"));
@@ -687,8 +698,7 @@ void ArchiveWidget::slotStartExtracting()
     QFileInfo f(m_extractUrl.path());
     m_requestedSize = f.size();
     KIO::NetAccess::mkdir(archive_url->url().path(KUrl::RemoveTrailingSlash), this);
-    icon_info->setPixmap(KIcon("system-run").pixmap(16, 16));
-    text_info->setText(i18n("Extracting..."));
+    slotDisplayMessage("system-run", i18n("Extracting..."));
     buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Abort"));
     m_progressTimer = new QTimer;
     m_progressTimer->setInterval(800);
index 5903937e0431c31430e8083260e74502437e4142..e76aa669255c604749797f57666629cb32a62695 100644 (file)
@@ -33,7 +33,7 @@
 #include <KTemporaryFile>
 
 class KJob;
-class KTar;
+class KArchive;
 
 /**
  * @class ArchiveWidget
@@ -68,6 +68,8 @@ private slots:
     void slotExtractingFinished();
     void slotExtractProgress();
     void slotGotProgress(KJob*);
+    void openArchiveForExtraction();
+    void slotDisplayMessage(const QString &icon, const QString &text);
 
 protected:
     virtual void closeEvent ( QCloseEvent * e );
@@ -88,7 +90,7 @@ private:
     KUrl m_extractUrl;
     QString m_projectName;
     QTimer *m_progressTimer;
-    KTar *m_extractArchive;
+    KArchive *m_extractArchive;
 
     /** @brief Generate tree widget subitems from a string list of urls. */
     void generateItems(QTreeWidgetItem *parentItem, QStringList items);
@@ -99,6 +101,7 @@ signals:
     void archivingFinished(bool);
     void archiveProgress(int);
     void extractingFinished();
+    void showMessage(const QString &, const QString &);
 };
 
 
index 46a48a0eb68f3bb4d62c2879cb5ecd4e6eec548f..24966d7e752a4435c6ca5cd89fc569e59e252529 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>263</width>
-    <height>210</height>
+    <height>197</height>
    </rect>
   </property>
   <property name="windowTitle">
   </property>
   <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0" colspan="2">
-    <layout class="QHBoxLayout" name="horizontalLayout_2">
-     <item>
-      <widget class="QLabel" name="label">
-       <property name="text">
-        <string>Archive folder</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="KUrlRequester" name="archive_url">
-       <property name="mode">
-        <set>KFile::Directory</set>
-       </property>
-      </widget>
-     </item>
-    </layout>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string/>
+     </property>
+     <property name="flat">
+      <bool>true</bool>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_2">
+      <property name="margin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Archive folder</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="KUrlRequester" name="archive_url">
+        <property name="mode">
+         <set>KFile::Directory</set>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item row="1" column="0" colspan="2">
+    <widget class="QCheckBox" name="compressed_archive">
+     <property name="text">
+      <string>Compressed archive</string>
+     </property>
+    </widget>
    </item>
    <item row="2" column="0" colspan="2">
     <layout class="QHBoxLayout" name="horizontalLayout">
      </property>
     </widget>
    </item>
-   <item row="5" column="0">
-    <widget class="QProgressBar" name="progressBar">
-     <property name="value">
-      <number>0</number>
-     </property>
-    </widget>
-   </item>
-   <item row="5" column="1">
-    <widget class="QDialogButtonBox" name="buttonBox">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="standardButtons">
-      <set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set>
-     </property>
-    </widget>
-   </item>
    <item row="4" column="0" colspan="2">
     <widget class="QTreeWidget" name="files_list">
      <property name="alternatingRowColors">
      </column>
     </widget>
    </item>
-   <item row="1" column="0" colspan="2">
-    <widget class="QCheckBox" name="compressed_archive">
-     <property name="text">
-      <string>Compressed archive</string>
+   <item row="5" column="0">
+    <widget class="QProgressBar" name="progressBar">
+     <property name="value">
+      <number>0</number>
+     </property>
+    </widget>
+   </item>
+   <item row="5" column="1">
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set>
      </property>
     </widget>
    </item>