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

Commit 2db5336f authored by Jeremy Whiting's avatar Jeremy Whiting

Port from KUrl to QUrl and KFileDialog to QFileDialog.

parent f3f24e28
......@@ -257,7 +257,7 @@ void KMouthApp::initPhraseList()
setCentralWidget(phraseList);
}
void KMouthApp::openDocumentFile(const KUrl& url)
void KMouthApp::openDocumentFile(const QUrl &url)
{
slotStatusMsg(i18n("Opening file..."));
......@@ -502,7 +502,7 @@ void KMouthApp::slotPhrasebookConfirmed()
QString standardBook = QStandardPaths::locate(QStandardPaths::DataLocation, QLatin1String("standard.phrasebook"));
if (!standardBook.isEmpty()) {
PhraseBook book;
book.open(KUrl(standardBook));
book.open(QUrl(standardBook));
QString name = QLatin1String("phrasebooks");
QMenu *popup = (QMenu *)factory()->container(name, this);
KToolBar *toolbar = toolBar(QLatin1String("phrasebookBar"));
......
......@@ -25,7 +25,7 @@
// include files for KDE
#include <ksharedconfig.h>
#include <kurl.h>
#include <QUrl>
#include <kxmlguiwindow.h>
// forward declaration of the KMouth classes
......@@ -65,7 +65,7 @@ public:
bool configured();
/** opens a file specified by commandline option
*/
void openDocumentFile(const KUrl& url = KUrl());
void openDocumentFile(const QUrl &url = QUrl());
TextToSpeechSystem *getTTSSystem() const;
......
......@@ -29,7 +29,7 @@
// include files for KDE
#include <KDialog>
#include <KLocalizedString>
#include <KUrl>
#include <QUrl>
#include <QDebug>
......@@ -121,7 +121,7 @@ void InitialPhraseBookWidget::createBook()
if (!bookLocation.isNull() && !bookLocation.isEmpty()) {
QDir().mkpath(bookLocation);
qDebug() << "creating book at location " << bookLocation;
book.save(KUrl(bookLocation + QLatin1String("standard.phrasebook")));
book.save(QUrl::fromLocalFile(bookLocation + QLatin1String("standard.phrasebook")));
}
}
......@@ -131,7 +131,7 @@ void InitialPhraseBookWidget::addChildrenToBook(PhraseBook &book, QStandardItem
QStandardItem *child = item->child(i);
if (child->checkState() != Qt::Unchecked) {
PhraseBook localBook;
if (localBook.open(KUrl(child->data().toString()))) {
if (localBook.open(QUrl(child->data().toString()))) {
book += localBook;
}
}
......
......@@ -19,6 +19,7 @@
#include "phrasebookparser.h"
#include <QFile>
#include <QFileDialog>
#include <QFontDatabase>
#include <QPainter>
#include <QRegExp>
......@@ -31,13 +32,12 @@
#include <KActionMenu>
#include <KActionCollection>
#include <KDesktopFile>
#include <KFileDialog>
#include <KLocalizedString>
#include <KMenu>
#include <KMessageBox>
#include <KToolBar>
#include <KTemporaryFile>
#include <KUrl>
#include <QUrl>
#include <kio/netaccess.h>
......@@ -232,7 +232,7 @@ QStringList PhraseBook::toStringList()
return result;
}
bool PhraseBook::save(const KUrl &url)
bool PhraseBook::save(const QUrl &url)
{
QRegExp pattern(QLatin1String("*.phrasebook"), Qt::CaseSensitive, QRegExp::Wildcard);
return save(url, pattern.exactMatch(url.fileName()));
......@@ -247,7 +247,7 @@ void PhraseBook::save(QTextStream &stream, bool asPhrasebook)
stream << toStringList().join(QLatin1String("\n"));
}
bool PhraseBook::save(const KUrl &url, bool asPhrasebook)
bool PhraseBook::save(const QUrl &url, bool asPhrasebook)
{
if (url.isLocalFile()) {
QFile file(url.path());
......@@ -274,27 +274,25 @@ bool PhraseBook::save(const KUrl &url, bool asPhrasebook)
}
}
int PhraseBook::save(QWidget *parent, const QString &title, KUrl &url, bool phrasebookFirst)
int PhraseBook::save(QWidget *parent, const QString &title, QUrl &url, bool phrasebookFirst)
{
// KFileDialog::getSaveUrl(...) is not useful here as we need
// to know the requested file type.
QString filters;
if (phrasebookFirst)
filters = i18n("*.phrasebook|Phrase Books (*.phrasebook)\n*.txt|Plain Text Files (*.txt)\n*|All Files");
filters = i18n("Phrase Books (*.phrasebook);;Plain Text Files (*.txt);;All Files (*)");
else
filters = i18n("*.txt|Plain Text Files (*.txt)\n*.phrasebook|Phrase Books (*.phrasebook)\n*|All Files");
filters = i18n("Plain Text Files (*.txt);;Phrase Books (*.phrasebook);;All Files (*)");
QString empty;
KFileDialog fdlg(empty, filters, parent);
fdlg.setWindowTitle(title);
fdlg.setOperationMode(KFileDialog::Saving);
QFileDialog fdlg(parent, title, QString(), filters);
fdlg.setAcceptMode(QFileDialog::AcceptSave);
if (fdlg.exec() != QDialog::Accepted) {
if (fdlg.exec() != QDialog::Accepted || fdlg.selectedUrls().size() < 1) {
return 0;
}
url = fdlg.selectedUrl();
url = fdlg.selectedUrls().at(0);
if (url.isEmpty() || !url.isValid()) {
return -1;
......@@ -308,9 +306,10 @@ int PhraseBook::save(QWidget *parent, const QString &title, KUrl &url, bool phra
}
bool result;
if (fdlg.currentFilter() == QLatin1String("*.phrasebook")) {
if (fdlg.selectedNameFilter() == QLatin1String("*.phrasebook")) {
if (url.fileName(0).contains(QLatin1Char('.')) == 0) {
url.setFileName(url.fileName(0) + QLatin1String(".phrasebook"));
url = url.adjusted(QUrl::RemoveFilename);
url.setPath(url.path() + url.fileName(0) + QLatin1String(".phrasebook"));
} else if (url.fileName(0).right(11).contains(QLatin1String(".phrasebook"), Qt::CaseInsensitive) == 0) {
int filetype = KMessageBox::questionYesNoCancel(0, QString(QLatin1String("<qt>%1</qt>")).arg(i18n("Your chosen filename <i>%1</i> has a different extension than <i>.phrasebook</i>. "
"Do you wish to add <i>.phrasebook</i> to the filename?", url.fileName())), i18n("File Extension"), KGuiItem(i18n("Add")), KGuiItem(i18n("Do Not Add")));
......@@ -318,11 +317,12 @@ int PhraseBook::save(QWidget *parent, const QString &title, KUrl &url, bool phra
return 0;
}
if (filetype == KMessageBox::Yes) {
url.setFileName(url.fileName(0) + QLatin1String(".phrasebook"));
url = url.adjusted(QUrl::RemoveFilename);
url.setPath(url.path() + url.fileName(0) + QLatin1String(".phrasebook"));
}
}
result = save(url, true);
} else if (fdlg.currentFilter() == QLatin1String("*.txt")) {
} else if (fdlg.selectedNameFilter() == QLatin1String("*.txt")) {
if (url.fileName(0).right(11).contains(QLatin1String(".phrasebook"), Qt::CaseInsensitive) == 0) {
result = save(url, false);
} else {
......@@ -346,14 +346,14 @@ int PhraseBook::save(QWidget *parent, const QString &title, KUrl &url, bool phra
return -1;
}
bool PhraseBook::open(const KUrl &url)
bool PhraseBook::open(const QUrl &url)
{
QString tempFile;
KUrl fileUrl = url;
QUrl fileUrl = url;
QString protocol = fileUrl.protocol();
QString protocol = fileUrl.scheme();
if (protocol.isEmpty() || protocol.isNull()) {
fileUrl.setProtocol(QLatin1String("file"));
fileUrl.setScheme(QLatin1String("file"));
fileUrl.setPath(url.url());
}
......@@ -361,6 +361,8 @@ bool PhraseBook::open(const KUrl &url)
QStringList list = QStringList();
// First: try to load it as a normal phrase book
qDebug() << "opening file " << tempFile
<< " downloaded from " << fileUrl.toString();
QFile file(tempFile);
QXmlInputSource source(&file);
bool error = !decode(source);
......@@ -414,7 +416,7 @@ StandardBookList PhraseBook::standardPhraseBooks()
for (it = bookPaths.begin(); it != bookPaths.end(); ++it) {
PhraseBook pbook;
// Open the phrasebook.
if (pbook.open(KUrl(*it))) {
if (pbook.open(QUrl(*it))) {
StandardBook book;
book.name = (*pbook.begin()).getPhrase().getPhrase();
......
......@@ -29,7 +29,7 @@
#include <KIcon>
#include <KToolBar>
class KUrl;
class QUrl;
struct StandardBook {
QString name;
......@@ -107,7 +107,7 @@ public:
~PhraseBook() {}
/** opens a file containing a phrase book. Returns true if successful. */
bool open(const KUrl &url);
bool open(const QUrl &url);
/** decodes a phrase book. Returns true if successful. */
bool decode(const QString &xml);
......@@ -116,10 +116,10 @@ public:
bool decode(QXmlInputSource &source);
/** Writes the phrases to a file. Returns true if successful. */
bool save(const KUrl &url);
bool save(const QUrl &url);
/** Writes the phrases to a file. Returns true if successful. */
bool save(const KUrl &url, bool asPhrasebook);
bool save(const QUrl &url, bool asPhrasebook);
/** Writes the phrases to a QTextStream. */
void save(QTextStream &stream, bool asPhrasebook);
......@@ -132,7 +132,7 @@ public:
* 0, if the user canceled the operation,
* -1, if there was an error when saving the file.
*/
int save(QWidget *parent, const QString &title, KUrl &url, bool phrasebookFirst = true);
int save(QWidget *parent, const QString &title, QUrl &url, bool phrasebookFirst = true);
/** encodes the phrase book. Returns the encoded xml code. */
QString encode();
......
......@@ -19,19 +19,21 @@
// include files for Qt
#include <QClipboard>
#include <QFileDialog>
#include <QMimeData>
#include <QStack>
#include <QStandardPaths>
// include files for KDE
#include <KActionMenu>
#include <KFileDialog>
#include <KMessageBox>
#include <KToolBarPopupAction>
#include <KXMLGUIFactory>
#include "phrasebook.h"
#include <QDebug>
const int kTextColumn = 0;
const int kShortcutColumn = 1;
......@@ -50,12 +52,12 @@ const QString kWholeBookXML = QLatin1String("<?xml version=\"1.0\" encoding=\"UT
const QIcon kPhraseBookIcon = KIcon(kPhraseBook);
const QIcon kPhraseIcon = KIcon(kPhrase);
StandardPhraseBookInsertAction::StandardPhraseBookInsertAction(const KUrl &url, const QString& name, const QObject* receiver, const char* slot, KActionCollection* parent)
StandardPhraseBookInsertAction::StandardPhraseBookInsertAction(const QUrl &url, const QString& name, const QObject* receiver, const char* slot, KActionCollection* parent)
: QAction(KIcon(QLatin1String("phrasebook")), name, parent)
{
this->url = url;
connect(this, SIGNAL(triggered(bool)), this, SLOT(slotActivated()));
connect(this, SIGNAL(slotActivated(const KUrl &)), receiver, slot);
connect(this, SIGNAL(slotActivated(const QUrl &)), receiver, slot);
parent->addAction(name, this);
}
......@@ -301,8 +303,7 @@ void PhraseBookDialog::initStandardPhraseBooks()
QStack<KActionMenu *> stack;
StandardBookList::iterator it;
for (it = bookPaths.begin(); it != bookPaths.end(); ++it) {
KUrl url;
url.setPath((*it).filename);
QUrl url = QUrl::fromLocalFile((*it).filename);
QString namePath = QLatin1String("x") + (*it).path;
QStringList dirs = namePath.split(QLatin1Char('/'));
......@@ -326,7 +327,7 @@ void PhraseBookDialog::initStandardPhraseBooks()
currentNamePath = dirs;
QAction *book = new StandardPhraseBookInsertAction(
url, (*it).name, this, SLOT(slotImportPhrasebook(KUrl)), actionCollection());
url, (*it).name, this, SLOT(slotImportPhrasebook(QUrl)), actionCollection());
parent->addAction(book);
if (parent == fileImportStandardBook)
toolbarImport->menu()->addAction(book);
......@@ -623,13 +624,13 @@ void PhraseBookDialog::slotSave()
void PhraseBookDialog::slotImportPhrasebook()
{
KUrl url = KFileDialog::getOpenUrl(KUrl(),
i18n("*.phrasebook|Phrase Books (*.phrasebook)\n*.txt|Plain Text Files (*.txt)\n*|All Files"), this, i18n("Import Phrasebook"));
QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Import Phrasebook"), QUrl(),
i18n("Phrase Books (*.phrasebook);Plain Text Files (*.txt);All Files (*)"));
slotImportPhrasebook(url);
}
void PhraseBookDialog::slotImportPhrasebook(const KUrl &url)
void PhraseBookDialog::slotImportPhrasebook(const QUrl &url)
{
if (!url.isEmpty()) {
QModelIndex parentIndex = getCurrentParent();
......@@ -654,6 +655,7 @@ void PhraseBookDialog::slotImportPhrasebook(const KUrl &url)
}
focusNewItem(parentIndex, item);
} else {
qDebug() << "Unable to open file " << url.toLocalFile();
KMessageBox::sorry(this, i18n("There was an error loading file\n%1", url.toLocalFile()));
}
}
......@@ -665,14 +667,14 @@ void PhraseBookDialog::slotExportPhrasebook()
QModelIndex parentIndex = getCurrentParent();
QString content = kWholeBookXML.arg(serializeBook(parentIndex));
KUrl url = KFileDialog::getSaveFileName(KUrl(), QLatin1String("*.phrasebook"), this, i18n("Export Phrase Book"));
QUrl url = QFileDialog::getSaveFileUrl(this, i18n("Export Phrase Book"), QUrl(), QLatin1String("Phrase Books (*.phrasebook)"));
QFile file(url.toLocalFile());
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << content;
file.close();
} else {
KMessageBox::sorry(this, i18n("There was an error saving file\n%1", url.url()));
KMessageBox::sorry(this, i18n("There was an error saving file\n%1", url.toLocalFile()));
}
}
......
......@@ -23,7 +23,7 @@
#include <QAction>
#include <KIcon>
#include <KUrl>
#include <QUrl>
#include <KXmlGuiWindow>
//#include "phrasebook.h"
......@@ -41,17 +41,17 @@ class StandardPhraseBookInsertAction : public QAction
{
Q_OBJECT
public:
StandardPhraseBookInsertAction(const KUrl &url, const QString& name, const QObject* receiver, const char* slot, KActionCollection* parent);
StandardPhraseBookInsertAction(const QUrl &url, const QString& name, const QObject* receiver, const char* slot, KActionCollection* parent);
~StandardPhraseBookInsertAction();
public slots:
void slotActivated();
signals:
void slotActivated(const KUrl &url);
void slotActivated(const QUrl &url);
private:
KUrl url;
QUrl url;
};
/**
......@@ -100,7 +100,7 @@ public slots:
void slotSave();
void slotImportPhrasebook();
void slotImportPhrasebook(const KUrl &url);
void slotImportPhrasebook(const QUrl &url);
void slotExportPhrasebook();
//void slotPrint ();
......
......@@ -42,6 +42,7 @@
#include <KXMLGUIFactory>
#include <kfiledialog.h>
#include <QFileDialog>
PhraseList::PhraseList(QWidget *parent, const char *name) : QWidget(parent)
{
......@@ -467,21 +468,21 @@ void PhraseList::save()
book += PhraseBookEntry(Phrase(item->text()));
}
KUrl url;
QUrl url;
if (book.save(this, i18n("Save As"), url, false) == -1)
KMessageBox::sorry(this, i18n("There was an error saving file\n%1", url.url()));
}
void PhraseList::open()
{
KUrl url = KFileDialog::getOpenUrl(KUrl(),
i18n("*|All Files\n*.phrasebook|Phrase Books (*.phrasebook)\n*.txt|Plain Text Files (*.txt)"), this, i18n("Open File as History"));
QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Open File as History"), QUrl(),
i18n("All Files (*);;Phrase Books (*.phrasebook);;Plain Text Files (*.txt)"));
if (!url.isEmpty())
open(url);
}
void PhraseList::open(KUrl url)
void PhraseList::open(QUrl url)
{
// We want to open a history of spoken sentences here. However, as
// the class PhraseBook does already provide a method for opening
......
......@@ -19,7 +19,7 @@
#define PHRASELIST_H
// include files for KDE
#include <KUrl>
#include <QUrl>
// include files for Qt
#include <QWidget>
......@@ -78,7 +78,7 @@ public slots:
void save();
void open();
void open(KUrl url);
void open(QUrl url);
void selectAllEntries();
void deselectAllEntries();
......
......@@ -27,7 +27,7 @@
#include <KFileDialog>
#include <KLocalizedString>
#include <KMessageBox>
#include <KUrl>
#include <QUrl>
#include <kio/netaccess.h>
#include "dictionarycreationwizard.h"
......@@ -205,7 +205,7 @@ void WordCompletionWidget::exportDictionary()
const QStandardItem *nameItem = model->item(dictionaryView->currentIndex().row(), 0);
if (nameItem != 0) {
KUrl url = KFileDialog::getSaveUrl(QString(), QString(), this, i18n("Export Dictionary"));
QUrl url = QFileDialog::getSaveFileUrl(this, i18n("Export Dictionary"));
if (url.isEmpty() || !url.isValid())
return;
......@@ -215,7 +215,7 @@ void WordCompletionWidget::exportDictionary()
return;
}
}
KUrl src;
QUrl src;
src.setPath(QStandardPaths::locate(QStandardPaths::DataLocation, nameItem->data().toString()));
KIO::NetAccess::file_copy(src, url, this);
}
......
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