diff --git a/src/main/startup/KexiNewProjectAssistant.cpp b/src/main/startup/KexiNewProjectAssistant.cpp index 5eae13226..827a55911 100644 --- a/src/main/startup/KexiNewProjectAssistant.cpp +++ b/src/main/startup/KexiNewProjectAssistant.cpp @@ -1,703 +1,703 @@ /* This file is part of the KDE project Copyright (C) 2003-2018 Jarosław Staniek Copyright (C) 2012 Dimitrios T. Tanis Copyright (C) 2014 Roman Shtemberko This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KexiNewProjectAssistant.h" #include "ui_KexiServerDBNamePage.h" #include "KexiAssistantMessageHandler.h" #include "KexiTemplatesModel.h" #include "KexiStartupFileHandler.h" #include "KexiStartup.h" #include "KexiPasswordPage.h" #include #include #include #include #include #include #include #include #include -#include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class KexiServerDBNamePage : public QWidget, public Ui::KexiServerDBNamePage { Q_OBJECT public: explicit KexiServerDBNamePage(QWidget* parent = 0); }; KexiServerDBNamePage::KexiServerDBNamePage(QWidget* parent) : QWidget(parent) { setupUi(this); } // ---- KexiTemplateSelectionPage::KexiTemplateSelectionPage(QWidget* parent) : KexiAssistantPage(xi18nc("@title:window", "New Project"), xi18nc("@info", "Kexi will create a new database project. Select blank database."), //! @todo Change to this when templates work: "Kexi will create a new database project. Select blank database or template.", parent) { m_templatesList = new KexiCategorizedView; setRecentFocusWidget(m_templatesList); m_templatesList->setFrameShape(QFrame::NoFrame); m_templatesList->setContentsMargins(0, 0, 0, 0); int margin = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, 0) + KexiUtils::marginHint(); //not needed in grid: m_templatesList->setSpacing(margin); m_templatesList->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); connect(m_templatesList, SIGNAL(activated(QModelIndex)), this, SLOT(slotItemClicked(QModelIndex))); KexiTemplateCategoryInfoList templateCategories; KexiTemplateCategoryInfo templateCategory; templateCategory.name = "blank"; templateCategory.caption = xi18n("Blank Projects"); KexiTemplateInfo info; info.name = "blank"; info.caption = xi18n("Blank database"); info.description = xi18n("Database project without any objects"); info.icon = KexiIcon("document-empty"); templateCategory.addTemplate(info); templateCategories.append(templateCategory); #ifdef KEXI_SHOW_UNIMPLEMENTED templateCategory = KexiTemplateCategoryInfo(); templateCategory.name = "office"; templateCategory.caption = futureI18n("Office Templates"); info = KexiTemplateInfo(); info.name = "contacts"; info.caption = xi18n("Contacts"); info.description = futureI18n("Database for collecting and managing contacts"); info.icon = koIcon("view-pim-contacts"); templateCategory.addTemplate(info); info = KexiTemplateInfo(); info.name = "movie"; info.caption = xi18n("Movie catalog"); info.description = futureI18n("Database for collecting movies"); info.icon = koIcon("video-x-generic"); templateCategory.addTemplate(info); templateCategories.append(templateCategory); #endif // KEXI_SHOW_UNIMPLEMENTED KexiTemplatesProxyModel* proxyModel = new KexiTemplatesProxyModel(m_templatesList); KexiTemplatesModel* model = new KexiTemplatesModel(templateCategories); proxyModel->setSourceModel(model); m_templatesList->setModel(proxyModel); //qDebug() << "templatesCategoryDrawer:" << m_templatesList->categoryDrawer(); setContents(m_templatesList); } void KexiTemplateSelectionPage::slotItemClicked(const QModelIndex& index) { if (!index.isValid()) return; selectedTemplate = index.data(KexiTemplatesModel::NameRole).toString(); selectedCategory = index.data(KexiTemplatesModel::CategoryRole).toString(); m_templatesList->clearSelection(); //! @todo support templates if (selectedTemplate == "blank" && selectedCategory == "blank") { next(); return; } KEXI_UNFINISHED(xi18n("Templates")); } // ---- KexiProjectStorageTypeSelectionPage::KexiProjectStorageTypeSelectionPage(QWidget* parent) : KexiAssistantPage(xi18nc("@title:window", "Storage Method"), xi18nc("@info", "Select a storage method which will be used to store the new project."), parent) { setBackButtonVisible(true); QWidget* contents = new QWidget; setupUi(contents); const int dsize = IconSize(KIconLoader::Desktop); btn_file->setIcon(Kexi::defaultFileBasedDriverIcon()); btn_file->setIconSize(QSize(dsize, dsize)); connect(btn_file, SIGNAL(clicked()), this, SLOT(buttonClicked())); btn_server->setIcon(Kexi::serverIcon()); btn_server->setIconSize(QSize(dsize, dsize)); connect(btn_server, SIGNAL(clicked()), this, SLOT(buttonClicked())); setRecentFocusWidget(btn_file); setContents(contents); } KexiProjectStorageTypeSelectionPage::~KexiProjectStorageTypeSelectionPage() { } void KexiProjectStorageTypeSelectionPage::buttonClicked() { next(); } KexiProjectStorageTypeSelectionPage::Type KexiProjectStorageTypeSelectionPage::selectedType() const { const QWidget *w = focusWidget(); if (w == btn_file) { return Type::File; } else if (w == btn_server) { return Type::Server; } return Type::None; } // ---- static QString defaultDatabaseName() { return xi18n("New database"); } -KexiProjectTitleSelectionPage::KexiProjectTitleSelectionPage(QWidget* parent) +KexiProjectCaptionSelectionPage::KexiProjectCaptionSelectionPage(QWidget* parent) : KexiAssistantPage(xi18nc("@title:window", "Project Caption & Filename"), xi18nc("@info", "Enter caption for the new project. " "Filename will be created automatically based on the caption. " "You can change the filename too."), parent) { setBackButtonVisible(true); setNextButtonVisible(true); - contents = new KexiDBTitlePage(QString()); + contents = new KexiDBCaptionPage(QString()); contents->formLayout->setSpacing(KexiUtils::spacingHint()); - contents->le_title->setText(defaultDatabaseName()); - contents->le_title->selectAll(); - connect(contents->le_title, SIGNAL(textChanged(QString)), - this, SLOT(titleTextChanged(QString))); + contents->le_caption->setText(defaultDatabaseName()); + contents->le_caption->selectAll(); + connect(contents->le_caption, &KLineEdit::textChanged, this, + &KexiProjectCaptionSelectionPage::captionTextChanged); fileHandler = new KexiStartupFileHandler( QUrl("kfiledialog:///OpenExistingOrCreateNewProject"), KexiFileFilters::SavingFileBasedDB, contents->file_requester); fileHandler->setDefaultExtension("kexi"); connect(fileHandler, SIGNAL(askForOverwriting(KexiContextMessage)), this, SLOT(askForOverwriting(KexiContextMessage))); updateUrl(); setContents(contents); - setRecentFocusWidget(contents->le_title); + setRecentFocusWidget(contents->le_caption); } -KexiProjectTitleSelectionPage::~KexiProjectTitleSelectionPage() +KexiProjectCaptionSelectionPage::~KexiProjectCaptionSelectionPage() { delete fileHandler; } -void KexiProjectTitleSelectionPage::askForOverwriting(const KexiContextMessage& message) +void KexiProjectCaptionSelectionPage::askForOverwriting(const KexiContextMessage& message) { qDebug() << message.text(); delete messageWidget; messageWidget = new KexiContextMessageWidget(this, contents->formLayout, contents->file_requester, message); - messageWidget->setNextFocusWidget(contents->le_title); + messageWidget->setNextFocusWidget(contents->le_caption); } -void KexiProjectTitleSelectionPage::titleTextChanged(const QString & text) +void KexiProjectCaptionSelectionPage::captionTextChanged(const QString &text) { Q_UNUSED(text); updateUrl(); } -void KexiProjectTitleSelectionPage::updateUrl() +void KexiProjectCaptionSelectionPage::updateUrl() { - fileHandler->updateUrl(contents->le_title->text()); + fileHandler->updateUrl(contents->le_caption->text()); } -bool KexiProjectTitleSelectionPage::isAcceptable() +bool KexiProjectCaptionSelectionPage::isAcceptable() { delete messageWidget; - if (contents->le_title->text().trimmed().isEmpty()) { + if (contents->le_caption->text().trimmed().isEmpty()) { messageWidget = new KexiContextMessageWidget(contents->formLayout, - contents->le_title, + contents->le_caption, xi18n("Enter project caption.")); - contents->le_title->setText(QString()); + contents->le_caption->setText(QString()); return false; } QUrl url = contents->file_requester->url(); QFileInfo fileInfo(contents->file_requester->text()); if (fileInfo.dir().isRelative()) { messageWidget = new KexiContextMessageWidget(contents->formLayout, contents->file_requester, xi18nc("@info", "%1 is a relative path." "Enter absolute path of a file to be created.", fileInfo.filePath())); return false; } if (!url.isValid() || !url.isLocalFile() || url.fileName().isEmpty()) { messageWidget = new KexiContextMessageWidget(contents->formLayout, contents->file_requester, xi18n("Enter a valid project filename. The file should be located on this computer.")); return false; } if (fileInfo.isDir()) { messageWidget = new KexiContextMessageWidget(contents->formLayout, contents->file_requester, xi18nc("@info", "%1 is a directory name." "Enter name of a file to be created.", fileInfo.filePath())); return false; } if (!fileHandler->checkSelectedUrl()) { return false; }; QFileInfo writableChecker(fileInfo.dir().path()); if (!writableChecker.isWritable()) { messageWidget = new KexiContextMessageWidget(contents->formLayout, contents->file_requester, xi18nc("@info","Could not create database file %1." "There is no permission to create this file. " "Pick another directory or change permissions so the file can be created.", contents->file_requester->url().toLocalFile())); return false; } //urlSelected(url); // to save recent dir return true; } // ---- KexiProjectCreationPage::KexiProjectCreationPage(QWidget* parent) : KexiAssistantPage(xi18nc("@title:window", "Creating Project"), xi18nc("@info", "Please wait while the project is created."), parent) { QVBoxLayout *vlyr = new QVBoxLayout; QHBoxLayout *lyr = new QHBoxLayout; vlyr->addLayout(lyr); m_progressBar = new QProgressBar; m_progressBar->setRange(0, 0); lyr->addWidget(m_progressBar); lyr->addStretch(1); //! @todo add cancel vlyr->addStretch(1); setContents(vlyr); } KexiProjectCreationPage::~KexiProjectCreationPage() { } // ---- KexiProjectConnectionSelectionPage::KexiProjectConnectionSelectionPage(QWidget* parent) : KexiAssistantPage(xi18nc("@title:window", "Database Connection"), xi18nc("@info", "Select database server's connection you wish to use to " "create a new Kexi project." "Here you may also add, edit or delete connections " "from the list."), parent) { setBackButtonVisible(true); setNextButtonVisible(true); if (KDbDriverManager().hasDatabaseServerDrivers()) { QVBoxLayout *lyr = new QVBoxLayout; connSelector = new KexiConnectionSelectorWidget( &Kexi::connset(), QUrl("kfiledialog:///OpenExistingOrCreateNewProject"), KexiConnectionSelectorWidget::Saving); lyr->addWidget(connSelector); connSelector->showAdvancedConnection(); connect(connSelector, SIGNAL(connectionItemExecuted(ConnectionDataLVItem*)), this, SLOT(next())); connSelector->layout()->setContentsMargins(0, 0, 0, 0); connSelector->hideHelpers(); connSelector->hideDescription(); setContents(lyr); setRecentFocusWidget(connSelector->connectionsList()); } else { setDescription(QString()); setNextButtonVisible(false); m_errorMessagePopup = new KexiServerDriverNotFoundMessage(this); setContents(m_errorMessagePopup); layout()->setAlignment(m_errorMessagePopup, Qt::AlignTop); m_errorMessagePopup->setAutoDelete(false); m_errorMessagePopup->animatedShow(); } } KexiProjectConnectionSelectionPage::~KexiProjectConnectionSelectionPage() { } // ---- KexiProjectDatabaseNameSelectionPage::KexiProjectDatabaseNameSelectionPage( KexiNewProjectAssistant* parent) : KexiAssistantPage(xi18nc("@title:window", "Project Caption & Database Name"), xi18nc("@info", "Enter caption for the new project. " "Database name will be created automatically based on the caption. " "You can change the database name too."), parent) , conndataToShow(0) , m_assistant(parent) { m_projectDataToOverwrite = 0; m_messageWidgetActionYes = 0; m_messageWidgetActionNo = new QAction(KStandardGuiItem::no().text(), this); setBackButtonVisible(true); setNextButtonVisible(true); nextButton()->setLinkText(xi18n("Create")); m_projectSetToShow = 0; m_dbNameAutofill = true; m_le_dbname_txtchanged_enabled = true; contents = new KexiServerDBNamePage; - connect(contents->le_title, SIGNAL(textChanged(QString)), - this, SLOT(slotTitleChanged(QString))); + connect(contents->le_caption, &KLineEdit::textChanged, this, + &KexiProjectDatabaseNameSelectionPage::slotCaptionChanged); connect(contents->le_dbname, SIGNAL(textChanged(QString)), this, SLOT(slotNameChanged(QString))); - connect(contents->le_title, SIGNAL(returnPressed()), - this, SLOT(next())); + connect(contents->le_caption, &KLineEdit::returnPressed, + this, &KexiProjectDatabaseNameSelectionPage::next); connect(contents->le_dbname, SIGNAL(returnPressed()), this, SLOT(next())); - contents->le_title->setText(defaultDatabaseName()); - contents->le_title->selectAll(); + contents->le_caption->setText(defaultDatabaseName()); + contents->le_caption->selectAll(); KDbIdentifierValidator *idValidator = new KDbIdentifierValidator(this); idValidator->setLowerCaseForced(true); contents->le_dbname->setValidator(idValidator); m_projectSelector = new KexiProjectSelectorWidget( contents->frm_dblist, 0, true, // showProjectNameColumn false // showConnectionColumns ); m_projectSelector->setFocusPolicy(Qt::NoFocus); m_projectSelector->setSelectable(false); m_projectSelector->list()->setFrameStyle(QFrame::NoFrame); GLUE_WIDGET(m_projectSelector, contents->frm_dblist); contents->layout()->setContentsMargins(0, 0, 0, 0); m_projectSelector->layout()->setContentsMargins(0, 0, 0, 0); setContents(contents); - setRecentFocusWidget(contents->le_title); + setRecentFocusWidget(contents->le_caption); } KexiProjectDatabaseNameSelectionPage::~KexiProjectDatabaseNameSelectionPage() { } bool KexiProjectDatabaseNameSelectionPage::setConnection(KDbConnectionData* data) { m_projectSelector->setProjectSet(0); conndataToShow = 0; if (data) { m_projectSetToShow = new KexiProjectSet(m_assistant->messageHandler()); KDbMessageGuard mg(m_projectSetToShow); if (!m_projectSetToShow->setConnectionData(data)) { m_projectSetToShow = 0; return false; } conndataToShow = data; //-refresh projects list m_projectSelector->setProjectSet(m_projectSetToShow); } if (conndataToShow) { QString selectorLabel = xi18nc("@info", "Existing project databases on %1 (%2) database server:", conndataToShow->caption(), conndataToShow->toUserVisibleString()); m_projectSelector->label()->setText(selectorLabel); } return true; } -void KexiProjectDatabaseNameSelectionPage::slotTitleChanged(const QString &capt) +void KexiProjectDatabaseNameSelectionPage::slotCaptionChanged(const QString &capt) { if (contents->le_dbname->text().isEmpty()) m_dbNameAutofill = true; if (m_dbNameAutofill) { m_le_dbname_txtchanged_enabled = false; QString captionAsId = KDb::stringToIdentifier(capt).toLower(); contents->le_dbname->setText(captionAsId); m_projectDataToOverwrite = 0; m_le_dbname_txtchanged_enabled = true; } } void KexiProjectDatabaseNameSelectionPage::slotNameChanged(const QString &) { if (!m_le_dbname_txtchanged_enabled) return; m_projectDataToOverwrite = 0; m_dbNameAutofill = false; } QString KexiProjectDatabaseNameSelectionPage::enteredDbName() const { return contents->le_dbname->text().trimmed(); } bool KexiProjectDatabaseNameSelectionPage::isAcceptable() { delete messageWidget; - if (contents->le_title->text().trimmed().isEmpty()) { + if (contents->le_caption->text().trimmed().isEmpty()) { messageWidget = new KexiContextMessageWidget(contents->formLayout, - contents->le_title, + contents->le_caption, xi18n("Enter project caption.")); - contents->le_title->setText(QString()); + contents->le_caption->setText(QString()); return false; } QString dbName(enteredDbName()); if (dbName.isEmpty()) { messageWidget = new KexiContextMessageWidget(contents->formLayout, contents->le_dbname, xi18n("Enter database name.")); return false; } if (m_projectSetToShow) { KexiProjectData* projectData = m_projectSetToShow->findProject(dbName); if (projectData) { if (m_projectDataToOverwrite == projectData) { delete messageWidget; return true; } KexiContextMessage message( xi18n("Database with this name already exists. " "Do you want to delete it and create a new one?")); if (!m_messageWidgetActionYes) { m_messageWidgetActionYes = new QAction(xi18n("Delete and Create New"), this); connect(m_messageWidgetActionYes, SIGNAL(triggered()), this, SLOT(overwriteActionTriggered())); } m_messageWidgetActionNo->setText(KStandardGuiItem::no().text()); message.addAction(m_messageWidgetActionYes); message.setDefaultAction(m_messageWidgetActionNo); message.addAction(m_messageWidgetActionNo); messageWidget = new KexiContextMessageWidget( this, contents->formLayout, contents->le_dbname, message); messageWidget->setMessageType(KMessageWidget::Warning); - messageWidget->setNextFocusWidget(contents->le_title); + messageWidget->setNextFocusWidget(contents->le_caption); return false; } } return true; } void KexiProjectDatabaseNameSelectionPage::overwriteActionTriggered() { m_projectDataToOverwrite = m_projectSetToShow->findProject(enteredDbName()); next(); } // ---- class Q_DECL_HIDDEN KexiNewProjectAssistant::Private { public: explicit Private(KexiNewProjectAssistant *qq) : q(qq) { } ~Private() { q->setMessageHandler(0); } KexiTemplateSelectionPage* templateSelectionPage() { return page(&m_templateSelectionPage); } KexiProjectStorageTypeSelectionPage* projectStorageTypeSelectionPage() { return page(&m_projectStorageTypeSelectionPage); } - KexiProjectTitleSelectionPage* titleSelectionPage() { - return page(&m_titleSelectionPage); + KexiProjectCaptionSelectionPage* captionSelectionPage() { + return page(&m_captionSelectionPage); } KexiProjectCreationPage* projectCreationPage() { return page(&m_projectCreationPage); } KexiProjectConnectionSelectionPage* projectConnectionSelectionPage() { return page(&m_projectConnectionSelectionPage); } KexiProjectDatabaseNameSelectionPage* projectDatabaseNameSelectionPage() { return page(&m_projectDatabaseNameSelectionPage, q); } KexiPasswordPage* passwordPage() { return page(&m_passwordPage, q); } template C* page(QPointer* p, KexiNewProjectAssistant *parent = 0) { if (p->isNull()) { *p = new C(parent); q->addPage(*p); } return *p; } QPointer m_templateSelectionPage; QPointer m_projectStorageTypeSelectionPage; - QPointer m_titleSelectionPage; + QPointer m_captionSelectionPage; QPointer m_projectCreationPage; QPointer m_projectConnectionSelectionPage; QPointer m_projectDatabaseNameSelectionPage; QPointer m_passwordPage; KexiNewProjectAssistant *q; }; // ---- KexiNewProjectAssistant::KexiNewProjectAssistant(QWidget* parent) : KexiAssistantWidget(parent) , d(new Private(this)) { setCurrentPage(d->templateSelectionPage()); setFocusProxy(d->templateSelectionPage()); setMessageHandler(this); d->templateSelectionPage()->setFocusProxy(d->templateSelectionPage()->recentFocusWidget()); d->templateSelectionPage()->focusRecentFocusWidget(); } KexiNewProjectAssistant::~KexiNewProjectAssistant() { delete d; } void KexiNewProjectAssistant::nextPageRequested(KexiAssistantPage* page) { if (page == d->m_templateSelectionPage) { setCurrentPage(d->projectStorageTypeSelectionPage()); } else if (page == d->m_projectStorageTypeSelectionPage) { switch (d->projectStorageTypeSelectionPage()->selectedType()) { case KexiProjectStorageTypeSelectionPage::Type::File: - setCurrentPage(d->titleSelectionPage()); + setCurrentPage(d->captionSelectionPage()); break; case KexiProjectStorageTypeSelectionPage::Type::Server: setCurrentPage(d->projectConnectionSelectionPage()); break; default: break; } } - else if (page == d->m_titleSelectionPage) { - if (!d->titleSelectionPage()->isAcceptable()) { + else if (page == d->m_captionSelectionPage) { + if (!d->captionSelectionPage()->isAcceptable()) { return; } //file-based project KDbConnectionData cdata; cdata.setDriverId(KDb::defaultFileBasedDriverId()); - cdata.setDatabaseName(d->titleSelectionPage()->contents->file_requester->url().toLocalFile()); - createProject(cdata, cdata.databaseName(), d->titleSelectionPage()->contents->le_title->text()); + cdata.setDatabaseName(d->captionSelectionPage()->contents->file_requester->url().toLocalFile()); + createProject(cdata, cdata.databaseName(), d->captionSelectionPage()->contents->le_caption->text()); } else if (page == d->m_projectConnectionSelectionPage) { KDbConnectionData *cdata = d->projectConnectionSelectionPage()->connSelector->selectedConnectionData(); if (cdata) { if (cdata->isPasswordNeeded()) { d->passwordPage()->setConnectionData(*cdata); setCurrentPage(d->passwordPage()); return; } if (d->projectDatabaseNameSelectionPage()->setConnection(cdata)) { setCurrentPage(d->projectDatabaseNameSelectionPage()); } } } else if (page == d->m_passwordPage) { KDbConnectionData *cdata = d->projectConnectionSelectionPage()->connSelector->selectedConnectionData(); d->passwordPage()->updateConnectionData(cdata); if (cdata && d->projectDatabaseNameSelectionPage()->setConnection(cdata)) { setCurrentPage(d->projectDatabaseNameSelectionPage()); } } else if (page == d->m_projectDatabaseNameSelectionPage) { if (!d->m_projectDatabaseNameSelectionPage->conndataToShow || !d->m_projectDatabaseNameSelectionPage->isAcceptable()) { return; } //server-based project createProject(*d->m_projectDatabaseNameSelectionPage->conndataToShow, d->m_projectDatabaseNameSelectionPage->contents->le_dbname->text().trimmed(), - d->m_projectDatabaseNameSelectionPage->contents->le_title->text().trimmed()); + d->m_projectDatabaseNameSelectionPage->contents->le_caption->text().trimmed()); } } void KexiNewProjectAssistant::createProject( const KDbConnectionData& cdata, const QString& databaseName, const QString& caption) { KexiProjectData new_data(cdata, databaseName, caption); setCurrentPage(d->projectCreationPage()); emit createProject(new_data); } void KexiNewProjectAssistant::cancelRequested(KexiAssistantPage* page) { Q_UNUSED(page); //! @todo } void KexiNewProjectAssistant::tryAgainActionTriggered() { messageWidget()->animatedHide(); currentPage()->next(); } void KexiNewProjectAssistant::cancelActionTriggered() { if (currentPage() == d->m_passwordPage) { d->passwordPage()->focusRecentFocusWidget(); } } const QWidget* KexiNewProjectAssistant::calloutWidget() const { return currentPage()->nextButton(); } #include "KexiNewProjectAssistant.moc" diff --git a/src/main/startup/KexiNewProjectAssistant.h b/src/main/startup/KexiNewProjectAssistant.h index 0d97e3385..6d554f69c 100644 --- a/src/main/startup/KexiNewProjectAssistant.h +++ b/src/main/startup/KexiNewProjectAssistant.h @@ -1,201 +1,201 @@ /* This file is part of the KDE project Copyright (C) 2003-2018 Jarosław Staniek Copyright (C) 2012 Dimitrios T. Tanis Copyright (C) 2014 Roman Shtemberko This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KEXINEWPROJECTASSISTANT_H #define KEXINEWPROJECTASSISTANT_H #include "KexiAssistantMessageHandler.h" #include "ui_KexiProjectStorageTypeSelectionPage.h" #include #include #include #include #include #include #include #include #include #include class KexiConnectionSelectorWidget; class KexiProjectSelectorWidget; class KexiTemplateSelectionPage : public KexiAssistantPage { Q_OBJECT public: explicit KexiTemplateSelectionPage(QWidget* parent = 0); QString selectedTemplate; QString selectedCategory; protected Q_SLOTS: void slotItemClicked(const QModelIndex& index); private: KexiCategorizedView* m_templatesList; }; class KexiProjectStorageTypeSelectionPage : public KexiAssistantPage, public Ui::KexiProjectStorageTypeSelectionPage { Q_OBJECT public: explicit KexiProjectStorageTypeSelectionPage(QWidget* parent = 0); virtual ~KexiProjectStorageTypeSelectionPage(); enum class Type { None, //!< No type selected File, Server }; /** * Returns selected connection type * * Selection depends on button that is focused. */ Type selectedType() const; private Q_SLOTS: void buttonClicked(); }; -class KexiDBTitlePage; +class KexiDBCaptionPage; class KexiStartupFileHandler; -class KexiProjectTitleSelectionPage : public KexiAssistantPage +class KexiProjectCaptionSelectionPage : public KexiAssistantPage { Q_OBJECT public: - explicit KexiProjectTitleSelectionPage(QWidget* parent = 0); - virtual ~KexiProjectTitleSelectionPage(); + explicit KexiProjectCaptionSelectionPage(QWidget* parent = nullptr); + virtual ~KexiProjectCaptionSelectionPage(); bool isAcceptable(); - KexiDBTitlePage* contents; + KexiDBCaptionPage* contents; KexiStartupFileHandler *fileHandler; QPointer messageWidget; private Q_SLOTS: - void titleTextChanged(const QString & text); + void captionTextChanged(const QString &text); void askForOverwriting(const KexiContextMessage& message); private: void updateUrl(); }; class QProgressBar; class KexiProjectCreationPage : public KexiAssistantPage { Q_OBJECT public: explicit KexiProjectCreationPage(QWidget* parent = 0); virtual ~KexiProjectCreationPage(); QProgressBar* m_progressBar; }; class KexiProjectConnectionSelectionPage : public KexiAssistantPage { Q_OBJECT public: explicit KexiProjectConnectionSelectionPage(QWidget* parent = 0); virtual ~KexiProjectConnectionSelectionPage(); KexiConnectionSelectorWidget* connSelector; private: QPointer m_errorMessagePopup; }; class KexiServerDBNamePage; class KexiGUIMessageHandler; class KexiProjectData; class KexiProjectSet; class KexiProjectSelectorWidget; class KexiNewProjectAssistant; class KexiProjectDatabaseNameSelectionPage : public KexiAssistantPage { Q_OBJECT public: explicit KexiProjectDatabaseNameSelectionPage( KexiNewProjectAssistant* parent); virtual ~KexiProjectDatabaseNameSelectionPage(); bool setConnection(KDbConnectionData* data); KexiServerDBNamePage* contents; //! @todo KEXI3 use equivalent of QPointer KDbConnectionData* conndataToShow; QPointer messageWidget; bool isAcceptable(); private Q_SLOTS: - void slotTitleChanged(const QString &capt); + void slotCaptionChanged(const QString &capt); void slotNameChanged(const QString &); void overwriteActionTriggered(); private: QString enteredDbName() const; KexiNewProjectAssistant* m_assistant; KexiProjectSet *m_projectSetToShow; KexiProjectSelectorWidget* m_projectSelector; bool m_dbNameAutofill; bool m_le_dbname_txtchanged_enabled; KexiProjectData* m_projectDataToOverwrite; QAction* m_messageWidgetActionYes; QAction* m_messageWidgetActionNo; }; class KexiProjectData; class KexiNewProjectAssistant : public KexiAssistantWidget, public KexiAssistantMessageHandler, public KDbResultable { Q_OBJECT public: explicit KexiNewProjectAssistant(QWidget* parent = 0); ~KexiNewProjectAssistant(); public Q_SLOTS: virtual void nextPageRequested(KexiAssistantPage* page); virtual void cancelRequested(KexiAssistantPage* page); void tryAgainActionTriggered(); void cancelActionTriggered(); Q_SIGNALS: void createProject(const KexiProjectData &data); protected: virtual const QWidget* calloutWidget() const; private: void createProject( const KDbConnectionData& cdata, const QString& databaseName, const QString& caption); class Private; Private* const d; }; #endif diff --git a/src/main/startup/KexiServerDBNamePage.ui b/src/main/startup/KexiServerDBNamePage.ui index 73741675e..9a9ee32ee 100644 --- a/src/main/startup/KexiServerDBNamePage.ui +++ b/src/main/startup/KexiServerDBNamePage.ui @@ -1,111 +1,120 @@ KexiServerDBNamePage 0 0 477 299 - + + 0 + + + 0 + + + 0 + + 0 Project caption: - + 0 0 100 0 300 16777215 Project's database name: 100 0 300 16777215 Qt::Vertical QSizePolicy::Fixed 20 12 0 0 KLineEdit QLineEdit -
KLineEdit
+
klineedit.h
diff --git a/src/migration/importtablewizard.cpp b/src/migration/importtablewizard.cpp index 84223666e..937df6d64 100644 --- a/src/migration/importtablewizard.cpp +++ b/src/migration/importtablewizard.cpp @@ -1,797 +1,797 @@ /* This file is part of the KDE project Copyright (C) 2009 Adam Pigg Copyright (C) 2014-2016 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "importtablewizard.h" #include "importoptionsdlg.h" #include "migratemanager.h" #include "keximigrate.h" #include "keximigratedata.h" #include "AlterSchemaWidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace KexiMigration; #define RECORDS_FOR_PREVIEW 3 ImportTableWizard::ImportTableWizard ( KDbConnection* curDB, QWidget* parent, QMap* args, Qt::WindowFlags flags) : KAssistantDialog ( parent, flags ), m_args(args) { m_connection = curDB; m_migrateDriver = 0; m_prjSet = 0; m_importComplete = false; m_importWasCanceled = false; m_sourceDbEncoding = QString::fromLatin1(KexiUtils::encoding()); //default KexiMainWindowIface::global()->setReasonableDialogSize(this); setupIntroPage(); setupSrcConn(); setupSrcDB(); setupTableSelectPage(); setupAlterTablePage(); setupImportingPage(); setupProgressPage(); setupFinishPage(); setValid(m_srcConnPageItem, false); connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(slot_currentPageChanged(KPageWidgetItem*,KPageWidgetItem*))); //! @todo Change this to message prompt when we move to non-dialog wizard. connect(m_srcConnSel, SIGNAL(connectionSelected(bool)), this, SLOT(slotConnPageItemSelected(bool))); connect(m_srcConnSel, &KexiConnectionSelectorWidget::connectionItemHighlighted, [this]() { setValid(m_srcConnPageItem, true); }); connect(m_srcConnSel, &KexiConnectionSelectorWidget::connectionItemExecuted, [this]() { setValid(m_srcConnPageItem, true); next(); }); } ImportTableWizard::~ImportTableWizard() { delete m_prjSet; delete m_srcConnSel; } void ImportTableWizard::back() { KAssistantDialog::back(); } void ImportTableWizard::next() { if (currentPage() == m_srcConnPageItem) { if (fileBasedSrcSelected()) { setAppropriate(m_srcDBPageItem, false); } else { setAppropriate(m_srcDBPageItem, true); } } else if (currentPage() == m_alterTablePageItem) { if (m_alterSchemaWidget->nameExists(m_alterSchemaWidget->nameWidget()->nameText())) { KMessageBox::information(this, xi18nc("@info", "%1 name is already used by an existing table. " "Enter different table name to continue.", m_alterSchemaWidget->nameWidget()->nameText()), xi18n("Name Already Used")); return; } } KAssistantDialog::next(); } void ImportTableWizard::accept() { if (m_args) { if (m_finishCheckBox->isChecked()) { m_args->insert("destinationTableName",m_alterSchemaWidget->nameWidget()->nameText()); } else { m_args->remove("destinationTableName"); } } QDialog::accept(); } void ImportTableWizard::reject() { QDialog::reject(); } //=========================================================== // void ImportTableWizard::setupIntroPage() { m_introPageWidget = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(); m_introPageWidget->setLayout(vbox); KexiUtils::setStandardMarginsAndSpacing(vbox); QLabel *lblIntro = new QLabel(m_introPageWidget); lblIntro->setAlignment(Qt::AlignTop | Qt::AlignLeft); lblIntro->setWordWrap(true); lblIntro->setText( xi18nc("@info", "Table Importing Assistant allows you to import a table from an existing " "database into the current Kexi project." "Click Next button to continue or " "Cancel button to exit this assistant.")); vbox->addWidget(lblIntro); m_introPageItem = new KPageWidgetItem(m_introPageWidget, xi18n("Welcome to the Table Importing Assistant")); addPage(m_introPageItem); } void ImportTableWizard::setupSrcConn() { m_srcConnPageWidget = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(m_srcConnPageWidget); m_srcConnSel = new KexiConnectionSelectorWidget(&Kexi::connset(), QUrl("kfiledialog:///ProjectMigrationSourceDir"), KexiConnectionSelectorWidget::Opening, m_srcConnPageWidget); m_srcConnSel->hideConnectonIcon(); m_srcConnSel->showSimpleConnection(); //! @todo remove when support for kexi files as source prj is added in migration const QStringList excludedMimeTypes({ KDb::defaultFileBasedDriverMimeType(), "application/x-kexiproject-shortcut", "application/x-kexi-connectiondata"}); m_srcConnSel->setExcludedMimeTypes(excludedMimeTypes); vbox->addWidget(m_srcConnSel); m_srcConnPageItem = new KPageWidgetItem(m_srcConnPageWidget, xi18n("Select Location for Source Database")); addPage(m_srcConnPageItem); } void ImportTableWizard::setupSrcDB() { // arrivesrcdbPage creates widgets on that page m_srcDBPageWidget = new QWidget(this); m_srcDBName = NULL; m_srcDBPageItem = new KPageWidgetItem(m_srcDBPageWidget, xi18n("Select Source Database")); addPage(m_srcDBPageItem); } void ImportTableWizard::setupTableSelectPage() { m_tablesPageWidget = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(m_tablesPageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); m_tableListWidget = new QListWidget(this); m_tableListWidget->setSelectionMode(QAbstractItemView::SingleSelection); connect(m_tableListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(slotTableListWidgetSelectionChanged())); vbox->addWidget(m_tableListWidget); m_tablesPageItem = new KPageWidgetItem(m_tablesPageWidget, xi18n("Select the Table to Import")); addPage(m_tablesPageItem); } //=========================================================== // void ImportTableWizard::setupImportingPage() { m_importingPageWidget = new QWidget(this); m_importingPageWidget->hide(); QVBoxLayout *vbox = new QVBoxLayout(m_importingPageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); m_lblImportingTxt = new QLabel(m_importingPageWidget); m_lblImportingTxt->setAlignment(Qt::AlignTop | Qt::AlignLeft); m_lblImportingTxt->setWordWrap(true); m_lblImportingErrTxt = new QLabel(m_importingPageWidget); m_lblImportingErrTxt->setAlignment(Qt::AlignTop | Qt::AlignLeft); m_lblImportingErrTxt->setWordWrap(true); vbox->addWidget(m_lblImportingTxt); vbox->addWidget(m_lblImportingErrTxt); vbox->addStretch(1); QWidget *options_widget = new QWidget(m_importingPageWidget); vbox->addWidget(options_widget); QVBoxLayout *options_vbox = new QVBoxLayout(options_widget); options_vbox->setSpacing(KexiUtils::spacingHint()); m_importOptionsButton = new QPushButton(koIcon("configure"), xi18n("Advanced Options"), options_widget); connect(m_importOptionsButton, SIGNAL(clicked()),this, SLOT(slotOptionsButtonClicked())); options_vbox->addWidget(m_importOptionsButton); options_vbox->addStretch(1); m_importingPageWidget->show(); m_importingPageItem = new KPageWidgetItem(m_importingPageWidget, xi18n("Importing")); addPage(m_importingPageItem); } void ImportTableWizard::setupAlterTablePage() { m_alterTablePageWidget = new QWidget(this); m_alterTablePageWidget->hide(); QVBoxLayout *vbox = new QVBoxLayout(m_alterTablePageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); m_alterSchemaWidget = new KexiMigration::AlterSchemaWidget(this); vbox->addWidget(m_alterSchemaWidget); m_alterTablePageWidget->show(); m_alterTablePageItem = new KPageWidgetItem(m_alterTablePageWidget, xi18n("Alter the Detected Table Design")); addPage(m_alterTablePageItem); } void ImportTableWizard::setupProgressPage() { m_progressPageWidget = new QWidget(this); m_progressPageWidget->hide(); QVBoxLayout *vbox = new QVBoxLayout(m_progressPageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); m_progressPageWidget->setLayout(vbox); m_progressLbl = new QLabel(m_progressPageWidget); m_progressLbl->setAlignment(Qt::AlignTop | Qt::AlignLeft); m_progressLbl->setWordWrap(true); m_rowsImportedLbl = new QLabel(m_progressPageWidget); m_importingProgressBar = new QProgressBar(m_progressPageWidget); m_importingProgressBar->setMinimum(0); m_importingProgressBar->setMaximum(0); m_importingProgressBar->setValue(0); vbox->addWidget(m_progressLbl); vbox->addWidget(m_rowsImportedLbl); vbox->addWidget(m_importingProgressBar); vbox->addStretch(1); m_progressPageItem = new KPageWidgetItem(m_progressPageWidget, xi18n("Processing Import")); addPage(m_progressPageItem); } void ImportTableWizard::setupFinishPage() { m_finishPageWidget = new QWidget(this); m_finishPageWidget->hide(); QVBoxLayout *vbox = new QVBoxLayout(m_finishPageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); m_finishLbl = new QLabel(m_finishPageWidget); m_finishLbl->setAlignment(Qt::AlignTop | Qt::AlignLeft); m_finishLbl->setWordWrap(true); vbox->addWidget(m_finishLbl); m_finishCheckBox = new QCheckBox(xi18n("Open imported table"), m_finishPageWidget); m_finishCheckBox->setChecked(true); vbox->addSpacing(KexiUtils::spacingHint()); vbox->addWidget(m_finishCheckBox); vbox->addStretch(1); m_finishPageItem = new KPageWidgetItem(m_finishPageWidget, xi18n("Success")); addPage(m_finishPageItem); } void ImportTableWizard::slot_currentPageChanged(KPageWidgetItem* curPage,KPageWidgetItem* prevPage) { Q_UNUSED(prevPage); if (curPage == m_introPageItem) { } else if (curPage == m_srcConnPageItem) { arriveSrcConnPage(); } else if (curPage == m_srcDBPageItem) { arriveSrcDBPage(); } else if (curPage == m_tablesPageItem) { arriveTableSelectPage(prevPage); } else if (curPage == m_alterTablePageItem) { if (prevPage == m_tablesPageItem) { arriveAlterTablePage(); } } else if (curPage == m_importingPageItem) { arriveImportingPage(); } else if (curPage == m_progressPageItem) { arriveProgressPage(); } else if (curPage == m_finishPageItem) { arriveFinishPage(); } } void ImportTableWizard::arriveSrcConnPage() { } void ImportTableWizard::arriveSrcDBPage() { if (fileBasedSrcSelected()) { //! @todo Back button doesn't work after selecting a file to import } else { delete m_prjSet; m_prjSet = 0; m_srcDBPageWidget->hide(); qDebug() << "Looks like we need a project selector widget!"; KDbConnectionData* conndata = m_srcConnSel->selectedConnectionData(); if (conndata) { KexiGUIMessageHandler handler; m_prjSet = new KexiProjectSet(&handler); if (!m_prjSet->setConnectionData(conndata)) { handler.showErrorMessage(m_prjSet->result()); delete m_prjSet; m_prjSet = 0; return; } if (!m_srcDBName) { QVBoxLayout *vbox = new QVBoxLayout(m_srcDBPageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); m_srcDBName = new KexiProjectSelectorWidget(m_srcDBPageWidget); vbox->addWidget(m_srcDBName); m_srcDBName->label()->setText(xi18n("Select source database you wish to import:")); } m_srcDBName->setProjectSet(m_prjSet); } m_srcDBPageWidget->show(); } } void ImportTableWizard::arriveTableSelectPage(KPageWidgetItem *prevPage) { if (prevPage == m_alterTablePageItem) { if (m_tableListWidget->count() == 1) { //we was skiping it before back(); } } else { Kexi::ObjectStatus result; KexiUtils::WaitCursor wait; m_tableListWidget->clear(); m_migrateDriver = prepareImport(&result); bool ok = m_migrateDriver; if (ok) { if (!m_sourceDbEncoding.isEmpty()) { m_migrateDriver->setPropertyValue( "source_database_nonunicode_encoding", QVariant(m_sourceDbEncoding.toUpper().remove(' ')) // "CP1250", not "cp 1250" ); } ok = m_migrateDriver->connectSource(&result); } if (ok) { QStringList tableNames; if (m_migrateDriver->tableNames(&tableNames)) { m_tableListWidget->addItems(tableNames); } if (m_tableListWidget->item(0)) { m_tableListWidget->item(0)->setSelected(true); if (m_tableListWidget->count() == 1) { KexiUtils::removeWaitCursor(); next(); } } } KexiUtils::removeWaitCursor(); if (!ok) { QString errMessage =result.message.isEmpty() ? xi18n("Unknown error") : result.message; QString errDescription = result.description.isEmpty() ? errMessage : result.description; KMessageBox::error(this, errMessage, errDescription); setValid(m_tablesPageItem, false); } } } void ImportTableWizard::arriveAlterTablePage() { //! @todo handle errors if (m_tableListWidget->selectedItems().isEmpty()) return; //! @todo (js) support multiple tables? #if 0 foreach(QListWidgetItem *table, m_tableListWidget->selectedItems()) { m_importTableName = table->text(); } #else m_importTableName = m_tableListWidget->selectedItems().first()->text(); #endif QScopedPointer ts(new KDbTableSchema); if (!m_migrateDriver->readTableSchema(m_importTableName, ts.data())) { return; } setValid(m_alterTablePageItem, ts->fieldCount() > 0); if (isValid(m_alterTablePageItem)) { connect(m_alterSchemaWidget->nameWidget(), SIGNAL(textChanged()), this, SLOT(slotNameChanged()), Qt::UniqueConnection); } m_alterSchemaWidget->setTableSchema(ts.take()); if (!readFromTable()) { m_alterSchemaWidget->setTableSchema(nullptr); back(); KMessageBox::information(this, xi18nc("@info", "Could not import table %1. " "Select different table or cancel importing.", m_importTableName)); } } bool ImportTableWizard::readFromTable() { QSharedPointer tableResult = m_migrateDriver->readFromTable(m_importTableName); KDbTableSchema *newSchema = m_alterSchemaWidget->newSchema(); if (!tableResult || tableResult->lastResult().isError() || tableResult->fieldsCount() != newSchema->fieldCount()) { back(); KMessageBox::information(this, xi18nc("@info", "Could not import table %1. " "Select different table or cancel importing.", m_importTableName)); return false; } QScopedPointer> data(new QList); for (int i = 0; i < RECORDS_FOR_PREVIEW; ++i) { QSharedPointer record(tableResult->fetchRecordData()); if (!record) { if (tableResult->lastResult().isError()) { return false; } break; } data->append(record.data()); } if (data->isEmpty()) { back(); KMessageBox::information(this, xi18nc("@info", "No data has been found in table %1. " "Select different table or cancel importing.", m_importTableName)); return false; } m_alterSchemaWidget->model()->setRowCount(data->count()); m_alterSchemaWidget->setData(data.take()); return true; } void ImportTableWizard::arriveImportingPage() { m_importingPageWidget->hide(); #if 0 if (checkUserInput()) { //setNextEnabled(m_importingPageWidget, true); user2Button->setEnabled(true); } else { //setNextEnabled(m_importingPageWidget, false); user2Button->setEnabled(false); } #endif QString txt; txt = xi18nc("@info Table import wizard, final message", "All required information has now been gathered. " "Click Next button to start importing table %1." "Depending on size of the table this may take some time.", m_alterSchemaWidget->nameWidget()->nameText()); m_lblImportingTxt->setText(txt); //temp. hack for MS Access driver only //! @todo for other databases we will need KexiMigration::Connection //! and KexiMigration::Driver classes bool showOptions = false; if (fileBasedSrcSelected()) { Kexi::ObjectStatus result; KexiMigrate* sourceDriver = prepareImport(&result); if (sourceDriver) { showOptions = !result.error() && sourceDriver->propertyValue("source_database_has_nonunicode_encoding").toBool(); sourceDriver->setData(nullptr); } } if (showOptions) m_importOptionsButton->show(); else m_importOptionsButton->hide(); m_importingPageWidget->show(); setAppropriate(m_progressPageItem, true); } void ImportTableWizard::arriveProgressPage() { m_progressLbl->setText(xi18nc("@info", "Please wait while the table is imported.")); backButton()->setEnabled(false); nextButton()->setEnabled(false); connect(button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &ImportTableWizard::slotCancelClicked); QApplication::setOverrideCursor(Qt::BusyCursor); m_importComplete = doImport(); QApplication::restoreOverrideCursor(); disconnect(button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &ImportTableWizard::slotCancelClicked); next(); } void ImportTableWizard::arriveFinishPage() { if (m_importComplete) { m_finishPageItem->setHeader(xi18n("Success")); m_finishLbl->setText(xi18nc("@info", "Table %1 has been imported.", m_alterSchemaWidget->nameWidget()->nameText())); } else { m_finishPageItem->setHeader(xi18n("Failure")); m_finishLbl->setText(xi18n("An error occurred.")); } m_migrateDriver->disconnectSource(); button(QDialogButtonBox::Cancel)->setEnabled(!m_importComplete); m_finishCheckBox->setVisible(m_importComplete); finishButton()->setEnabled(m_importComplete); nextButton()->setEnabled(m_importComplete); setAppropriate(m_progressPageItem, false); } bool ImportTableWizard::fileBasedSrcSelected() const { return m_srcConnSel->selectedConnectionType() == KexiConnectionSelectorWidget::FileBased; } KexiMigrate* ImportTableWizard::prepareImport(Kexi::ObjectStatus *result) { Q_ASSERT(result); // Find a source (migration) driver name QString sourceDriverId = driverIdForSelectedSource(); if (sourceDriverId.isEmpty()) { result->setStatus(xi18n("No appropriate migration driver found."), m_migrateManager.possibleProblemsMessage()); } // Get a source (migration) driver KexiMigrate* sourceDriver = 0; if (!result->error()) { sourceDriver = m_migrateManager.driver(sourceDriverId); if (!sourceDriver || m_migrateManager.result().isError()) { qDebug() << "Import migrate driver error..."; result->setStatus(m_migrateManager.resultable()); } } // Set up source (migration) data required for connection if (sourceDriver && !result->error()) { #if 0 // Setup progress feedback for the GUI if (sourceDriver->progressSupported()) { m_progressBar->updateGeometry(); disconnect(sourceDriver, SIGNAL(progressPercent(int)), this, SLOT(progressUpdated(int))); connect(sourceDriver, SIGNAL(progressPercent(int)), this, SLOT(progressUpdated(int))); progressUpdated(0); } #endif bool keepData = true; #if 0 if (m_importTypeStructureAndDataCheckBox->isChecked()) { qDebug() << "Structure and data selected"; keepData = true; } else if (m_importTypeStructureOnlyCheckBox->isChecked()) { qDebug() << "structure only selected"; keepData = false; } else { qDebug() << "Neither radio button is selected (not possible?) presume keep data"; keepData = true; } #endif KexiMigration::Data* md = new KexiMigration::Data(); if (fileBasedSrcSelected()) { KDbConnectionData* conn_data = new KDbConnectionData(); conn_data->setDatabaseName(m_srcConnSel->selectedFile()); md->source = conn_data; md->sourceName.clear(); } else { md->source = m_srcConnSel->selectedConnectionData(); md->sourceName = m_srcDBName->selectedProjectData()->databaseName(); } md->setShouldCopyData(keepData); sourceDriver->setData(md); return sourceDriver; } return 0; } //=========================================================== // QString ImportTableWizard::driverIdForSelectedSource() { if (fileBasedSrcSelected()) { QMimeDatabase db; QMimeType mime = db.mimeTypeForFile(m_srcConnSel->selectedFile()); if (!mime.isValid() || mime.name() == "application/octet-stream" || mime.name() == "text/plain" || mime.name() == "application/zip") { //try by URL: mime = db.mimeTypeForFile(m_srcConnSel->selectedFile()); } if (!mime.isValid()) { return QString(); } const QStringList ids(m_migrateManager.driverIdsForMimeType(mime.name())); //! @todo do we want to return first migrate driver for the mime type or allow to select it? return ids.isEmpty() ? QString() : ids.first(); } return m_srcConnSel->selectedConnectionData() ? m_srcConnSel->selectedConnectionData()->databaseName() : QString(); } bool ImportTableWizard::doImport() { KexiGUIMessageHandler msg; KexiProject* project = KexiMainWindowIface::global()->project(); if (!project) { msg.showErrorMessage(KDbMessageHandler::Error, xi18n("No project available.")); return false; } KexiPart::Part *part = Kexi::partManager().partForPluginId("org.kexi-project.table"); if (!part) { msg.showErrorMessage(Kexi::partManager().result()); return false; } KDbTableSchema* newSchema = m_alterSchemaWidget->newSchema(); if (!newSchema) { msg.showErrorMessage(KDbMessageHandler::Error, xi18n("No table was selected to import.")); return false; } newSchema->setName(m_alterSchemaWidget->nameWidget()->nameText()); newSchema->setCaption(m_alterSchemaWidget->nameWidget()->captionText()); KexiPart::Item* partItemForSavedTable = project->createPartItem(part->info(), newSchema->name()); if (!partItemForSavedTable) { msg.showErrorMessage(project->result()); return false; } //Create the table if (!m_connection->createTable(newSchema, KDbConnection::CreateTableOption::Default | KDbConnection::CreateTableOption::DropDestination)) { msg.showErrorMessage(KDbMessageHandler::Error, xi18nc("@info", "Unable to create table %1.", newSchema->name())); return false; } m_alterSchemaWidget->takeTableSchema(); //m_connection takes ownership of the KDbTableSchema object //Import the data QApplication::setOverrideCursor(Qt::BusyCursor); QList row; unsigned int fieldCount = newSchema->fieldCount(); m_migrateDriver->moveFirst(); KDbTransactionGuard tg(m_connection); if (m_connection->result().isError()) { QApplication::restoreOverrideCursor(); return false; } do { for (unsigned int i = 0; i < fieldCount; ++i) { if (m_importWasCanceled) { return false; } if (i % 100 == 0) { QApplication::processEvents(); } row.append(m_migrateDriver->value(i)); } m_connection->insertRecord(newSchema, row); row.clear(); } while (m_migrateDriver->moveNext()); if (!tg.commit()) { QApplication::restoreOverrideCursor(); return false; } QApplication::restoreOverrideCursor(); //Done so save part and update gui partItemForSavedTable->setIdentifier(newSchema->id()); project->addStoredItem(part->info(), partItemForSavedTable); return true; } void ImportTableWizard::slotConnPageItemSelected(bool isSelected) { setValid(m_srcConnPageItem, isSelected); if (isSelected && fileBasedSrcSelected()) { next(); } } void ImportTableWizard::slotTableListWidgetSelectionChanged() { setValid(m_tablesPageItem, !m_tableListWidget->selectedItems().isEmpty()); } void ImportTableWizard::slotNameChanged() { setValid(m_alterTablePageItem, !m_alterSchemaWidget->nameWidget()->captionText().isEmpty()); } void ImportTableWizard::slotCancelClicked() { m_importWasCanceled = true; } void ImportTableWizard::slotOptionsButtonClicked() { OptionsDialog dlg(m_srcConnSel->selectedFile(), m_sourceDbEncoding, this); if (QDialog::Accepted == dlg.exec()) { m_sourceDbEncoding = dlg.encodingComboBox()->selectedEncoding(); } } diff --git a/src/migration/importwizard.cpp b/src/migration/importwizard.cpp index b36e660de..7dda4a549 100644 --- a/src/migration/importwizard.cpp +++ b/src/migration/importwizard.cpp @@ -1,1137 +1,1137 @@ /* This file is part of the KDE project Copyright (C) 2004-2009 Adam Pigg Copyright (C) 2004-2016 Jarosław Staniek Copyright (C) 2005 Martin Ellis This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "importwizard.h" #include "keximigrate.h" #include "importoptionsdlg.h" #include #include #include #include #include #include #include #include #include #include -#include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace KexiMigration; class Q_DECL_HIDDEN ImportWizard::Private { public: Private(QMap* args_) : srcProjectSelector(0) , fileBasedDstWasPresented(false) , setupFileBasedSrcNeeded(true) , importExecuted(false) , prjSet(0) , args(args_) { } ~Private() { delete prjSet; } QWidget *introPageWidget, *srcConnPageWidget, *srcDBPageWidget, *dstTypePageWidget, *dstPageWidget, *importTypePageWidget, *importingPageWidget, *finishPageWidget; KPageWidgetItem *introPageItem, *srcConnPageItem, *srcDBPageItem, *dstTypePageItem, *dstPageItem, *importTypePageItem, *importingPageItem, *finishPageItem; QGroupBox *importTypeGroupBox; QRadioButton *importTypeStructureAndDataCheckBox; QRadioButton *importTypeStructureOnlyCheckBox; - KexiDBTitlePage* dstTitlePageWidget; - KPageWidgetItem *dstTitlePageItem; + KexiDBCaptionPage* dstCaptionPageWidget; + KPageWidgetItem *dstCaptionPageItem; KexiPrjTypeSelector *dstPrjTypeSelector; KexiConnectionSelectorWidget *srcConn, *dstConn; QString driverIdForSelectedSource; - QLineEdit *dstNewDBTitleLineEdit; + QLineEdit *dstNewDBCaptionLineEdit; QLabel *dstNewDBNameLabel; QLineEdit *dstNewDBNameLineEdit; QLabel *dstNewDBNameUrlLabel; KUrlRequester *dstNewDBNameUrl; KexiStartupFileHandler *dstNewDBFileHandler; KexiProjectSelectorWidget *srcProjectSelector; QLabel *lblImportingTxt, *lblImportingErrTxt, *finishLbl; QCheckBox *openImportedProjectCheckBox; bool fileBasedDstWasPresented; bool setupFileBasedSrcNeeded; bool importExecuted; //!< used in import() KexiProjectSet* prjSet; QProgressBar *progressBar; QPushButton* importOptionsButton; QMap *args; QString predefinedDatabaseName, predefinedMimeType; KDbConnectionData *predefinedConnectionData; MigrateManager migrateManager; //!< object lives here, so status messages can be globally preserved //! Encoding for source db. Currently only used for MDB driver. //! @todo Hardcoded. Move to KexiMigrate driver's impl. QString sourceDBEncoding; }; //=========================================================== // ImportWizard::ImportWizard(QWidget *parent, QMap* args) : KAssistantDialog(parent) , d(new Private(args)) { setModal(true); setWindowTitle(xi18nc("@title:window", "Import Database")); setWindowIcon(KexiIcon("database-import")); KexiMainWindowIface::global()->setReasonableDialogSize(this); parseArguments(); setupIntro(); setupSrcConn(); setupSrcDB(); setupDstType(); - setupDstTitle(); + setupDstCaption(); setupDst(); setupImportType(); setupImporting(); setupFinish(); connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(slot_currentPageChanged(KPageWidgetItem*,KPageWidgetItem*))); connect(button(QDialogButtonBox::Help), &QPushButton::clicked, this, &ImportWizard::helpClicked); if (d->predefinedConnectionData) { // setup wizard for predefined server source d->srcConn->showAdvancedConnection(); setAppropriate(d->srcConnPageItem, false); setAppropriate(d->srcDBPageItem, false); } else if (!d->predefinedDatabaseName.isEmpty()) { // setup wizard for predefined source // (used when external project type was opened in Kexi, e.g. mdb file) setAppropriate(d->srcConnPageItem, false); setAppropriate(d->srcDBPageItem, false); d->srcConn->showSimpleConnection(); d->srcConn->setSelectedFile(d->predefinedDatabaseName); #if 0 //disable all prev pages except "welcome" page for (int i = 0; i < indexOf(d->dstTypePage); i++) { if (page(i) != d->introPage) setAppropriate(page(i), false); } #endif } d->sourceDBEncoding = QString::fromLatin1(KexiUtils::encoding()); //default } //=========================================================== // ImportWizard::~ImportWizard() { delete d; } //=========================================================== // void ImportWizard::parseArguments() { d->predefinedConnectionData = 0; if (!d->args) return; if (!(*d->args)["databaseName"].isEmpty() && !(*d->args)["mimeType"].isEmpty()) { d->predefinedDatabaseName = (*d->args)["databaseName"]; d->predefinedMimeType = (*d->args)["mimeType"]; if (d->args->contains("connectionData")) { bool ok; d->predefinedConnectionData = new KDbConnectionData( KDbUtils::deserializeMap((*d->args)["connectionData"]), &ok); if (!ok) { delete d->predefinedConnectionData; d->predefinedConnectionData = 0; } } } d->args->clear(); } QString ImportWizard::selectedSourceFileName() const { if (d->predefinedDatabaseName.isEmpty()) return d->srcConn->selectedFile(); return d->predefinedDatabaseName; } //=========================================================== // void ImportWizard::setupIntro() { d->introPageWidget = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(); d->introPageWidget->setLayout(vbox); KexiUtils::setStandardMarginsAndSpacing(vbox); QLabel *lblIntro = new QLabel(d->introPageWidget); lblIntro->setAlignment(Qt::AlignTop | Qt::AlignLeft); lblIntro->setWordWrap(true); lblIntro->setTextFormat(Qt::RichText); KLocalizedString msg; if (d->predefinedConnectionData) { // predefined import: server source msg = kxi18nc("@info", "Database Importing Assistant is about to import %1 " "database " "(connection %2) into a KEXI project.") .subs(d->predefinedDatabaseName) .subs(d->predefinedConnectionData->toUserVisibleString()); } else if (!d->predefinedDatabaseName.isEmpty()) { // predefined import: file source //! @todo this message is currently ok for files only QMimeDatabase db; QMimeType mime = db.mimeTypeForName(d->predefinedMimeType); if (!mime.isValid()) { qWarning() << QString("'%1' mimetype not installed!").arg(d->predefinedMimeType); } d->driverIdForSelectedSource = driverIdForMimeType(mime); msg = kxi18nc( "@info", "Database Importing Assistant is about to import %1 file " "of type %2 into a KEXI project.") .subs(QDir::toNativeSeparators(d->predefinedDatabaseName)) .subs(mime.isValid() ? mime.comment() : "???"); } else { msg = kxi18nc("@info", "Database Importing Assistant allows you to import an existing database " "into a KEXI project."); } const QString finalMessage = KexiUtils::localizedSentencesToHtml( msg, kxi18nc("@info", "Click Next button to continue or " "Cancel button to exit this assistant.")); lblIntro->setText(finalMessage); vbox->addWidget(lblIntro); d->introPageItem = new KPageWidgetItem(d->introPageWidget, xi18n("Welcome to the Database Importing Assistant")); addPage(d->introPageItem); } //=========================================================== // void ImportWizard::setupSrcConn() { d->srcConnPageWidget = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(d->srcConnPageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); d->srcConn = new KexiConnectionSelectorWidget(&Kexi::connset(), QUrl("kfiledialog:///ProjectMigrationSourceDir"), KexiConnectionSelectorWidget::Opening, d->srcConnPageWidget); d->srcConn->hideConnectonIcon(); d->srcConn->showSimpleConnection(); connect(d->srcConn, &KexiConnectionSelectorWidget::connectionSelected, this, &ImportWizard::sourceConnectionSelected); const QStringList excludedMimeTypes({ //! @todo remove when support for kexi files as source prj is added in migration KDb::defaultFileBasedDriverMimeType(), "application/x-kexiproject-shortcut", "application/x-kexi-connectiondata"}); d->srcConn->setExcludedMimeTypes(excludedMimeTypes); vbox->addWidget(d->srcConn); d->srcConnPageItem = new KPageWidgetItem(d->srcConnPageWidget, xi18n("Select Location for Source Database")); addPage(d->srcConnPageItem); } //=========================================================== // void ImportWizard::setupSrcDB() { // arrivesrcdbPage creates widgets on that page d->srcDBPageWidget = new QWidget(this); d->srcDBPageItem = new KPageWidgetItem(d->srcDBPageWidget, xi18n("Select Source Database")); addPage(d->srcDBPageItem); } //=========================================================== // void ImportWizard::setupDstType() { d->dstTypePageWidget = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(d->dstTypePageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); QHBoxLayout *hbox = new QHBoxLayout; vbox->addLayout(hbox); KexiUtils::setStandardMarginsAndSpacing(hbox); QLabel *lbl = new QLabel(xi18n("Destination database type:") /*+ ' '*/, d->dstTypePageWidget); lbl->setAlignment(Qt::AlignLeft | Qt::AlignTop); lbl->setTextFormat(Qt::RichText); hbox->addWidget(lbl); d->dstPrjTypeSelector = new KexiPrjTypeSelector(d->dstTypePageWidget); hbox->addWidget(d->dstPrjTypeSelector); d->dstPrjTypeSelector->option_file->setText(xi18n("Database project stored in a file")); d->dstPrjTypeSelector->option_server->setText(xi18n("Database project stored on a server")); hbox->addStretch(1); vbox->addStretch(1); d->dstTypePageItem = new KPageWidgetItem(d->dstTypePageWidget, xi18n("Select Destination Database Type")); addPage(d->dstTypePageItem); } //=========================================================== // -void ImportWizard::setupDstTitle() +void ImportWizard::setupDstCaption() { - d->dstTitlePageWidget = new KexiDBTitlePage(xi18n("Destination project's caption:"), this); - d->dstTitlePageWidget->layout()->setMargin(KexiUtils::marginHint()); - d->dstTitlePageWidget->updateGeometry(); - d->dstNewDBTitleLineEdit = d->dstTitlePageWidget->le_title; - connect(d->dstNewDBTitleLineEdit, SIGNAL(textChanged(QString)), - this, SLOT(destinationTitleTextChanged(QString))); - d->dstNewDBNameUrlLabel = d->dstTitlePageWidget->label_requester; - d->dstNewDBNameUrl = d->dstTitlePageWidget->file_requester; + d->dstCaptionPageWidget = new KexiDBCaptionPage(xi18n("Destination project's caption:"), this); + d->dstCaptionPageWidget->layout()->setMargin(KexiUtils::marginHint()); + d->dstCaptionPageWidget->updateGeometry(); + d->dstNewDBCaptionLineEdit = d->dstCaptionPageWidget->le_caption; + connect(d->dstNewDBCaptionLineEdit, &QLineEdit::textChanged, this, + &ImportWizard::destinationCaptionTextChanged); + d->dstNewDBNameUrlLabel = d->dstCaptionPageWidget->label_requester; + d->dstNewDBNameUrl = d->dstCaptionPageWidget->file_requester; d->dstNewDBFileHandler = new KexiStartupFileHandler( QUrl("kfiledialog:///ProjectMigrationDestinationDir"), KexiFileFilters::SavingFileBasedDB, - d->dstTitlePageWidget->file_requester); - d->dstNewDBNameLabel = new QLabel(xi18n("Destination project's name:"), d->dstTitlePageWidget); - d->dstTitlePageWidget->formLayout->setWidget(2, QFormLayout::LabelRole, d->dstNewDBNameLabel); - d->dstNewDBNameLineEdit = new QLineEdit(d->dstTitlePageWidget); + d->dstCaptionPageWidget->file_requester); + d->dstNewDBNameLabel = new QLabel(xi18n("Destination project's name:"), d->dstCaptionPageWidget); + d->dstCaptionPageWidget->formLayout->setWidget(2, QFormLayout::LabelRole, d->dstNewDBNameLabel); + d->dstNewDBNameLineEdit = new QLineEdit(d->dstCaptionPageWidget); d->dstNewDBNameLineEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); KDbIdentifierValidator *idValidator = new KDbIdentifierValidator(this); idValidator->setLowerCaseForced(true); d->dstNewDBNameLineEdit->setValidator(idValidator); - d->dstTitlePageWidget->formLayout->setWidget(2, QFormLayout::FieldRole, d->dstNewDBNameLineEdit); + d->dstCaptionPageWidget->formLayout->setWidget(2, QFormLayout::FieldRole, d->dstNewDBNameLineEdit); - d->dstTitlePageItem = new KPageWidgetItem(d->dstTitlePageWidget, xi18n("Enter Destination Database Project's Caption")); - addPage(d->dstTitlePageItem); + d->dstCaptionPageItem = new KPageWidgetItem(d->dstCaptionPageWidget, xi18n("Enter Destination Database Project's Caption")); + addPage(d->dstCaptionPageItem); } -void ImportWizard::destinationTitleTextChanged(const QString & text) +void ImportWizard::destinationCaptionTextChanged(const QString &text) { Q_UNUSED(text); updateDestinationDBFileName(); } void ImportWizard::updateDestinationDBFileName() { - d->dstNewDBFileHandler->updateUrl(d->dstNewDBTitleLineEdit->text()); - d->dstNewDBNameLineEdit->setText(d->dstNewDBTitleLineEdit->text()); + d->dstNewDBFileHandler->updateUrl(d->dstNewDBCaptionLineEdit->text()); + d->dstNewDBNameLineEdit->setText(d->dstNewDBCaptionLineEdit->text()); } //=========================================================== // void ImportWizard::setupDst() { d->dstPageWidget = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(d->dstPageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); d->dstConn = new KexiConnectionSelectorWidget(&Kexi::connset(), QUrl("kfiledialog:///ProjectMigrationDestinationDir"), KexiConnectionSelectorWidget::Saving, d->dstPageWidget); d->dstConn->hideHelpers(); vbox->addWidget(d->dstConn); connect(d->dstConn, SIGNAL(connectionItemExecuted(ConnectionDataLVItem*)), this, SLOT(next())); d->dstConn->showSimpleConnection(); //anyway, db files will be _saved_ d->dstConn->setFileMode(KexiFileFilters::SavingFileBasedDB); d->dstPageItem = new KPageWidgetItem(d->dstPageWidget, xi18n("Select Location for Destination Database Project")); addPage(d->dstPageItem); } //=========================================================== // void ImportWizard::setupImportType() { d->importTypePageWidget = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(d->importTypePageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); d->importTypeGroupBox = new QGroupBox(d->importTypePageWidget); vbox->addWidget(d->importTypeGroupBox); QVBoxLayout *importTypeGroupBoxLyr = new QVBoxLayout; importTypeGroupBoxLyr->addWidget( d->importTypeStructureAndDataCheckBox = new QRadioButton( xi18nc("Scope of import", "Structure and data"), d->importTypeGroupBox)); d->importTypeStructureAndDataCheckBox->setChecked(true); importTypeGroupBoxLyr->addWidget( d->importTypeStructureOnlyCheckBox = new QRadioButton( xi18nc("Scope of import", "Structure only"), d->importTypeGroupBox)); importTypeGroupBoxLyr->addStretch(1); d->importTypeGroupBox->setLayout(importTypeGroupBoxLyr); d->importTypePageItem = new KPageWidgetItem(d->importTypePageWidget, xi18n("Select Scope of Import")); addPage(d->importTypePageItem); } //=========================================================== // void ImportWizard::setupImporting() { d->importingPageWidget = new QWidget(this); d->importingPageWidget->hide(); QVBoxLayout *vbox = new QVBoxLayout(d->importingPageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); d->lblImportingTxt = new QLabel(d->importingPageWidget); d->lblImportingTxt->setAlignment(Qt::AlignTop | Qt::AlignLeft); d->lblImportingTxt->setWordWrap(true); d->lblImportingTxt->setTextFormat(Qt::RichText); d->lblImportingErrTxt = new QLabel(d->importingPageWidget); d->lblImportingErrTxt->setAlignment(Qt::AlignTop | Qt::AlignLeft); d->lblImportingErrTxt->setWordWrap(true); d->lblImportingErrTxt->setTextFormat(Qt::RichText); d->progressBar = new QProgressBar(d->importingPageWidget); d->progressBar->setRange(0, 100); d->progressBar->hide(); vbox->addWidget(d->lblImportingTxt); vbox->addWidget(d->lblImportingErrTxt); vbox->addStretch(1); QWidget *options_widget = new QWidget(d->importingPageWidget); vbox->addWidget(options_widget); QVBoxLayout *options_vbox = new QVBoxLayout(options_widget); options_vbox->setSpacing(KexiUtils::spacingHint()); QHBoxLayout *importOptionsButtonLyr = new QHBoxLayout; options_vbox->addLayout(importOptionsButtonLyr); d->importOptionsButton = new QPushButton(koIcon("configure"), xi18n("Advanced Options"), options_widget); connect(d->importOptionsButton, SIGNAL(clicked()), this, SLOT(slotOptionsButtonClicked())); importOptionsButtonLyr->addStretch(1); importOptionsButtonLyr->addWidget(d->importOptionsButton); importOptionsButtonLyr->addStretch(1); options_vbox->addStretch(1); vbox->addWidget(d->progressBar); vbox->addStretch(2); d->importingPageWidget->show(); d->importingPageItem = new KPageWidgetItem(d->importingPageWidget, xi18n("Importing")); addPage(d->importingPageItem); } //=========================================================== // void ImportWizard::setupFinish() { d->finishPageWidget = new QWidget(this); d->finishPageWidget->hide(); QVBoxLayout *vbox = new QVBoxLayout(d->finishPageWidget); KexiUtils::setStandardMarginsAndSpacing(vbox); d->finishLbl = new QLabel(d->finishPageWidget); d->finishLbl->setAlignment(Qt::AlignTop | Qt::AlignLeft); d->finishLbl->setWordWrap(true); d->finishLbl->setTextFormat(Qt::RichText); vbox->addWidget(d->finishLbl); d->openImportedProjectCheckBox = new QCheckBox(xi18n("Open imported project"), d->finishPageWidget); d->openImportedProjectCheckBox->setChecked(true); vbox->addSpacing(KexiUtils::spacingHint()); vbox->addWidget(d->openImportedProjectCheckBox); vbox->addStretch(1); d->finishPageItem = new KPageWidgetItem(d->finishPageWidget, xi18n("Success")); addPage(d->finishPageItem); } //=========================================================== // bool ImportWizard::checkUserInput() { QString issues; - if (d->dstNewDBTitleLineEdit->text().isEmpty()) { + if (d->dstNewDBCaptionLineEdit->text().isEmpty()) { issues = xi18nc("@info", "No new database name was entered."); } Kexi::ObjectStatus result; KexiMigrate* sourceDriver = prepareImport(result); if (sourceDriver && sourceDriver->isSourceAndDestinationDataSourceTheSame()) { // note: we're using .arg() here because the 'issues' argument is already in rich-text format issues = xi18nc("@info", "%1Source database is the same as destination.") .arg(issues); } if (!issues.isEmpty()) { // note: we're using .arg() here because the 'issues' argument is already in rich-text format d->lblImportingErrTxt->setText( xi18nc("@info", "Following issues were found with the data you entered:" "%1" "Please click Back button and correct these issues.") .arg(issues)); return false; } return true; } void ImportWizard::arriveSrcConnPage() { d->srcConnPageWidget->hide(); /*! @todo KexiFileWidget needs "open file" and "open server" modes in addition to just "open" */ if (d->setupFileBasedSrcNeeded) { d->setupFileBasedSrcNeeded = false; d->srcConn->setFileMode(KexiFileFilters::Opening); d->srcConn->setAdditionalMimeTypes(QStringList()); } /*! @todo Support different file extensions based on MigrationDriver */ d->srcConnPageWidget->show(); } void ImportWizard::arriveSrcDBPage() { if (fileBasedSrcSelected()) { //! @todo Back button doesn't work after selecting a file to import } else { if (!d->srcProjectSelector) { QVBoxLayout *vbox = new QVBoxLayout(d->srcDBPageWidget); d->srcProjectSelector = new KexiProjectSelectorWidget(d->srcDBPageWidget); vbox->addWidget(d->srcProjectSelector); KexiUtils::setStandardMarginsAndSpacing(vbox); d->srcProjectSelector->label()->setText(xi18n("Select source database you wish to import:")); } d->srcDBPageWidget->hide(); KDbConnectionData* condata = d->srcConn->selectedConnectionData(); Q_ASSERT(condata); Q_ASSERT(d->prjSet); d->srcProjectSelector->setProjectSet(d->prjSet); d->srcDBPageWidget->show(); } } -void ImportWizard::arriveDstTitlePage() +void ImportWizard::arriveDstCaptionPage() { d->dstNewDBNameUrlLabel->setVisible(fileBasedDstSelected()); d->dstNewDBNameUrl->setVisible(fileBasedDstSelected()); d->dstNewDBNameLabel->setVisible(!fileBasedDstSelected()); d->dstNewDBNameLineEdit->setVisible(!fileBasedDstSelected()); if (fileBasedSrcSelected()) { const QString fname(selectedSourceFileName()); QString suggestedDBName(QFileInfo(fname).fileName()); const QFileInfo fi(suggestedDBName); suggestedDBName = suggestedDBName.left(suggestedDBName.length() - (fi.completeSuffix().isEmpty() ? 0 : (fi.completeSuffix().length() + 1))); - d->dstNewDBTitleLineEdit->setText(suggestedDBName); + d->dstNewDBCaptionLineEdit->setText(suggestedDBName); } else { if (d->predefinedConnectionData) { // server source db is predefined - d->dstNewDBTitleLineEdit->setText(d->predefinedDatabaseName); + d->dstNewDBCaptionLineEdit->setText(d->predefinedDatabaseName); } else { if (!d->srcProjectSelector || !d->srcProjectSelector->selectedProjectData()) { back(); //!< @todo return; } - d->dstNewDBTitleLineEdit->setText(d->srcProjectSelector->selectedProjectData()->databaseName()); + d->dstNewDBCaptionLineEdit->setText(d->srcProjectSelector->selectedProjectData()->databaseName()); } } - d->dstNewDBTitleLineEdit->selectAll(); - d->dstNewDBTitleLineEdit->setFocus(); + d->dstNewDBCaptionLineEdit->selectAll(); + d->dstNewDBCaptionLineEdit->setFocus(); updateDestinationDBFileName(); } void ImportWizard::arriveDstPage() { if (fileBasedDstSelected()) { d->dstPageWidget->hide(); KAssistantDialog::next(); return; } else { d->dstConn->showAdvancedConnection(); } d->dstPageWidget->show(); } void ImportWizard::arriveImportingPage() { d->importingPageWidget->hide(); nextButton()->setEnabled(checkUserInput()); d->lblImportingTxt->setText(xi18nc("@info", "All required information has now " "been gathered. Click Next button to start importing." "Depending on size of the database this may take some time." /*"Note: You may be asked for extra " "information such as field types if " "the wizard could not automatically " "determine this for you."*/)); //temp. hack for MS Access driver only //! @todo for other databases we will need KexiMigration::Connection //! and KexiMigration::Driver classes bool showOptions = false; if (fileBasedSrcSelected()) { Kexi::ObjectStatus result; KexiMigrate* sourceDriver = prepareImport(result); if (sourceDriver) { showOptions = !result.error() && sourceDriver->propertyValue("source_database_has_nonunicode_encoding").toBool(); sourceDriver->setData(nullptr); } } if (showOptions) d->importOptionsButton->show(); else d->importOptionsButton->hide(); d->importingPageWidget->show(); } void ImportWizard::arriveFinishPage() { } bool ImportWizard::fileBasedSrcSelected() const { if (d->predefinedConnectionData) return false; // qDebug() << (d->srcConn->selectedConnectionType()==KexiConnectionSelectorWidget::FileBased); return d->srcConn->selectedConnectionType() == KexiConnectionSelectorWidget::FileBased; } bool ImportWizard::fileBasedDstSelected() const { return d->dstPrjTypeSelector->option_file->isChecked(); } void ImportWizard::progressUpdated(int percent) { d->progressBar->setValue(percent); qApp->processEvents(); } QString ImportWizard::driverIdForMimeType(const QMimeType &mime) const { if (!mime.isValid()) { return QString(); } const QStringList ids(d->migrateManager.driverIdsForMimeType(mime.name())); //! @todo do we want to return first migrate driver for the mime type or allow to select it? return ids.isEmpty() ? QString() : ids.first(); } QString ImportWizard::findDriverIdForSelectedSource() { if (fileBasedSrcSelected()) { QMimeDatabase db; QMimeType mime = db.mimeTypeForFile(selectedSourceFileName()); if (!mime.isValid() || mime.name() == "application/octet-stream" || mime.name() == "text/plain" || mime.name() == "application/zip") { //try by URL: mime = db.mimeTypeForFile(selectedSourceFileName()); } return driverIdForMimeType(mime); } //server-based QString sourceDriverId; if (d->predefinedConnectionData) { sourceDriverId = d->predefinedConnectionData->driverId(); } else if (d->srcConn->selectedConnectionData()) { sourceDriverId = d->srcConn->selectedConnectionData()->driverId(); } const QStringList migrationDriverIds(d->migrateManager.driverIdsForSourceDriver(sourceDriverId)); //! @todo First found driver ID is picked. It's OK as long as there is one migration //! driver per source database type. How about allowing users to pick migration driver? return migrationDriverIds.isEmpty() ? QString() : migrationDriverIds.first(); } //=========================================================== // void ImportWizard::accept() { if (d->args) { if ((!fileBasedDstSelected() && !d->args->contains("destinationConnectionShortcut")) || !d->openImportedProjectCheckBox->isChecked()) { //do not open dest db if used didn't want it //for server connections, destinationConnectionShortcut must be defined d->args->remove("destinationDatabaseName"); } } KAssistantDialog::accept(); } KexiMigrate* ImportWizard::prepareImport(Kexi::ObjectStatus& result) { KexiUtils::WaitCursor wait; // Start with a driver manager KDbDriverManager manager; //qDebug() << "Creating destination driver..."; // Get a driver to the destination database KDbDriver *destDriver = manager.driver( d->dstConn->selectedConnectionData() ? d->dstConn->selectedConnectionData()->driverId() : KDb::defaultFileBasedDriverId()); if (!destDriver || manager.result().isError()) { result.setStatus(manager.resultable()); qWarning() << "Manager error:" << manager.result(); } // Set up destination connection data KDbConnectionData *cdata = 0; QScopedPointer cdataDeleter; QString dbname; if (!result.error()) { if (d->dstConn->selectedConnectionData()) { //server-based project qDebug() << "Server destination..."; cdata = d->dstConn->selectedConnectionData(); dbname = d->dstNewDBNameLineEdit->text(); } else { //file-based project qDebug() << "File Destination..."; cdata = new KDbConnectionData(); cdataDeleter.reset(cdata); // ownership won't be transferred - cdata->setCaption(d->dstNewDBTitleLineEdit->text()); + cdata->setCaption(d->dstNewDBCaptionLineEdit->text()); cdata->setDriverId(KDb::defaultFileBasedDriverId()); - dbname = d->dstTitlePageWidget->file_requester->url().toLocalFile(); + dbname = d->dstCaptionPageWidget->file_requester->url().toLocalFile(); cdata->setDatabaseName(dbname); qDebug() << "Current file name:" << dbname; } } // Find a source (migration) driver name if (!result.error()) { if (d->driverIdForSelectedSource.isEmpty()) result.setStatus(xi18n("No appropriate migration driver found."), d->migrateManager.possibleProblemsMessage()); } // Get a source (migration) driver KexiMigrate* sourceDriver = 0; if (!result.error()) { sourceDriver = d->migrateManager.driver(d->driverIdForSelectedSource); if (!sourceDriver || d->migrateManager.result().isError()) { qDebug() << "Import migrate driver error..."; result.setStatus(d->migrateManager.resultable()); } } KexiUtils::removeWaitCursor(); // Set up source (migration) data required for connection if (sourceDriver && !result.error() && cdata) { // Setup progress feedback for the GUI if (sourceDriver->progressSupported()) { d->progressBar->updateGeometry(); disconnect(sourceDriver, SIGNAL(progressPercent(int)), this, SLOT(progressUpdated(int))); connect(sourceDriver, SIGNAL(progressPercent(int)), this, SLOT(progressUpdated(int))); progressUpdated(0); } bool keepData; if (d->importTypeStructureAndDataCheckBox->isChecked()) { qDebug() << "Structure and data selected"; keepData = true; } else if (d->importTypeStructureOnlyCheckBox->isChecked()) { qDebug() << "structure only selected"; keepData = false; } else { qDebug() << "Neither radio button is selected (not possible?) presume keep data"; keepData = true; } KexiMigration::Data* md = new KexiMigration::Data(); md->setDestinationProjectData(new KexiProjectData(*cdata, dbname)); if (fileBasedSrcSelected()) { KDbConnectionData* conn_data = new KDbConnectionData(); conn_data->setDatabaseName(selectedSourceFileName()); md->source = conn_data; md->sourceName.clear(); } else { if (d->predefinedConnectionData) md->source = d->predefinedConnectionData; else md->source = d->srcConn->selectedConnectionData(); if (!d->predefinedDatabaseName.isEmpty()) md->sourceName = d->predefinedDatabaseName; else md->sourceName = d->srcProjectSelector->selectedProjectData()->databaseName(); //! @todo Aah, this is so C-like. Move to performImport(). } md->setShouldCopyData(keepData); sourceDriver->setData(md); return sourceDriver; } return 0; } tristate ImportWizard::import() { d->importExecuted = true; Kexi::ObjectStatus result; KexiMigrate* sourceDriver = prepareImport(result); bool acceptingNeeded = false; // Perform import if (sourceDriver && !result.error()) { if (!d->sourceDBEncoding.isEmpty()) { sourceDriver->setPropertyValue("source_database_nonunicode_encoding", QVariant(d->sourceDBEncoding.toUpper().remove(' ')) // "CP1250", not "cp 1250" ); } if (!sourceDriver->checkIfDestinationDatabaseOverwritingNeedsAccepting(&result, &acceptingNeeded)) { qDebug() << "Abort import cause checkIfDestinationDatabaseOverwritingNeedsAccepting " "returned false."; return false; } qDebug() << sourceDriver->data()->destinationProjectData()->databaseName(); qDebug() << "Performing import..."; } if (sourceDriver && !result.error() && acceptingNeeded) { // ok, the destination-db already exists... if (KMessageBox::Yes != KMessageBox::warningYesNo(this, xi18nc("@info (don't add tags around %1, it's done already)", "Database %1 already exists." "Do you want to replace it with a new one?", KexiUtils::localizedStringToHtmlSubstring( sourceDriver->data()->destinationProjectData()->infoString())), 0, KGuiItem(xi18nc("@action:button Replace Database", "&Replace")), KStandardGuiItem::no())) { return cancelled; } } if (sourceDriver && !result.error() && sourceDriver->progressSupported()) { d->progressBar->show(); } if (sourceDriver && !result.error() && sourceDriver->performImport(&result)) { if (d->args) { d->args->insert("destinationDatabaseName", fileBasedDstSelected() ? sourceDriver->data()->destinationProjectData()->connectionData()->databaseName() : sourceDriver->data()->destinationProjectData()->databaseName()); QString destinationConnectionShortcut; if (d->dstConn->selectedConnectionData()) { destinationConnectionShortcut = Kexi::connset().fileNameForConnectionData(*d->dstConn->selectedConnectionData()); } if (!destinationConnectionShortcut.isEmpty()) { d->args->insert("destinationConnectionShortcut", destinationConnectionShortcut); } } d->finishPageItem->setHeader(xi18n("Success")); return true; } if (!sourceDriver || result.error()) { d->progressBar->setValue(0); d->progressBar->hide(); QString msg, details; KexiTextMessageHandler handler(&msg, &details); handler.showErrorMessage(&result); qDebug() << msg << "\n" << details; d->finishPageItem->setHeader(xi18n("Failure")); // note: we're using .arg() here because the msg and details arguments are already in rich-text format d->finishLbl->setText( xi18nc("@info", "Import failed." "%1" "%2" "You can click Back button and try again.") .arg(msg).arg(details)); return false; } return true; } void ImportWizard::reject() { KAssistantDialog::reject(); } //=========================================================== // void ImportWizard::next() { if (currentPage() == d->srcConnPageItem) { if (fileBasedSrcSelected() && /*! @todo use QUrl? */!QFileInfo(selectedSourceFileName()).isFile()) { KMessageBox::sorry(this, xi18n("Select source database filename.")); return; } KDbConnectionData* conndata = d->srcConn->selectedConnectionData(); if (!fileBasedSrcSelected() && !conndata) { KMessageBox::sorry(this, xi18n("Select source database.")); return; } d->driverIdForSelectedSource = findDriverIdForSelectedSource(); // cache KexiMigrate* import = d->migrateManager.driver(d->driverIdForSelectedSource); if (!import || d->migrateManager.result().isError()) { QString dbname; if (fileBasedSrcSelected()) dbname = QDir::toNativeSeparators(selectedSourceFileName()); else dbname = conndata ? conndata->toUserVisibleString() : QString(); KMessageBox::error(this, dbname.isEmpty() ? xi18n("Could not import database. This type is not supported.") : xi18nc("@info", "Could not import database %1. " "This type is not supported.", dbname)); return; } if (!fileBasedSrcSelected()) { // make sure we have password if needed tristate passwordNeeded = false; if (conndata->password().isEmpty()) { passwordNeeded = KexiDBPasswordDialog::getPasswordIfNeeded(conndata, this); } bool ok = passwordNeeded != cancelled; if (ok) { KexiGUIMessageHandler handler; d->prjSet = new KexiProjectSet(&handler); if (!d->prjSet->setConnectionData(conndata)) { handler.showErrorMessage(d->prjSet->result()); ok = false; } } if (!ok) { if (passwordNeeded == true) { conndata->setPassword(QString::null); // not clear(), we have to remove password } delete d->prjSet; d->prjSet = 0; return; } } - } else if (currentPage() == d->dstTitlePageItem) { + } else if (currentPage() == d->dstCaptionPageItem) { if (fileBasedDstSelected()) { if (QFileInfo::exists(d->dstNewDBNameUrl->url().toLocalFile())) { if (!KexiUtils::askForFileOverwriting(d->dstNewDBNameUrl->url().toLocalFile(), this)) { return; } } } } else if (currentPage() == d->importTypePageItem) { if (!fileBasedDstSelected()) { // make sure we have password if needed tristate passwordNeeded = false; KDbConnectionData* condata = d->dstConn->selectedConnectionData(); if (condata->password().isEmpty()) { passwordNeeded = KexiDBPasswordDialog::getPasswordIfNeeded(condata, this); } bool ok = passwordNeeded != cancelled; if (!ok) { if (passwordNeeded == true) { condata->setPassword(QString::null); // not clear(), we have to remove password } return; } } } else if (currentPage() == d->importingPageItem) { if (!d->importExecuted) { d->importOptionsButton->hide(); backButton()->setEnabled(false); nextButton()->setEnabled(false); finishButton()->setEnabled(false); d->lblImportingTxt->setText(xi18n("Importing in progress...")); tristate res = import(); if (true == res) { d->finishLbl->setText( xi18nc("@info", "Database has been imported into Kexi project %1.", d->dstNewDBNameLineEdit->text())); button(QDialogButtonBox::Cancel)->setEnabled(false); backButton()->setEnabled(false); nextButton()->setEnabled(true); finishButton()->setEnabled(false); d->openImportedProjectCheckBox->show(); next(); return; } d->progressBar->hide(); button(QDialogButtonBox::Cancel)->setEnabled(true); backButton()->setEnabled(true); nextButton()->setEnabled(false); finishButton()->setEnabled(false); d->openImportedProjectCheckBox->hide(); if (!res) next(); else if (~res) { arriveImportingPage(); } d->importExecuted = false; return; } } setAppropriate(d->srcDBPageItem, !fileBasedSrcSelected() && !d->predefinedConnectionData); setAppropriate(d->dstPageItem, !fileBasedDstSelected()); KAssistantDialog::next(); } void ImportWizard::back() { setAppropriate(d->srcDBPageItem, !fileBasedSrcSelected() && !d->predefinedConnectionData); KAssistantDialog::back(); } void ImportWizard::slot_currentPageChanged(KPageWidgetItem* curPage,KPageWidgetItem* prevPage) { Q_UNUSED(prevPage); if (curPage == d->introPageItem) { } else if (curPage == d->srcConnPageItem) { arriveSrcConnPage(); } else if (curPage == d->srcDBPageItem) { arriveSrcDBPage(); } else if (curPage == d->dstTypePageItem) { - } else if (curPage == d->dstTitlePageItem) { - arriveDstTitlePage(); + } else if (curPage == d->dstCaptionPageItem) { + arriveDstCaptionPage(); } else if (curPage == d->dstPageItem) { if (fileBasedDstSelected()) { if (prevPage == d->importTypePageItem) { KAssistantDialog::back(); } else { KAssistantDialog::next(); } } else { arriveDstPage(); } } else if (curPage == d->importingPageItem) { arriveImportingPage(); } else if (curPage == d->finishPageItem) { arriveFinishPage(); } } void ImportWizard::helpClicked() { if (currentPage() == d->introPageItem) { KMessageBox::information(this, xi18n("No help is available for this page."), xi18n("Help")); } else if (currentPage() == d->srcConnPageItem) { KMessageBox::information(this, xi18n("Here you can choose the location to import data from."), xi18n("Help")); } else if (currentPage() == d->srcDBPageItem) { KMessageBox::information(this, xi18n("Here you can choose the actual database to import data from."), xi18n("Help")); } else if (currentPage() == d->dstTypePageItem) { KMessageBox::information(this, xi18n("Here you can choose the location to save the data."), xi18n("Help")); } else if (currentPage() == d->dstPageItem) { KMessageBox::information(this, xi18n("Here you can choose the location to save the data in and the new database name."), xi18n("Help")); } else if (currentPage() == d->finishPageItem || currentPage() == d->importingPageItem) { KMessageBox::information(this, xi18n("No help is available for this page."), xi18n("Help")); } } void ImportWizard::slotOptionsButtonClicked() { OptionsDialog dlg(selectedSourceFileName(), d->sourceDBEncoding, this); if (QDialog::Accepted == dlg.exec()) { d->sourceDBEncoding = dlg.encodingComboBox()->selectedEncoding(); } } void ImportWizard::sourceConnectionSelected(bool selected) { if (selected) { next(); } } diff --git a/src/migration/importwizard.h b/src/migration/importwizard.h index 17dd2493f..a3aaa8101 100644 --- a/src/migration/importwizard.h +++ b/src/migration/importwizard.h @@ -1,118 +1,118 @@ -/* This file is part of the KDE project +/* This file is part of the KDE project Copyright (C) 2004 Adam Pigg Copyright (C) 2004-2016 Jarosław Staniek Copyright (C) 2005 Martin Ellis This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KEXIMIGRATIONIMPORTWIZARD_H #define KEXIMIGRATIONIMPORTWIZARD_H #include "migratemanager.h" #include #include #include class QMimeType; class QLabel; class KPageWidgetItem; namespace Kexi { class ObjectStatus; } namespace KexiMigration { class KexiMigrate; //! GUI for importing external databases (file-based and server-based) class KEXIMIGRATE_EXPORT ImportWizard : public KAssistantDialog { Q_OBJECT public: /*! Creates wizard's instance. \a args contains arguments that can be parsed by parseArguments(). \a *arg will be also set to imported project's filename on success and to null value on failure or cancellation. */ explicit ImportWizard(QWidget *parent = 0, QMap* args = 0); virtual ~ImportWizard(); public Q_SLOTS: void progressUpdated(int percent); protected Q_SLOTS: virtual void next(); virtual void back(); void slot_currentPageChanged(KPageWidgetItem*,KPageWidgetItem*); virtual void accept(); virtual void reject(); void helpClicked(); void slotOptionsButtonClicked(); - void destinationTitleTextChanged(const QString & text); + void destinationCaptionTextChanged(const QString &text); void sourceConnectionSelected(bool selected); private: void parseArguments(); void setupIntro(); void setupSrcConn(); void setupSrcDB(); void setupDstType(); - void setupDstTitle(); + void setupDstCaption(); void setupDst(); void setupFinish(); void setupImportType(); void setupImporting(); bool checkUserInput(); KexiMigrate* prepareImport(Kexi::ObjectStatus& result); /*! Performs import. \return true/false on success/faulure or cancelled when user cancelled importing (mainly because didn't allow overwriting an existing database by a new one). */ tristate import(); bool fileBasedSrcSelected() const; bool fileBasedDstSelected() const; QString driverIdForSelectedSource() const; QString driverIdForMimeType(const QMimeType &mime) const; QString findDriverIdForSelectedSource(); void arriveSrcConnPage(); void arriveSrcDBPage(); - void arriveDstTitlePage(); + void arriveDstCaptionPage(); void arriveDstPage(); void arriveFinishPage(); void arriveImportingPage(); //! @return source filename selected by user or preselected one (if present) QString selectedSourceFileName() const; void updateDestinationDBFileName(); class Private; Private * const d; }; } #endif diff --git a/src/widget/CMakeLists.txt b/src/widget/CMakeLists.txt index 09e2de7b8..d53a91915 100644 --- a/src/widget/CMakeLists.txt +++ b/src/widget/CMakeLists.txt @@ -1,111 +1,111 @@ add_subdirectory( dataviewcommon ) add_subdirectory( relations ) add_subdirectory( undo ) add_subdirectory( utils ) if(SHOULD_BUILD_KEXI_DESKTOP_APP) add_subdirectory( tableview ) endif() add_definitions(-DKDE_DEFAULT_DEBUG_AREA=44023) include_directories(${CMAKE_SOURCE_DIR}/src/widget/tableview ${CMAKE_SOURCE_DIR}/src/core) ########### next target ############### set(kexiextendedwidgets_LIB_SRCS fields/KexiFieldComboBox.cpp fields/KexiFieldListModel.cpp fields/KexiFieldListModelItem.cpp fields/KexiFieldListView.cpp navigator/KexiProjectModel.cpp navigator/KexiProjectModelItem.cpp navigator/KexiProjectItemDelegate.cpp navigator/KexiProjectNavigator.cpp navigator/KexiProjectTreeView.cpp properties/KexiCustomPropertyFactory.cpp properties/KexiCustomPropertyFactory_p.cpp properties/KexiPropertyEditorView.cpp properties/KexiPropertyPaneViewBase.cpp kexiquerydesignersqleditor.cpp kexiqueryparameters.cpp kexisectionheader.cpp kexidbdrivercombobox.cpp kexieditor.cpp KexiDataSourceComboBox.cpp KexiObjectInfoLabel.cpp kexicharencodingcombobox.cpp - KexiDBTitlePage.cpp + KexiDBCaptionPage.cpp KexiProjectSelectorWidget.cpp kexislider.cpp KexiServerDriverNotFoundMessage.cpp KexiNameWidget.cpp KexiNameDialog.cpp KexiFileWidgetInterface.cpp KexiFileRequester.cpp KexiStartupFileHandler.cpp KexiListView.cpp ) if(SHOULD_BUILD_KEXI_DESKTOP_APP) list(APPEND kexiextendedwidgets_LIB_SRCS #navigator/KexiProjectListView.cpp #navigator/KexiProjectListViewItem.cpp kexidbconnectionwidget.cpp # TODO replace use of KexiProjectListView and KexiProjectListViewList (with KexiProjectNavigator) # in kexiactionselectiondialog and remove them kexiprjtypeselector.cpp KexiConnectionSelectorWidget.cpp KexiFileDialog.cpp KexiPasswordWidget.cpp KexiDBPasswordDialog.cpp ) if(KEXI_USE_KFILEWIDGET) list(APPEND kexiextendedwidgets_LIB_SRCS KexiFileWidget.cpp) endif() ki18n_wrap_ui(kexiextendedwidgets_LIB_SRCS KexiConnectionSelector.ui kexidbconnectionwidget.ui kexidbconnectionwidgetdetails.ui kexiprjtypeselector.ui KexiPasswordWidget.ui ) endif () ki18n_wrap_ui(kexiextendedwidgets_LIB_SRCS - KexiDBTitlePage.ui + KexiDBCaptionPage.ui KexiProjectSelector.ui ) kexi_add_library(kexiextendedwidgets SHARED ${kexiextendedwidgets_LIB_SRCS}) generate_export_header(kexiextendedwidgets BASE_NAME kexiextwidgets) target_link_libraries(kexiextendedwidgets PRIVATE kexidataviewcommon kexiguiutils KF5::TextWidgets # KTextEdit KF5::Codecs # KCharsets PUBLIC kexicore KPropertyWidgets KF5::TextEditor ) if(KEXI_USE_KFILEWIDGET) target_link_libraries(kexiextendedwidgets PUBLIC KF5::KIOFileWidgets) # KFileWidget else() target_link_libraries(kexiextendedwidgets PRIVATE KF5::KIOFileWidgets) # KFileWidget::getStartUrl, KFileFilterCombo endif() install(TARGETS kexiextendedwidgets ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/src/widget/KexiDBTitlePage.cpp b/src/widget/KexiDBCaptionPage.cpp similarity index 86% rename from src/widget/KexiDBTitlePage.cpp rename to src/widget/KexiDBCaptionPage.cpp index d2d976d06..7addde54e 100644 --- a/src/widget/KexiDBTitlePage.cpp +++ b/src/widget/KexiDBCaptionPage.cpp @@ -1,33 +1,33 @@ /* This file is part of the KDE project Copyright (C) 2004 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -#include "KexiDBTitlePage.h" +#include "KexiDBCaptionPage.h" -KexiDBTitlePage::KexiDBTitlePage(const QString& labelText, QWidget* parent) +KexiDBCaptionPage::KexiDBCaptionPage(const QString& labelText, QWidget* parent) : QWidget(parent) { setupUi(this); if (!labelText.isEmpty()) label->setText(labelText); } -KexiDBTitlePage::~KexiDBTitlePage() +KexiDBCaptionPage::~KexiDBCaptionPage() { } diff --git a/src/widget/KexiDBTitlePage.h b/src/widget/KexiDBCaptionPage.h similarity index 69% rename from src/widget/KexiDBTitlePage.h rename to src/widget/KexiDBCaptionPage.h index fe50f9cc6..d19aa7d06 100644 --- a/src/widget/KexiDBTitlePage.h +++ b/src/widget/KexiDBCaptionPage.h @@ -1,38 +1,40 @@ /* This file is part of the KDE project Copyright (C) 2004 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -#ifndef KEXIDBTITLEPAGE_H -#define KEXIDBTITLEPAGE_H +#ifndef KEXIDBCAPTIONPAGE_H +#define KEXIDBCAPTIONPAGE_H #include "kexiextwidgets_export.h" -#include "ui_KexiDBTitlePage.h" +#include "ui_KexiDBCaptionPage.h" #include //! @short A helper widget used to displaying a line edit with a label and layout -class KEXIEXTWIDGETS_EXPORT KexiDBTitlePage : public QWidget, public Ui_KexiDBTitlePage +class KEXIEXTWIDGETS_EXPORT KexiDBCaptionPage : public QWidget, public Ui_KexiDBCaptionPage { Q_OBJECT public: - //! Constructs title page. \a labelText can be provided to change default - //! "Project caption:" label. - explicit KexiDBTitlePage(const QString& labelText, QWidget* parent = 0); - ~KexiDBTitlePage(); + //! Constructs a caption editing page. + //! + //! \a labelText can be provided to change default "Project caption:" label. + explicit KexiDBCaptionPage(const QString &labelText, QWidget *parent = nullptr); + + ~KexiDBCaptionPage(); }; -#endif // KEXIDBTITLEPAGE_H +#endif // KEXIDBCAPTIONPAGE_H diff --git a/src/widget/KexiDBTitlePage.ui b/src/widget/KexiDBCaptionPage.ui similarity index 84% rename from src/widget/KexiDBTitlePage.ui rename to src/widget/KexiDBCaptionPage.ui index c1e1bad7d..5924bc003 100644 --- a/src/widget/KexiDBTitlePage.ui +++ b/src/widget/KexiDBCaptionPage.ui @@ -1,147 +1,156 @@ - KexiDBTitlePage - + KexiDBCaptionPage + 0 0 460 154 - + + 0 + + + 0 + + + 0 + + 0 - Project title: + Pro&ject caption: false - le_title + le_caption - + 1 0 100 0 - + true - Project filename: + Project file&name: false file_requester 1 0 KFile::File|KFile::LocalOnly Qt::Horizontal QSizePolicy::Minimum 30 25 Qt::Vertical QSizePolicy::Expanding 20 111 Qt::Horizontal QSizePolicy::Minimum 40 20 - - KUrlRequester - QWidget -
KUrlRequester
-
KLineEdit QLineEdit -
KLineEdit
+
klineedit.h
+
+ + KUrlRequester + QWidget +
kurlrequester.h