void KexiReportView::slotExportAsPdf() { QScopedPointer<KoReportRendererBase> renderer(m_factory.createInstance("print")); if (renderer) { KoReportRendererContext cxt; cxt.destinationUrl = getExportUrl(QLatin1String("application/pdf"), xi18n("Export Report as PDF"), "kfiledialog:///LastVisitedPDFExportPath/", "pdf"); if (!cxt.destinationUrl.isValid()) { return; } QPrinter printer; QPainter painter; printer.setOutputFileName(cxt.destinationUrl.path()); printer.setOutputFormat(QPrinter::PdfFormat); printer.setColorMode(QPrinter::Color); painter.begin(&printer); cxt.printer = &printer; cxt.painter = &painter; if (!renderer->render(cxt, m_reportDocument)) { KMessageBox::error(this, xi18n("Exporting the report as PDF to %1 failed.", cxt.destinationUrl.toDisplayString()), xi18n("Export Failed")); } else { openExportedDocument(cxt.destinationUrl); } } }
void KexiReportView::slotExportAsTextDocument() { KoReportRendererBase *renderer; KoReportRendererContext cxt; renderer = m_factory.createInstance("odt"); if (renderer) { cxt.destinationUrl = getExportUrl(QLatin1String("application/vnd.oasis.opendocument.text"), xi18n("Export Report as Text Document"), "kfiledialog:///LastVisitedODTExportPath/", "odt"); if (!cxt.destinationUrl.isValid()) { return; } if (!renderer->render(cxt, m_reportDocument)) { KMessageBox::error(this, xi18n("Exporting the report as text document to %1 failed.", cxt.destinationUrl.toDisplayString()), xi18n("Export Failed")); } else { openExportedDocument(cxt.destinationUrl); } } }
/******************************************************************* ** INDI Menu: Handles communication to server and fetching basic XML ** data. *******************************************************************/ INDIMenu::INDIMenu(QWidget *parent) : QWidget(parent, Qt::Window) { ksw = (KStars *) parent; mainLayout = new QVBoxLayout(this); mainLayout->setMargin(10); mainLayout->setSpacing(10); mainTabWidget = new QTabWidget(this); mainLayout->addWidget(mainTabWidget); setWindowTitle(xi18n("INDI Control Panel")); setAttribute(Qt::WA_ShowModal, false); clearB = new QPushButton(xi18n("Clear")); closeB = new QPushButton(xi18n("Close")); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->insertStretch(0); buttonLayout->addWidget(clearB, 0, Qt::AlignRight); buttonLayout->addWidget(closeB, 0, Qt::AlignRight); mainLayout->addLayout(buttonLayout); connect(closeB, SIGNAL(clicked()), this, SLOT(close())); connect(clearB, SIGNAL(clicked()), this, SLOT(clearLog())); resize( 640, 480); }
QString SkyObjItem::getDesc() const { if (m_Type == Planet) { KSFileReader fileReader; if (!fileReader.open("PlanetFacts.dat")) return xi18n("No Description found for selected sky-object"); while (fileReader.hasMoreLines()) { QString line = fileReader.readLine(); if(line.length() != 0 && line[0] != '#') { QString soname = line.split("::")[0]; QString desc = line.split("::")[1]; if (soname == m_Name) { return desc; } } } } if(skd) { if(skd->downloadedData() != "") return skd->downloadedData(); } if(m_Type == Star) return xi18n("Bright Star"); return getTypeName(); }
static QString captionForDialogType(int type) { if (type == KexiStartupDialog::Templates) return xi18n("Create Project"); else if (type == KexiStartupDialog::OpenExisting) return xi18n("Open Existing Project"); return xi18n("Choose Project"); }
QVariant KexiFieldListModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) return QVariant(); if (orientation == Qt::Horizontal) { if (section == 0) { return xi18n("Field Name"); } else if (section == 1) { return xi18n("Data Type"); } } return QVariant(); }
QString SkyObjItem::getDescSource() { if (m_Type == Planet) { return xi18n("(Source: Wikipedia)"); } if(skd) { if(!skd->downloadedData().isEmpty() && !skd->url().isEmpty()) return "(Source: <a href=\"" + skd->url() + "\">Wikipedia</a>)"; } return xi18n("(Source: N/A)"); }
KexiCSVTextQuoteComboBox::KexiCSVTextQuoteComboBox(QWidget * parent) : KComboBox(parent) { addItem("\""); addItem("'"); addItem(xi18n("None")); }
void ExtractJob::doWork() { QString desc; if (m_entries.count() == 0) { desc = i18n("Extracting all files"); } else { desc = i18np("Extracting one file", "Extracting %1 files", m_entries.count()); } emit description(this, desc, qMakePair(i18n("Archive"), archiveInterface()->filename()), qMakePair(i18nc("extraction folder", "Destination"), m_destinationDir)); QFileInfo destDirInfo(m_destinationDir); if (destDirInfo.isDir() && (!destDirInfo.isWritable() || !destDirInfo.isExecutable())) { onError(xi18n("Could not write to destination <filename>%1</filename>.<nl/>Check whether you have sufficient permissions.", m_destinationDir), QString()); onFinished(false); return; } connectToArchiveInterfaceSignals(); qCDebug(ARK) << "Starting extraction with" << m_entries.count() << "selected files." << m_entries << "Destination dir:" << m_destinationDir << "Options:" << m_options; bool ret = archiveInterface()->extractFiles(m_entries, m_destinationDir, m_options); if (!archiveInterface()->waitForFinishedSignal()) { onFinished(ret); } }
tristate KexiReportView::afterSwitchFrom(Kexi::ViewMode mode) { Q_UNUSED(mode); qDebug(); if (tempData()->reportSchemaChangedInPreviousView) { qDebug() << "Schema changed"; delete m_preRenderer; qDebug() << tempData()->reportDefinition.tagName(); m_preRenderer = new KoReportPreRenderer(tempData()->reportDefinition); if (m_preRenderer->isValid()) { KoReportData *reportData = 0; if (!tempData()->connectionDefinition.isNull()) { reportData = sourceData(tempData()->connectionDefinition); } m_preRenderer->setSourceData(reportData); m_preRenderer->setName(window()->partItem()->name()); //Add a kexi object to provide kexidb and extra functionality //! @todo KEXI3 if we want this if(!m_kexi) { // m_kexi = new KexiScriptAdaptor(); // } // m_preRenderer->registerScriptObject(m_kexi, "Kexi"); //If using a kexidb source, add a functions scripting object if (tempData()->connectionDefinition.attribute("type") == "internal") { m_functions = new KRScriptFunctions(reportData, KexiMainWindowIface::global()->project()->dbConnection()); m_preRenderer->registerScriptObject(m_functions, "field"); connect(m_preRenderer, SIGNAL(groupChanged(QMap<QString, QVariant>)), m_functions, SLOT(setGroupData(QMap<QString, QVariant>))); } if (m_reportDocument) { qDebug() << "=======================================Deleting old document"; delete m_reportDocument; } m_reportDocument = m_preRenderer->generate(); if (m_reportDocument) { m_reportView->setDocument(m_reportDocument); #ifndef KEXI_MOBILE m_pageSelector->setRecordCount(m_reportView->pageCount()); m_pageSelector->setCurrentRecordNumber(1); #endif } } else { KMessageBox::error(this, xi18n("Report schema appears to be invalid or corrupt"), xi18n("Opening failed")); } tempData()->reportSchemaChangedInPreviousView = false; } return true; }
/********************************************************************* ** Traverse the drivers list, check for updated drivers and take ** appropriate action *********************************************************************/ void INDIMenu::updateStatus() { if (managers.size() == 0) { KMessageBox::error(0, xi18n("No INDI devices currently running. To run devices, please select devices from the Device Manager in the devices menu.")); return; } show(); }
void KexiFormPart::setupCustomPropertyPanelTabs(QTabWidget *tab) { if (!d->dataSourcePage) { d->dataSourcePage = new KexiDataSourcePage(0); d->dataSourcePage->setObjectName("dataSourcePage"); connect(d->dataSourcePage, SIGNAL(jumpToObjectRequested(QString,QString)), KexiMainWindowIface::global()->thisWidget(), SLOT(highlightObject(QString,QString))); connect(d->dataSourcePage, SIGNAL(formDataSourceChanged(QString,QString)), KexiFormManager::self(), SLOT(setFormDataSource(QString,QString))); connect(d->dataSourcePage, SIGNAL(dataSourceFieldOrExpressionChanged(QString,QString,KDbField::Type)), KexiFormManager::self(), SLOT(setDataSourceFieldOrExpression(QString,QString,KDbField::Type))); #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT connect(d->dataSourcePage, SIGNAL(insertAutoFields(QString,QString,QStringList)), KexiFormManager::self(), SLOT(insertAutoFields(QString,QString,QStringList))); #endif } KexiProject *prj = KexiMainWindowIface::global()->project(); d->dataSourcePage->setProject(prj); tab->addTab(d->dataSourcePage, koIcon("server-database"), QString()); tab->setTabToolTip(tab->indexOf(d->dataSourcePage), xi18n("Data Source")); if (!d->widgetTreeWidget) { d->widgetTreeWidget = new QWidget; QVBoxLayout *lyr = new QVBoxLayout(d->widgetTreeWidget); lyr->setContentsMargins(2, 2, 2, 2); d->widgetTree = new KFormDesigner::WidgetTreeWidget; d->widgetTree->setObjectName("KexiFormPart:WidgetTreeWidget"); lyr->addWidget(d->widgetTree); } tab->addTab(d->widgetTreeWidget, koIcon("widgets"), QString()); tab->setTabToolTip(tab->indexOf(d->widgetTreeWidget), xi18n("Widgets")); }
KexiCSVCommentWidget::KexiCSVCommentWidget(bool lineEditOnBottom, QWidget *parent) : QWidget(parent) , d(new Private()) { QBoxLayout *lyr = new QBoxLayout(lineEditOnBottom ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); setLayout(lyr); KexiUtils::setMargins(lyr, 0); lyr->setSpacing(KexiUtils::spacingHint()); d->combo = new KComboBox(this); d->combo->setObjectName("KexiCSVcommentSymbolComboBox"); d->combo->addItem(xi18n("None")); d->combo->addItem(xi18n("Hash \"#\"")); lyr->addWidget(d->combo); setFocusProxy(d->combo); const int numberOfNonePosition = 0; slotcommentSymbolChangedInternal(numberOfNonePosition); connect(d->combo, SIGNAL(activated(int)), this, SLOT(slotcommentSymbolChanged(int))); }
void SkyObjItem::setPosition(SkyObject* so) { KStarsData *data = KStarsData::Instance(); KStarsDateTime ut = data->geo()->LTtoUT(KStarsDateTime(QDateTime::currentDateTime().toLocalTime())); SkyPoint sp = so->recomputeCoords(ut, data->geo()); //check altitude of object at this time. sp.EquatorialToHorizontal(data->lst(), data->geo()->lat()); double rounded_altitude = (int)(sp.alt().Degrees()/5.0)*5.0; m_Position = xi18n("Now visible: About %1 degrees above the %2 horizon", rounded_altitude, KSUtils::toDirectionString( sp.az() ) ); }
void RenameTabAction::slotTriggered() { if (!qobject_cast<QTabWidget*>(m_receiver)) return; QWidget *w = m_receiver->currentWidget(); bool ok; QString name = QInputDialog::getText(w->topLevelWidget(), xi18nc("@window:title", "New Page Title"), xi18n("Enter a new title for the current page:"), QLineEdit::Normal, m_receiver->tabText(m_receiver->indexOf(w)), &ok); if (ok) m_receiver->setTabText(m_receiver->indexOf(w), name); }
void KexiReportView::slotExportAsWebPage() { KoReportRendererContext cxt; KoReportRendererBase *renderer; const QString dialogTitle = xi18n("Export Report as Web Page"); cxt.destinationUrl = getExportUrl(QLatin1String("text/html"), dialogTitle, "kfiledialog:///LastVisitedHTMLExportPath/", "html"); if (!cxt.destinationUrl.isValid()) { return; } const int answer = KMessageBox::questionYesNo( this, xi18n("Would you like to export using a Cascading Style Sheet (CSS), " "which will give an output closer to the original, " "or export using a HTML Table, which outputs a much simpler format?"), dialogTitle, KGuiItem(xi18nc("@action:button", "Use CSS")), KGuiItem(xi18nc("@action:button", "Use Table"))); if (answer == KMessageBox::Yes) { renderer = m_factory.createInstance("htmlcss"); } else { renderer = m_factory.createInstance("htmltable"); } if (!renderer->render(cxt, m_reportDocument)) { KMessageBox::error(this, xi18n("Exporting the report as web page to %1 failed.", cxt.destinationUrl.toDisplayString()), xi18n("Export Failed")); } else { openExportedDocument(cxt.destinationUrl); } }
KexiCSVDelimiterWidget::KexiCSVDelimiterWidget(bool lineEditOnBottom, QWidget * parent) : QWidget(parent) , d(new Private()) { QBoxLayout *lyr = new QBoxLayout(lineEditOnBottom ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); setLayout(lyr); KexiUtils::setMargins(lyr, 0); lyr->setSpacing(KexiUtils::spacingHint()); d->combo = new KComboBox(this); d->combo->setObjectName("KexiCSVDelimiterComboBox"); d->combo->addItem(xi18n("Comma \",\"")); //<-- KEXICSV_DEFAULT_FILE_DELIMITER d->combo->addItem(xi18n("Semicolon \";\"")); d->combo->addItem(xi18n("Tabulator")); d->combo->addItem(xi18n("Space \" \"")); d->combo->addItem(xi18n("Other")); lyr->addWidget(d->combo); setFocusProxy(d->combo); d->delimiterEdit = new QLineEdit(this); d->delimiterEdit->setObjectName("d->delimiterEdit"); d->delimiterEdit->setMaximumSize(QSize(30, 32767)); d->delimiterEdit->setMaxLength(1); d->delimiterEdit->setVisible(false); lyr->addWidget(d->delimiterEdit); if (!lineEditOnBottom) lyr->addStretch(2); slotDelimiterChangedInternal(KEXICSV_DEFAULT_FILE_DELIMITER_INDEX); //this will init d->delimiter connect(d->combo, SIGNAL(activated(int)), this, SLOT(slotDelimiterChanged(int))); connect(d->delimiterEdit, SIGNAL(returnPressed()), this, SLOT(slotDelimiterLineEditReturnPressed())); connect(d->delimiterEdit, SIGNAL(textChanged(QString)), this, SLOT(slotDelimiterLineEditTextChanged(QString))); slotDelimiterChangedInternal(KEXICSV_DEFAULT_FILE_DELIMITER_INDEX); //this will init d->delimiter connect(d->combo, SIGNAL(activated(int)), this, SLOT(slotDelimiterChanged(int))); }
//! Helper, used in Part::openInstance() tristate askForOpeningInTextMode(KexiWindow *window, KexiPart::Item *item, Kexi::ViewModes supportedViewModes, Kexi::ViewMode viewMode) { if (viewMode != Kexi::TextViewMode && supportedViewModes & Kexi::TextViewMode && window->data()->proposeOpeningInTextViewModeBecauseOfProblems) { //ask KexiUtils::WaitCursorRemover remover; //! @todo use message handler for this to enable non-gui apps QString singleStatusString(window->singleStatusString()); if (!singleStatusString.isEmpty()) singleStatusString.prepend(QString("\n\n") + xi18n("Details:") + " "); if (KMessageBox::No == KMessageBox::questionYesNo(0, ((viewMode == Kexi::DesignViewMode) ? xi18n("Object \"%1\" could not be opened in Design View.", item->name()) : xi18n("Object could not be opened in Data View.")) + "\n" + xi18n("Do you want to open it in Text View?") + singleStatusString, 0, KStandardGuiItem::open(), KStandardGuiItem::cancel())) { return false; } return true; } return cancelled; }
void KexiReportView::openExportedDocument(const QUrl &destination) { const int answer = KMessageBox::questionYesNo( this, xi18n("Do you want to open exported document?"), QString(), KStandardGuiItem::open(), KStandardGuiItem::close()); if (answer == KMessageBox::Yes) { (void)new KRun(destination, this->topLevelWidget()); } }
void RenameDialog::setFilename(const QString& filename) { d->mFilename->setText(filename); d->mFilenameLabel->setText(xi18n("Rename <filename>%1</filename> to:", filename)); const QMimeDatabase db; const QString extension = db.suffixForFileName(filename); int selectionLength = filename.length(); if (extension.length() > 0) { // The filename contains an extension. Assure that only the filename // gets selected. selectionLength -= extension.length() + 1; } d->mFilename->setSelection(0, selectionLength); }
bool setupSchemaObject(KDbObject *object, KexiPart::Item *item, KexiView::StoreNewDataOptions options) const { object->setName(item->name()); object->setCaption(item->caption()); object->setDescription(item->description()); KexiProject *project = KexiMainWindowIface::global()->project(); KexiPart::Item* existingItem = project->item(part->info(), object->name()); if (existingItem && !(options & KexiView::OverwriteExistingData)) { KMessageBox::information(win, xi18n("Could not create new object.") + win->part()->i18nMessage("Object <resource>%1</resource> already exists.", win) .subs(object->name()).toString()); return false; } return true; }
void ContinueExtractionQuery::execute() { qCDebug(ARK) << "Executing ContinueExtraction prompt"; QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); QMessageBox box(QMessageBox::Warning, i18n("Error during extraction"), xi18n("Extraction of the entry:<nl/>" " <filename>%1</filename><nl/>" "failed with the error message:<nl/> %2<nl/><nl/>" "Do you want to continue extraction?<nl/>", m_data.value(QStringLiteral("archiveEntry")).toString(), m_data.value(QStringLiteral("error")).toString()), QMessageBox::Yes|QMessageBox::Cancel); m_chkDontAskAgain = new QCheckBox(i18n("Don't ask again.")); box.setCheckBox(m_chkDontAskAgain); setResponse(box.exec()); QApplication::restoreOverrideCursor(); }
tristate KexiQueryView::executeQuery(KDbQuerySchema *query) { if (!query) return false; KexiUtils::WaitCursor wait; KDbCursor *oldCursor = d->cursor; qDebug() << query->parameters(); bool ok; KDbConnection * conn = KexiMainWindowIface::global()->project()->dbConnection(); { KexiUtils::WaitCursorRemover remover; d->currentParams = KexiQueryParameters::getParameters(this, *conn->driver(), query, &ok); } if (!ok) {//input cancelled return cancelled; } d->cursor = conn->executeQuery(query, d->currentParams); if (!d->cursor) { window()->setStatus( conn, xi18n("Query executing failed.")); //! @todo also provide server result and sql statement return false; } setData(d->cursor); //! @todo remove close() when dynamic cursors arrive if (!d->cursor->close()) { return false; } if (oldCursor) oldCursor->connection()->deleteCursor(oldCursor); //! @todo maybe allow writing and inserting for single-table relations? tableView()->setReadOnly(true); //! @todo maybe allow writing and inserting for single-table relations? //set data model itself read-only too tableView()->data()->setReadOnly(true); tableView()->setInsertingEnabled(false); return true; }
KexiSourceSelector::KexiSourceSelector(KexiProject* project, QWidget* parent) : QWidget(parent) , d(new Private) { d->conn = project->dbConnection(); d->kexiDBData = 0; #ifndef KEXI_MOBILE #ifdef HAVE_KEXIMMIGRATE d->kexiMigrateData = 0; #endif #endif d->layout = new QVBoxLayout(this); d->sourceType = new QComboBox(this); d->internalSource = new KexiDataSourceComboBox(this); d->internalSource->setProject(project); d->externalSource = new QLineEdit(this); d->setData = new QPushButton(xi18n("Set Data")); connect(d->setData, SIGNAL(clicked()), this, SLOT(setDataClicked())); d->sourceType->addItem(xi18n("Internal"), QVariant("internal")); d->sourceType->addItem(xi18n("External"), QVariant("external")); #ifndef NO_EXTERNAL_SOURCES //!@TODO enable when adding external data d->layout->addWidget(new QLabel(xi18n("Source Type:"), this)); d->layout->addWidget(d->sourceType); d->layout->addSpacing(10); #else d->sourceType->setVisible(false); d->externalSource->setVisible(false); #endif d->layout->addWidget(new QLabel(xi18n("Internal Source:"), this)); d->layout->addWidget(d->internalSource); d->layout->addSpacing(10); #ifndef NO_EXTERNAL_SOURCES d->layout->addWidget(new QLabel(xi18n("External Source:"), this)); d->layout->addWidget(d->externalSource); #endif d->layout->addSpacing(20); d->layout->addWidget(d->setData); d->layout->addStretch(); setLayout(d->layout); }
QUrl KexiReportView::getExportUrl(const QString &mimetype, const QString &caption, const QString &lastExportPath, const QString &extension) { QUrl result; QString defaultSavePath; if (lastExportPath.startsWith("kfiledialog:///")) { defaultSavePath = lastExportPath + window()->partItem()->captionOrName() + "." + extension; } // loop until an url has been chosen or the file selection has been cancelled const QMimeDatabase db; const QString filterString = db.mimeTypeForName(mimetype).filterString(); while (true) { QUrl result = QFileDialog::getSaveFileUrl(this, caption, QUrl::fromLocalFile(defaultSavePath), filterString); // not cancelled? if (result.isValid()) { if (KIO::NetAccess::exists(result, KIO::NetAccess::DestinationSide, this)) { const KMessageBox::ButtonCode answer = KMessageBox::warningContinueCancel(this, xi18n("The file %1 exists.\nDo you want to overwrite it?", result.path()), caption, KGuiItem(xi18nc("@action:button Overwrite File", "Overwrite"))); // if overwriting not wanted, let select another url if (answer == KMessageBox::Cancel) { continue; } } } // decision has been made, leave loop break; } return result; }
KSPluto::KSPluto(const QString &fn, double pSize ) : KSAsteroid( 0, xi18n("Pluto"), fn, J2000, 39.48168677, 0.24880766, dms(17.14175), dms(113.76329), dms(110.30347), dms(14.86205), 1.0, 0.0 ) { //Initialize the base orbital element values for J2000: a0 = 39.48168677; //semi-major axis (AU) e0 = 0.24880766; //eccentricity i0.setD( 17.14175 ); //inclination (degrees) w0.setD( 113.76329 ); //argument of perihelion (degrees) N0.setD( 110.30347 ); //long. of ascending node (degrees) M0.setD( 14.86205 ); //mean anomaly (degrees) //rate-of-change values for the orbital elements a1 = -0.00076912; // da/dt (AU/cnetury) e1 = 0.00006465; // de/dt (1/century) i1 = 11.07/3600.; // di/dt (degrees/century) w1 = -94.92/3600.; // dw/dt (degrees/century) N1 = -37.33/3600.; // dN/dt (degrees/century) M1 = 522880.15/3600.; // dM/dt (degrees/century) setPhysicalSize( pSize ); }
//! Creates action for toggling to view mode @a mode. @a slot should have signature //! matching switchedTo(Kexi::ViewMode mode) signal. KexiToggleViewModeAction(Kexi::ViewMode mode, QObject* parent) : QAction( QIcon::fromTheme(Kexi::iconNameForViewMode(mode)), Kexi::nameForViewMode(mode, true/*withAmpersand*/), parent) { setCheckable(true); if (mode == Kexi::DataViewMode) { setObjectName("view_data_mode"); setToolTip(xi18n("Switch to data view")); setWhatsThis(xi18n("Switches to data view.")); } else if (mode == Kexi::DesignViewMode) { setObjectName("view_design_mode"); setToolTip(xi18n("Switch to design view")); setWhatsThis(xi18n("Switches to design view.")); } else if (mode == Kexi::TextViewMode) { setObjectName("view_text_mode"); setToolTip(xi18n("Switch to text view")); setWhatsThis(xi18n("Switches to text view.")); } else { qWarning() << "KexiToggleViewModeAction: invalid mode " << mode; } }
void ArkViewer::view(const QString& fileName) { QMimeDatabase db; QMimeType mimeType = db.mimeTypeForFile(fileName); qCDebug(ARK) << "viewing" << fileName << "with mime type:" << mimeType.name(); KService::Ptr viewer = ArkViewer::getViewer(mimeType.name()); const bool needsExternalViewer = (viewer && !viewer->hasServiceType(QStringLiteral("KParts/ReadOnlyPart"))); if (needsExternalViewer) { // We have already resolved the MIME type and the service above. // So there is no point in using KRun::runUrl() which would need // to do the same again. qCDebug(ARK) << "Using external viewer"; const QList<QUrl> fileUrlList = {QUrl::fromLocalFile(fileName)}; // The last argument (tempFiles) set to true means that the temporary // file will be removed when the viewer application exits. KRun::runService(*viewer, fileUrlList, nullptr, true); return; } qCDebug(ARK) << "Attempting to use internal viewer"; bool viewInInternalViewer = true; if (!viewer) { // No internal viewer available for the file. Ask the user if it // should be previewed as text/plain. qCDebug(ARK) << "Internal viewer not available"; int response; if (!mimeType.isDefault()) { // File has a defined MIME type, and not the default // application/octet-stream. So it could be viewable as // plain text, ask the user. response = KMessageBox::warningContinueCancel(nullptr, xi18n("The internal viewer cannot preview this type of file<nl/>(%1).<nl/><nl/>Do you want to try to view it as plain text?", mimeType.name()), i18nc("@title:window", "Cannot Preview File"), KGuiItem(i18nc("@action:button", "Preview as Text"), QIcon::fromTheme(QStringLiteral("text-plain"))), KStandardGuiItem::cancel(), QStringLiteral("PreviewAsText_%1").arg(mimeType.name())); } else { // No defined MIME type, or the default application/octet-stream. // There is still a possibility that it could be viewable as plain // text, so ask the user. Not the same as the message/question // above, because the wording and default are different. response = KMessageBox::warningContinueCancel(nullptr, xi18n("The internal viewer cannot preview this unknown type of file.<nl/><nl/>Do you want to try to view it as plain text?"), i18nc("@title:window", "Cannot Preview File"), KGuiItem(i18nc("@action:button", "Preview as Text"), QIcon::fromTheme(QStringLiteral("text-plain"))), KStandardGuiItem::cancel(), QString(), KMessageBox::Dangerous); } if (response == KMessageBox::Cancel) { viewInInternalViewer = false; } else { // set for viewer later mimeType = db.mimeTypeForName(QStringLiteral("text/plain")); } } if (viewInInternalViewer) { qCDebug(ARK) << "Opening internal viewer"; ArkViewer *internalViewer = new ArkViewer(); internalViewer->show(); if (internalViewer->viewInInternalViewer(fileName, mimeType)) { // The internal viewer is showing the file, and will // remove the temporary file in its destructor. So there // is no more to do here. return; } else { KMessageBox::sorry(nullptr, i18n("The internal viewer cannot preview this file.")); delete internalViewer; } } // Only get here if there is no internal viewer available or could be // used for the file, and no external viewer was opened. Nothing can be // done with the temporary file, so remove it now. qCDebug(ARK) << "Removing temporary file:" << fileName; QFile::remove(fileName); }
void AddToArchive::slotStartJob() { Kerfuffle::CompressionOptions options; if (m_inputs.isEmpty()) { KMessageBox::error(NULL, i18n("No input files were given.")); emitResult(); return; } Kerfuffle::Archive *archive; if (!m_filename.isEmpty()) { archive = Kerfuffle::Archive::create(m_filename, m_mimeType, this); qCDebug(ARK) << "Set filename to " << m_filename; } else { if (m_autoFilenameSuffix.isEmpty()) { KMessageBox::error(Q_NULLPTR, xi18n("You need to either supply a filename for the archive or a suffix (such as rar, tar.gz) with the <command>--autofilename</command> argument.")); emitResult(); return; } if (m_firstPath.isEmpty()) { qCWarning(ARK) << "Weird, this should not happen. no firstpath defined. aborting"; emitResult(); return; } const QString base = detectBaseName(m_inputs); QString finalName = base + QLatin1Char( '.' ) + m_autoFilenameSuffix; //if file already exists, append a number to the base until it doesn't //exist int appendNumber = 0; while (QFileInfo::exists(finalName)) { ++appendNumber; finalName = base + QLatin1Char( '_' ) + QString::number(appendNumber) + QLatin1Char( '.' ) + m_autoFilenameSuffix; } qCDebug(ARK) << "Autoset filename to "<< finalName; archive = Kerfuffle::Archive::create(finalName, m_mimeType, this); } Q_ASSERT(archive); if (!archive->isValid()) { if (archive->error() == NoPlugin) { KMessageBox::error(Q_NULLPTR, i18n("Failed to create the new archive. No suitable plugin found.")); emitResult(); return; } if (archive->error() == FailedPlugin) { KMessageBox::error(Q_NULLPTR, i18n("Failed to create the new archive. Could not load a suitable plugin.")); emitResult(); return; } } else if (archive->isReadOnly()) { KMessageBox::error(Q_NULLPTR, i18n("It is not possible to create archives of this type.")); emitResult(); return; } if (!m_password.isEmpty()) { archive->encrypt(m_password, m_enableHeaderEncryption); } if (m_changeToFirstPath) { if (m_firstPath.isEmpty()) { qCWarning(ARK) << "Weird, this should not happen. no firstpath defined. aborting"; emitResult(); return; } const QDir stripDir(m_firstPath); for (int i = 0; i < m_inputs.size(); ++i) { m_inputs[i] = stripDir.absoluteFilePath(m_inputs.at(i)); } options[QStringLiteral( "GlobalWorkDir" )] = stripDir.path(); qCDebug(ARK) << "Setting GlobalWorkDir to " << stripDir.path(); } Kerfuffle::AddJob *job = archive->addFiles(m_inputs, options); KIO::getJobTracker()->registerJob(job); connect(job, &Kerfuffle::AddJob::result, this, &AddToArchive::slotFinished); job->start(); }
KexiRelationsView::KexiRelationsView(QWidget *parent) : KexiView(parent) , d(new Private) { QWidget *mainWidget = new QWidget(this); QGridLayout *g = new QGridLayout(mainWidget); g->setContentsMargins(0, 0, 0, 0); g->setSpacing(KexiUtils::spacingHint()); QWidget *horWidget = new QWidget(mainWidget); QHBoxLayout *hlyr = new QHBoxLayout(horWidget); hlyr->setContentsMargins(0, 0, 0, 0); g->addWidget(horWidget, 0, 0); d->tableCombo = new KComboBox(horWidget); d->tableCombo->setObjectName("tables_combo"); d->tableCombo->setMinimumWidth(QFontMetrics(font()).width("w")*20); d->tableCombo->setInsertPolicy(QComboBox::NoInsert); d->tableCombo->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred)); QLabel *lbl = new QLabel(xi18n("Table:"), horWidget); lbl->setBuddy(d->tableCombo); lbl->setIndent(3); hlyr->addWidget(lbl); hlyr->addWidget(d->tableCombo); d->btnAdd = new QPushButton(xi18nc("Insert table/query into relations view", "&Insert"), horWidget); hlyr->addWidget(d->btnAdd); hlyr->addStretch(1); connect(d->btnAdd, SIGNAL(clicked()), this, SLOT(slotAddTable())); d->scrollArea = new KexiRelationsScrollArea(mainWidget); d->scrollArea->setObjectName("scroll_area"); setViewWidget(mainWidget, false/* no focus proxy */); setFocusProxy(d->scrollArea); g->addWidget(d->scrollArea, 1, 0); //actions d->tableQueryPopup = new QMenu(this); d->tableQueryPopup->setObjectName("tableQueryPopup"); connect(d->tableQueryPopup, SIGNAL(aboutToShow()), this, SLOT(aboutToShowPopupMenu())); d->hideTableAction = plugSharedAction("edit_delete", xi18n("&Hide Table"), d->tableQueryPopup); if (d->hideTableAction) d->hideTableAction->setIcon(QIcon()); d->connectionPopup = new QMenu(this); d->connectionPopup->setObjectName("connectionPopup"); connect(d->connectionPopup, SIGNAL(aboutToShow()), this, SLOT(aboutToShowPopupMenu())); //! @todo areaPopup d->areaPopup = new QMenu(this); d->areaPopup->setObjectName("areaPopup"); d->appendSelectedFieldAction = new QAction(koIcon("add_field"), xi18n("&Append Field"), this); d->appendSelectedFieldAction->setObjectName("relationsview_appendField"); connect(d->appendSelectedFieldAction, SIGNAL(triggered()), this, SLOT(appendSelectedFields())); d->appendSelectedFieldsAction = new QAction(koIcon("add_field"), xi18n("&Append Fields"), this); d->appendSelectedFieldsAction->setObjectName("relationsview_appendFields"); connect(d->appendSelectedFieldsAction, SIGNAL(triggered()), this, SLOT(appendSelectedFields())); d->openSelectedTableAction = new QAction(koIcon("document-open"), xi18n("&Open Table"), this); d->openSelectedTableAction->setObjectName("relationsview_openTable"); connect(d->openSelectedTableAction, SIGNAL(triggered()), this, SLOT(openSelectedTable())); d->designSelectedTableAction = new QAction(koIcon("document-properties"), xi18n("&Design Table"), this); connect(d->designSelectedTableAction, SIGNAL(triggered()), this, SLOT(designSelectedTable())); d->designSelectedTableAction->setObjectName("relationsview_designTable"); plugSharedAction("edit_delete", this, SLOT(removeSelectedObject())); connect(d->scrollArea, SIGNAL(tableViewGotFocus()), this, SLOT(tableViewGotFocus())); connect(d->scrollArea, SIGNAL(connectionViewGotFocus()), this, SLOT(connectionViewGotFocus())); connect(d->scrollArea, SIGNAL(emptyAreaGotFocus()), this, SLOT(emptyAreaGotFocus())); connect(d->scrollArea, SIGNAL(tableContextMenuRequest(QPoint)), this, SLOT(tableContextMenuRequest(QPoint))); connect(d->scrollArea, SIGNAL(connectionContextMenuRequest(QPoint)), this, SLOT(connectionContextMenuRequest(QPoint))); connect(d->scrollArea, SIGNAL(tableHidden(KDbTableSchema*)), this, SLOT(slotTableHidden(KDbTableSchema*))); connect(d->scrollArea, SIGNAL(tablePositionChanged(KexiRelationsTableContainer*)), this, SIGNAL(tablePositionChanged(KexiRelationsTableContainer*))); connect(d->scrollArea, SIGNAL(aboutConnectionRemove(KexiRelationsConnection*)), this, SIGNAL(aboutConnectionRemove(KexiRelationsConnection*))); //! @todo #if 0 if (!embedd) { /*todo setContextHelp(xi18n("Relations"), xi18n("To create a relationship simply drag the source field onto the target field. " "An arrowhead is used to show which table is the parent (master) and which table is the child (slave) in the relationship."));*/ } #endif #ifdef TESTING_KexiRelationWidget for (int i = 0;i < (int)d->db->tableNames().count();i++) QTimer::singleShot(100, this, SLOT(slotAddTable())); #endif invalidateActions(); }