Skip to content

Commit

Permalink
fixed file dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrd2 committed Mar 12, 2015
1 parent fd74830 commit 7fbe777
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 198 deletions.
6 changes: 3 additions & 3 deletions .copyright.sh
Expand Up @@ -8,17 +8,17 @@ fi
TEXT=':a;N;$!ba;s/\/\*[^\/]+Copyright([^\/]+|[^\*]\/)+\*\//\/**\
* Copyright (C) 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>\
* Copyright (C) 2010-2015 Mladen Milinkovic <max@smoothware.net>\
* \
*\
* This program is free software; you can redistribute it and\/or modify\
* it under the terms of the GNU General Public License as published by\
* the Free Software Foundation; either version 2 of the License, or\
* (at your option) any later version.\
* \
*\
* This program is distributed in the hope that it will be useful,\
* but WITHOUT ANY WARRANTY; without even the implied warranty of\
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\
* GNU General Public License for more details.\
* \
*\
* You should have received a copy of the GNU General Public License\
* along with this program; if not, write to the\
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\
Expand Down
1 change: 1 addition & 0 deletions src/main/CMakeLists.txt
Expand Up @@ -47,6 +47,7 @@ target_link_libraries(subtitlecomposer
KF5::CoreAddons KF5::WidgetsAddons KF5::TextWidgets KF5::Codecs
KF5::SonnetCore KF5::SonnetUi
KF5::KrossCore KF5::KrossUi
KF5::KIOCore KF5::KIOFileWidgets KF5::KIOWidgets KF5::KIONTLM
KF5::KDELibs4Support
${common_LIBS}
${core_LIBS}
Expand Down
35 changes: 24 additions & 11 deletions src/main/actions/krecentfilesactionext.cpp
@@ -1,17 +1,17 @@
/**
* Copyright (C) 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
* Copyright (C) 2010-2015 Mladen Milinkovic <max@smoothware.net>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Expand Down Expand Up @@ -84,10 +84,12 @@ KRecentFilesActionExt::count() const
QString
KRecentFilesActionExt::encodingForUrl(const QUrl &url) const
{
// TODO: mmmm?
return QString();
// QAction *action = actionForUrl(url);
// return action ? m_urls[action].fileEncoding() : QString();
QAction *action = actionForUrl(url);
if(action) {
QRegExp rx("encoding=([^&]*)");
return rx.indexIn(url.query()) == -1 ? "" : rx.cap(1);
}
return "";
}

QList<QUrl>
Expand All @@ -111,7 +113,11 @@ KRecentFilesActionExt::setUrls(const QList<QUrl> &urls)
if(actionForUrl(*it))
continue;

QAction *action = new QAction(entryText.arg(it->fileName()).arg(it->toString(QUrl::PreferLocalFile)), selectableActionGroup());
QString path(it->path());
int n = path.lastIndexOf('/');
if(n != -1)
path.chop(path.length() - n - 1);
QAction *action = new QAction(entryText.arg(it->fileName()).arg(path), selectableActionGroup());

m_urls[*it] = action;

Expand Down Expand Up @@ -164,9 +170,16 @@ KRecentFilesActionExt::clearUrls()
}

QAction *
KRecentFilesActionExt::actionForUrl(const QUrl &url) const
{
return m_urls[url];
KRecentFilesActionExt::actionForUrl(QUrl url) const
{
url.setQuery(QString());
for(QMap<QUrl, QAction *>::const_iterator it = m_urls.begin(); it != m_urls.end(); it++) {
QUrl key = it.key();
key.setQuery(QString());
if(key == url)
return *it;
}
return NULL;
}

void
Expand Down
8 changes: 4 additions & 4 deletions src/main/actions/krecentfilesactionext.h
Expand Up @@ -4,17 +4,17 @@
/**
* Copyright (C) 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
* Copyright (C) 2010-2015 Mladen Milinkovic <max@smoothware.net>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Expand Down Expand Up @@ -68,7 +68,7 @@ public slots:
void urlSelected(const QUrl &url);

protected:
virtual QAction * actionForUrl(const QUrl &url) const;
virtual QAction * actionForUrl(QUrl url) const;

protected slots:
void onActionTriggered(QAction *action);
Expand Down
57 changes: 29 additions & 28 deletions src/main/application.cpp
Expand Up @@ -327,7 +327,7 @@ Application::saveConfig()
{
KConfigGroup group(KGlobal::config()->group("Application Settings"));

group.writePathEntry("LastSubtitleUrl", m_lastSubtitleUrl.toString(QUrl::PreferLocalFile));
group.writePathEntry("LastSubtitleUrl", m_lastSubtitleUrl.toString());
m_recentSubtitlesAction->saveEntries(KGlobal::config()->group("Recent Subtitles"));
m_recentSubtitlesTrAction->saveEntries(KGlobal::config()->group("Recent Translation Subtitles"));

Expand Down Expand Up @@ -1287,23 +1287,24 @@ Application::redo()
QTextCodec *
Application::codecForUrl(const QUrl &url, bool useRecentFiles, bool useDefault)
{
// QString encoding = url.fileEncoding();
QRegExp rx("encoding=([^&]*)");
QString encoding = rx.indexIn(url.query()) == -1 ? "" : rx.cap(1);

// if(useRecentFiles) {
// if(encoding.isEmpty())
// m_recentSubtitlesAction->encodingForUrl(url);
// if(encoding.isEmpty())
// encoding = m_recentSubtitlesTrAction->encodingForUrl(url);
// }
if(useRecentFiles) {
if(encoding.isEmpty())
m_recentSubtitlesAction->encodingForUrl(url);
if(encoding.isEmpty())
encoding = m_recentSubtitlesTrAction->encodingForUrl(url);
}

QTextCodec *codec = 0;

// if(!encoding.isEmpty()) {
// bool codecFound = false;
// codec = KGlobal::charsets()->codecForName(encoding, codecFound);
// if(!codecFound)
// codec = 0;
// }
if(!encoding.isEmpty()) {
bool codecFound = false;
codec = KGlobal::charsets()->codecForName(encoding, codecFound);
if(!codecFound)
codec = 0;
}

if(!codec && useDefault)
codec = QTextCodec::codecForName(SCConfig::defaultSubtitlesEncoding().toLatin1());
Expand Down Expand Up @@ -1364,19 +1365,19 @@ Application::newSubtitle()
void
Application::openSubtitle()
{
OpenSubtitleDialog openDlg(true, m_lastSubtitleUrl.toString(QUrl::PreferLocalFile), QString());
OpenSubtitleDialog openDlg(true, m_lastSubtitleUrl, QString());

if(openDlg.exec() == QDialog::Accepted) {
if(!acceptClashingUrls(openDlg.selectedUrls().first(), m_subtitleTrUrl))
if(!acceptClashingUrls(openDlg.selectedUrl(), m_subtitleTrUrl))
return;

if(!closeSubtitle())
return;

m_lastSubtitleUrl = openDlg.selectedUrls().first();
m_lastSubtitleUrl = openDlg.selectedUrl();

QUrl fileUrl = m_lastSubtitleUrl;
// fileUrl.setFileEncoding(openDlg.selectedEncoding());
fileUrl.setQuery("encoding=" + openDlg.selectedEncoding());
openSubtitle(fileUrl);
}
}
Expand All @@ -1393,7 +1394,7 @@ Application::openSubtitle(const QUrl &url, bool warnClashingUrls)
QTextCodec *codec = codecForUrl(url, true, false);

QUrl fileUrl = url;
// fileUrl.setFileEncoding(QString());
fileUrl.setQuery(QString());

m_subtitle = new Subtitle();

Expand All @@ -1409,7 +1410,7 @@ Application::openSubtitle(const QUrl &url, bool warnClashingUrls)
m_subtitleFileName = QFileInfo(m_subtitleUrl.path()).fileName();
m_subtitleEncoding = codec->name();

// fileUrl.setFileEncoding(codec->name());
fileUrl.setQuery("encoding=" + codec->name());
m_recentSubtitlesAction->addUrl(fileUrl);

m_reopenSubtitleAsAction->setCurrentCodec(codec);
Expand Down Expand Up @@ -1551,10 +1552,10 @@ Application::saveSubtitleAs()
m_subtitleFormat);

if(saveDlg.exec() == QDialog::Accepted) {
if(!acceptClashingUrls(saveDlg.selectedUrls().first(), m_subtitleTrUrl))
if(!acceptClashingUrls(saveDlg.selectedUrl(), m_subtitleTrUrl))
return false;

m_subtitleUrl = saveDlg.selectedUrls().first();
m_subtitleUrl = saveDlg.selectedUrl();
m_subtitleFileName = QFileInfo(m_subtitleUrl.path()).completeBaseName();
m_subtitleEncoding = saveDlg.selectedEncoding();
m_subtitleFormat = saveDlg.selectedFormat();
Expand Down Expand Up @@ -1636,19 +1637,19 @@ Application::openSubtitleTr()
if(!m_subtitle)
return;

OpenSubtitleDialog openDlg(false, m_lastSubtitleUrl.toString(QUrl::PreferLocalFile), QString());
OpenSubtitleDialog openDlg(false, m_lastSubtitleUrl, QString());

if(openDlg.exec() == QDialog::Accepted) {
if(!acceptClashingUrls(m_subtitleUrl, openDlg.selectedUrls().first()))
if(!acceptClashingUrls(m_subtitleUrl, openDlg.selectedUrl()))
return;

if(!closeSubtitleTr())
return;

m_lastSubtitleUrl = openDlg.selectedUrls().first();
m_lastSubtitleUrl = openDlg.selectedUrl();

QUrl fileUrl = m_lastSubtitleUrl;
// fileUrl.setFileEncoding(openDlg.selectedEncoding());
fileUrl.setQuery("encoding=" + openDlg.selectedEncoding());
openSubtitleTr(fileUrl);
}
}
Expand Down Expand Up @@ -1802,10 +1803,10 @@ Application::saveSubtitleTrAs()
m_subtitleTrFormat);

if(saveDlg.exec() == QDialog::Accepted) {
if(!acceptClashingUrls(m_subtitleUrl, saveDlg.selectedUrls().first()))
if(!acceptClashingUrls(m_subtitleUrl, saveDlg.selectedUrl()))
return false;

m_subtitleTrUrl = saveDlg.selectedUrls().first();
m_subtitleTrUrl = saveDlg.selectedUrl();
m_subtitleTrFileName = QFileInfo(m_subtitleTrUrl.path()).completeBaseName();
m_subtitleTrEncoding = saveDlg.selectedEncoding();
m_subtitleTrFormat = saveDlg.selectedFormat();
Expand Down

0 comments on commit 7fbe777

Please sign in to comment.