Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Fix some QUrl / mimetypes issues

parent 55826189
......@@ -417,7 +417,7 @@ void RenderWidget::slotUpdateButtons(const QUrl &url)
} else {
updateButtons(); // This also checks whether the selected format is available
}
if (!url.isEmpty()) {
if (url.isValid()) {
QListWidgetItem *item = m_view.size_list->currentItem();
if (!item) {
m_view.buttonRender->setEnabled(false);
......@@ -1465,7 +1465,7 @@ void RenderWidget::refreshView(const QString &profile)
QUrl RenderWidget::filenameWithExtension(QUrl url, const QString &extension)
{
if (url.isEmpty()) url = QUrl(m_projectFolder);
if (!url.isValid()) url = QUrl(m_projectFolder);
QString directory = url.adjusted(QUrl::RemoveFilename).path();
QString filename = url.fileName();
QString ext;
......
......@@ -84,7 +84,7 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin
}
QUrl url = QUrl(xml.attribute("resource"));
if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
if (!m_properties.contains("file_hash") && url.isValid()) getFileHash(url.path());
if (xml.hasAttribute("duration")) {
setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
......@@ -1060,7 +1060,7 @@ void DocClipBase::getFileHash(const QString &url)
bool DocClipBase::checkHash() const
{
QUrl url = fileURL();
if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
if (url.isValid() && getClipHash() != getHash(url.path())) return false;
return true;
}
......
......@@ -606,7 +606,7 @@ void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int)
//|| t == TITLE_IMAGE_ELEMENT) {
QUrl url = KUrlRequesterDialog::getUrl(item->text(1), m_dialog, i18n("Enter new location for file"));
if (url.isEmpty()) return;
if (!url.isValid()) return;
item->setText(1, url.path());
if (QFile::exists(url.path())) {
item->setIcon(0, QIcon::fromTheme("dialog-ok"));
......
......@@ -135,7 +135,7 @@ KdenliveDoc::KdenliveDoc(const QUrl &url, const QUrl &projectFolder, QUndoGroup
*openBackup = false;
if (!url.isEmpty()) {
if (url.isValid()) {
QFile file(url.path());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// The file cannot be opened
......@@ -1063,7 +1063,7 @@ void KdenliveDoc::setUrl(const QUrl &url)
void KdenliveDoc::setModified(bool mod)
{
if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
if (m_url.isValid() && mod && KdenliveSettings::crashrecovery()) {
m_autoSaveTimer->start(3000);
}
if (mod == m_modified) return;
......@@ -1078,10 +1078,10 @@ bool KdenliveDoc::isModified() const
const QString KdenliveDoc::description() const
{
if (m_url.isEmpty())
return i18n("Untitled") + " / " + m_profile.description;
if (!m_url.isValid())
return i18n("Untitled") + "[*] / " + m_profile.description;
else
return m_url.fileName() + " / " + m_profile.description;
return m_url.fileName() + " [*]/ " + m_profile.description;
}
bool KdenliveDoc::addClip(QDomElement elem, const QString &clipId, bool createClipItem)
......
......@@ -102,7 +102,7 @@ void KThumb::updateClipUrl(const QUrl &url, const QString &hash)
//static
QPixmap KThumb::getImage(const QUrl &url, int width, int height)
{
if (url.isEmpty()) return QPixmap();
if (!url.isValid()) return QPixmap();
return getImage(url, 0, width, height);
}
......@@ -145,7 +145,7 @@ QPixmap KThumb::getImage(const QUrl &url, int frame, int width, int height)
{
Mlt::Profile profile(KdenliveSettings::current_profile().toUtf8().constData());
QPixmap pix(width, height);
if (url.isEmpty()) return pix;
if (!url.isValid()) return pix;
Mlt::Producer *producer = new Mlt::Producer(profile, url.path().toUtf8().constData());
double swidth = (double) profile.width() / profile.height();
pix = QPixmap::fromImage(getFrame(producer, frame, (int) (height * swidth + 0.5), width, height));
......@@ -289,7 +289,7 @@ uint KThumb::imageVariance(const QImage &image )
/*
void KThumb::getImage(QUrl url, int frame, int width, int height)
{
if (url.isEmpty()) return;
if (!url.isValid()) return;
QPixmap image(width, height);
Mlt::Producer m_producer(url.path().toUtf8().constData());
image.fill(Qt::black);
......@@ -317,7 +317,7 @@ void KThumb::getImage(QUrl url, int frame, int width, int height)
void KThumb::getThumbs(QUrl url, int startframe, int endframe, int width, int height)
{
if (url.isEmpty()) return;
if (!url.isValid()) return;
QPixmap image(width, height);
Mlt::Producer m_producer(url.path().toUtf8().constData());
image.fill(QColor(Qt::black).rgb());
......
......@@ -897,7 +897,7 @@ void DvdWizard::slotAbort()
void DvdWizard::slotSave()
{
QUrl url = QFileDialog::getSaveFileUrl(this, i18n("Save DVD Project"), QUrl("kfiledialog:///projectfolder"), "*.kdvd");
if (url.isEmpty())
if (!url.isValid())
return;
if (currentId() == 0)
......@@ -933,8 +933,8 @@ void DvdWizard::slotSave()
void DvdWizard::slotLoad()
{
const QUrl url = QFileDialog::getOpenFileUrl(this, QString(), QUrl("kfiledialog:///projectfolder"), "*.kdvd");
if (url.isEmpty())
const QUrl url = QFileDialog::getOpenFileUrl(this, QString(), QUrl("kfiledialog:///projectfolder"), i18n("DVD project (*.kdvd)"));
if (!url.isValid())
return;
QDomDocument doc;
QFile file(url.path());
......
......@@ -174,8 +174,8 @@ void DvdWizardVob::slotAddVobList(const QList<QUrl> &list)
void DvdWizardVob::slotAddVobFile(QUrl url, const QString &chapters, bool checkFormats)
{
if (url.isEmpty()) url = QFileDialog::getOpenFileUrl(this, i18n("Add new video file"), QUrl("kfiledialog:///projectfolder"), "video/mpeg");
if (url.isEmpty()) return;
if (!url.isValid()) url = QFileDialog::getOpenFileUrl(this, i18n("Add new video file"), QUrl("kfiledialog:///projectfolder"), i18n("MPEG clip (*.mpeg)"));
if (!url.isValid()) return;
QFile f(url.path());
qint64 fileSize = f.size();
......
......@@ -559,7 +559,7 @@ void MainWindow::generateClip()
KdenliveDoc *project = pCore->projectManager()->current();
QUrl clipUrl = iGenerator->generatedClip(KdenliveSettings::rendererpath(), action->data().toString(), project->projectFolder(),
QStringList(), QStringList(), project->fps(), project->width(), project->height());
if (!clipUrl.isEmpty()) {
if (clipUrl.isValid()) {
m_projectList->slotAddClip(QList <QUrl> () << clipUrl);
}
}
......@@ -1085,7 +1085,7 @@ void MainWindow::setupActions()
QAction *pasteEffects = addAction("paste_effects", i18n("Paste Effects"), this, SLOT(slotPasteEffects()), QIcon::fromTheme("edit-paste"));
pasteEffects->setData("paste_effects");
m_saveAction = KStandardAction::save(pCore->projectManager(), SLOT(saveFile()), actionCollection());
m_saveAction = KStandardAction::save(pCore->projectManager(), SLOT(saveFile()), actionCollection());
KStandardAction::quit(this, SLOT(close()), actionCollection());
// TODO: make the following connection to slotEditKeys work
//KStandardAction::keyBindings(this, SLOT(slotEditKeys()), actionCollection());
......@@ -3076,8 +3076,8 @@ void MainWindow::slotSaveTimelineClip()
m_messageLabel->setMessage(i18n("Select a clip to save"), InformationMessage);
return;
}
QUrl url = QFileDialog::getSaveFileUrl(this, i18n("Save clip"), pCore->projectManager()->current()->projectFolder(), "video/mlt-playlist");
if (!url.isEmpty()) {
QUrl url = QFileDialog::getSaveFileUrl(this, i18n("Save clip"), pCore->projectManager()->current()->projectFolder(), i18n("MLT playlist (*.mlt)"));
if (url.isValid()) {
m_projectMonitor->render->saveClip(pCore->projectManager()->current()->tracksCount() - clip->track(), clip->startPos(), url);
}
}
......
......@@ -507,7 +507,7 @@ ClipProperties::ClipProperties(DocClipBase *clip, const Timecode &tc, double fps
// Check for Nepomuk metadata
#ifdef USE_NEPOMUK
#if KDE_IS_VERSION(4,6,0)
if (!url.isEmpty()) {
if (url.isValid()) {
Nepomuk::ResourceManager::instance()->init();
Nepomuk::Resource res( url.path() );
// Check if file has a license
......@@ -528,7 +528,7 @@ ClipProperties::ClipProperties(DocClipBase *clip, const Timecode &tc, double fps
#else
#ifdef USE_NEPOMUKCORE
if (!url.isEmpty()) {
if (url.isValid()) {
Nepomuk2::ResourceManager::instance()->init();
Nepomuk2::Resource res( url.path() );
// Check if file has a license
......@@ -927,7 +927,7 @@ void ClipProperties::slotDeleteAnalysis()
void ClipProperties::slotSaveAnalysis()
{
const QString url = QFileDialog::getSaveFileName(this, i18n("Save Analysis Data"), "kfiledialog:///projectfolder", "text/plain");
const QString url = QFileDialog::getSaveFileName(this, i18n("Save Analysis Data"), "kfiledialog:///projectfolder", i18n("Text File (*.txt)"));
if (url.isEmpty())
return;
KSharedConfigPtr config = KSharedConfig::openConfig(url, KConfig::SimpleConfig);
......@@ -938,7 +938,7 @@ void ClipProperties::slotSaveAnalysis()
void ClipProperties::slotLoadAnalysis()
{
const QString url = QFileDialog::getOpenFileName(this, i18n("Open Analysis Data"), "kfiledialog:///projectfolder", "text/plain");
const QString url = QFileDialog::getOpenFileName(this, i18n("Open Analysis Data"), "kfiledialog:///projectfolder", i18n("Text File (*.txt)"));
if (url.isEmpty())
return;
KSharedConfigPtr config = KSharedConfig::openConfig(url, KConfig::SimpleConfig);
......
......@@ -29,7 +29,7 @@ BackupWidget::BackupWidget(const QUrl &projectUrl, const QUrl &projectFolder, co
setupUi(this);
setWindowTitle(i18n("Restore Backup File"));
if (projectUrl.isEmpty()) {
if (!projectUrl.isValid()) {
// No url, means we opened the backup dialog from an empty project
info_label->setText(i18n("Showing all backup files in folder"));
m_projectWildcard = '*';
......
......@@ -210,7 +210,7 @@ void ProjectSettings::slotDeleteUnused()
DocClipBase *clip = list.at(i);
if (clip->numReferences() == 0 && clip->clipType() != SlideShow) {
QUrl url = clip->fileURL();
if (!url.isEmpty() && !toDelete.contains(url.path())) toDelete << url.path();
if (url.isValid() && !toDelete.contains(url.path())) toDelete << url.path();
}
}
......@@ -219,7 +219,7 @@ void ProjectSettings::slotDeleteUnused()
DocClipBase *clip = list.at(i);
if (clip->numReferences() > 0) {
QUrl url = clip->fileURL();
if (!url.isEmpty() && toDelete.contains(url.path())) toDelete.removeAll(url.path());
if (url.isValid() && toDelete.contains(url.path())) toDelete.removeAll(url.path());
}
}
......
......@@ -641,7 +641,7 @@ void ProjectList::trashUnusedClips()
if (item->numReferences() == 0) {
ids << item->clipId();
QUrl url = item->clipUrl();
if (!url.isEmpty() && !urls.contains(url.path()))
if (url.isValid() && !urls.contains(url.path()))
urls << url.path();
}
it++;
......@@ -657,7 +657,7 @@ void ProjectList::trashUnusedClips()
item = static_cast <ProjectItem *>(*it2);
if (item->numReferences() > 0) {
QUrl url = item->clipUrl();
if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
if (url.isValid() && urls.contains(url.path())) urls.removeAll(url.path());
}
it2++;
}
......@@ -1348,7 +1348,7 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
QUrl url = clip->fileURL();
#ifdef USE_NEPOMUK
if (!url.isEmpty() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
if (url.isValid() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
// if file has Nepomuk comment, use it
Nepomuk::Resource f(url.path());
QString annotation = f.description();
......@@ -1705,7 +1705,8 @@ void ProjectList::slotAddClip(const QList <QUrl> &givenList, const QString &grou
QList <QUrl> list;
if (givenList.isEmpty()) {
QString allExtensions = getExtensions().join(" ");
const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
qDebug()<<"*********\nEXTENSIONS: "<<allExtensions<<"\n********************";
const QString dialogFilter = i18n("All Supported Files") + "(" + allExtensions + ");;" + i18n("All Files") + "(*)";
QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
b->setChecked(KdenliveSettings::autoimagesequence());
QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
......
......@@ -62,7 +62,7 @@ ProjectManager::~ProjectManager()
void ProjectManager::init(const QUrl& projectUrl, const QString& clipList)
{
if (!projectUrl.isEmpty()) {
if (projectUrl.isValid()) {
// delay loading so that the window shows up
m_startUrl = projectUrl;
QTimer::singleShot(500, this, SLOT(openFile()));
......@@ -255,16 +255,15 @@ bool ProjectManager::saveFile()
void ProjectManager::openFile()
{
if (!m_startUrl.isEmpty()) {
if (m_startUrl.isValid()) {
openFile(m_startUrl);
m_startUrl = QUrl();
return;
}
QUrl url = QFileDialog::getOpenFileUrl(0, QString(), QUrl("kfiledialog:///projectfolder"), getMimeType());
if (url.isEmpty()) {
QUrl url = QFileDialog::getOpenFileUrl(QApplication::activeWindow(), QString(), QUrl("kfiledialog:///projectfolder"), getMimeType());
if (url.isValid()) {
return;
}
m_recentFilesAction->addUrl(url);
openFile(url);
}
......@@ -296,7 +295,7 @@ void ProjectManager::openFile(const QUrl &url)
QPointer<ArchiveWidget> ar = new ArchiveWidget(url);
if (ar->exec() == QDialog::Accepted) {
openFile(QUrl(ar->extractedProjectFile()));
} else if (!m_startUrl.isEmpty()) {
} else if (m_startUrl.isValid()) {
// we tried to open an invalid file from command line, init new project
newFile(false);
}
......@@ -307,7 +306,7 @@ void ProjectManager::openFile(const QUrl &url)
if (!url.fileName().endsWith(".kdenlive")) {
// This is not a Kdenlive project file, abort loading
KMessageBox::sorry(pCore->window(), i18n("File %1 is not a Kdenlive project file", url.path()));
if (!m_startUrl.isEmpty()) {
if (m_startUrl.isValid()) {
// we tried to open an invalid file from command line, init new project
newFile(false);
}
......@@ -450,15 +449,8 @@ void ProjectManager::slotRevert()
QString ProjectManager::getMimeType(bool open)
{
QMimeDatabase db;
QString mimetype = "application/x-kdenlive";
QMimeType mime = db.mimeTypeForName(mimetype);
if (!mime.isValid()) {
mimetype = "*.kdenlive";
if (open) mimetype.append(" *.tar.gz");
}
else if (open) mimetype.append(" application/x-compressed-tar");
QString mimetype = i18n("Kdenlive project (*.kdenlive)");
if (open) mimetype.append(";;" + i18n("Archived project (*.tar.gz)"));
return mimetype;
}
......@@ -473,7 +465,7 @@ void ProjectManager::slotOpenBackup(const QUrl& url)
QUrl projectFile;
QUrl projectFolder;
QString projectId;
if (!url.isEmpty()) {
if (url.isValid()) {
// we could not open the project file, guess where the backups are
projectFolder = QUrl(KdenliveSettings::defaultprojectfolder());
projectFile = url;
......
......@@ -668,7 +668,7 @@ void Render::processFileProperties()
producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + info.xml.attribute("resource")).toUtf8().constData());
if (producer && producer->is_valid() && info.xml.hasAttribute("xmldata"))
producer->set("xmldata", info.xml.attribute("xmldata").toUtf8().constData());
} else if (url.isEmpty()) {
} else if (!url.isValid()) {
//WARNING: when is this case used? Not sure it is working.. JBM/
QDomDocument doc;
QDomElement mlt = doc.createElement("mlt");
......
......@@ -449,7 +449,7 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, const QString &pro
// scale the view so that the title widget is not too big at startup
graphicsView->scale(.5, .5);
if (!url.isEmpty()) {
if (url.isValid()) {
loadTitle(url);
} else {
prepareTools(NULL);
......@@ -651,7 +651,7 @@ void TitleWidget::slotImageTool()
// TODO: find a way to get a list of all supported image types...
QString allExtensions = "image/gif image/jpeg image/png image/x-tga image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr";
QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Load Image"), QUrl(), allExtensions); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
if (!url.isEmpty()) {
if (url.isValid()) {
if (url.path().endsWith(QLatin1String(".svg"))) {
QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
......@@ -1683,8 +1683,8 @@ void TitleWidget::itemRight()
void TitleWidget::loadTitle(QUrl url)
{
if (url.isEmpty()) url = QFileDialog::getOpenFileUrl(this, i18n("Load Title"), QUrl(m_projectTitlePath), "application/x-kdenlivetitle");
if (!url.isEmpty()) {
if (!url.isValid()) url = QFileDialog::getOpenFileUrl(this, i18n("Load Title"), QUrl(m_projectTitlePath), i18n("Kdenlive title (*.kdenlivetitle)"));
if (url.isValid()) {
QList<QGraphicsItem *> items = m_scene->items();
for (int i = 0; i < items.size(); ++i) {
if (items.at(i)->zValue() > -1000) delete items.at(i);
......@@ -1735,7 +1735,7 @@ void TitleWidget::saveTitle(QUrl url)
{
embed_image=false;
}
if (url.isEmpty()) {
if (!url.isValid()) {
QPointer<QFileDialog> fs = new QFileDialog(this, i18n("Save Title"), m_projectTitlePath, "application/x-kdenlivetitle");
fs->setFileMode(QFileDialog::AnyFile);
//TODO: KF5 porting?
......@@ -1746,7 +1746,7 @@ void TitleWidget::saveTitle(QUrl url)
}
delete fs;
}
if (!url.isEmpty()) {
if (url.isValid()) {
if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()), embed_image) == false)
KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
}
......
......@@ -243,7 +243,6 @@ void ResourceWidget::slotPlaySound()
void ResourceWidget::slotSaveItem(const QString &originalUrl)
{
//if (m_currentUrl.isEmpty()) return;
QListWidgetItem *item = search_results->currentItem();
if (!item) return;
QString path = m_folder;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment