Ejemplo n.º 1
0
bool Bundle::installPackage(const QString &archivePath, const QString &packageRoot)
{
    //kDebug() << "??????????????" << archivePath << packageRoot;
    QFile f(archivePath);
    f.open(QIODevice::ReadOnly);
    m_data = f.readAll();
    f.close();
    open();

    if (m_isValid) {
        m_tempDir->setAutoRemove(false);
        QString pluginName = "dashboard_" + m_bundleId;
        //kDebug() << "valid, so going to move it in to" << pluginName;
        KIO::CopyJob* job = KIO::move(m_tempDir->name(), QString(packageRoot + pluginName), KIO::HideProgressInfo);
        m_isValid = job->exec();

        if (m_isValid) {
            //kDebug() << "still so good ... registering";
            Plasma::PackageMetadata data;
            data.setName(m_name);
            data.setDescription(m_description);
            data.setPluginName(pluginName);
            data.setImplementationApi("dashboard");
            Plasma::Package::registerPackage(data, m_iconLocation);
        }
    }

    if (!m_isValid) {
        // make sure we clean up after ourselves afterwards on failure
        m_tempDir->setAutoRemove(true);
    }

    return m_isValid;
}
Ejemplo n.º 2
0
void TreeLog::onSaveLog()
{
	const QUrl url = QFileDialog::getSaveFileUrl();

	if (!url.isEmpty())
	{
		QTemporaryFile tempFile;

		if (!tempFile.open())
		{
			KMessageBox::error(this, xi18nc("@info", "Could not create temporary output file to save <filename>%1</filename>.", url.fileName()), i18nc("@title:window", "Error Saving Log File"));
			return;
		}

		QTextStream stream(&tempFile);

		for (qint32 idx = 0; idx < treeLog().topLevelItemCount(); idx++)
		{
			QTreeWidgetItem* item = treeLog().topLevelItem(idx);
			stream << item->text(1) << ": " << item->text(2) << "\n";
		}

		tempFile.close();

		KIO::CopyJob* job = KIO::move(QUrl::fromLocalFile(tempFile.fileName()), url, KIO::HideProgressInfo);
		job->exec();
		if ( job->error() )
			job->ui()->showErrorMessage();
	}
}
Ejemplo n.º 3
0
void KPrHtmlExport::copyFromTmpToDest()
{
    KIO::CopyJob *job = KIO::moveAs(m_tmpDirPath, m_parameters.destination);
    job->setWriteIntoExistingDirectories(true);
    job->setUiDelegate(new KPrHtmlExportUiDelegate);
    connect(job, SIGNAL(result(KJob*)), this, SLOT(moveResult(KJob*)));
    job->exec();
}
Ejemplo n.º 4
0
    void parseArgs(KCmdLineArgs* args)
    {
        if (args->count() > 1) {
            // Createa a temp dir containing links to url args
            mMultipleUrlsDir.reset(new KTempDir);
            mUrl = KUrl::fromPath(mMultipleUrlsDir->name());
            KUrl::List list;
            for (int pos = 0; pos < args->count(); ++pos) {
                list << args->url(pos);
            }
            KIO::CopyJob* job = KIO::link(list, mUrl);
            job->exec();
        } else {
            mUrl = args->url(0);
        }

        if (mUrl.isValid() && (args->isSet("f") || args->isSet("s"))) {
            mFullScreen = true;
            if (args->isSet("s")) {
                mSlideShow = true;
            }
        }
    }
Ejemplo n.º 5
0
void KIOExec::slotRunApp()
{
    if ( fileList.isEmpty() ) {
        qDebug() << "No files downloaded -> exiting";
        mExited = true;
        QApplication::exit(1);
        return;
    }

    KService service(QStringLiteral("dummy"), command, QString());

    QList<QUrl> list;
    // Store modification times
    QList<FileInfo>::Iterator it = fileList.begin();
    for ( ; it != fileList.end() ; ++it )
    {
        QFileInfo info(QFile::encodeName(it->path));
        it->time = info.lastModified();
        QUrl url = QUrl::fromLocalFile(it->path);
        list << url;
    }

    KIO::DesktopExecParser execParser(service, list);
    QStringList params = execParser.resultingArguments();

    qDebug() << "EXEC " << params.join(QStringLiteral(" "));

#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
    // propagate the startup identification to the started process
    KStartupInfoId id;
    QByteArray startupId;
#if HAVE_X11
    if (QX11Info::isPlatformX11()) {
        startupId = QX11Info::nextStartupId();
    }
#endif
    id.initId(startupId);
    id.setupStartupEnv();
#endif

    QString exe( params.takeFirst() );
    const int exit_code = QProcess::execute( exe, params );

#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
    KStartupInfo::resetStartupEnv();
#endif

    qDebug() << "EXEC done";

    // Test whether one of the files changed
    for(it = fileList.begin(); it != fileList.end(); ++it )
    {
        QString src = it->path;
        const QUrl dest = it->url;
        QFileInfo info(src);
        if ( info.exists() && (it->time != info.lastModified()) )
        {
            if ( mTempFiles )
            {
                if ( KMessageBox::questionYesNo( 0L,
                                                 i18n( "The supposedly temporary file\n%1\nhas been modified.\nDo you still want to delete it?", dest.toDisplayString(QUrl::PreferLocalFile)),
                                                 i18n( "File Changed" ), KStandardGuiItem::del(), KGuiItem(i18n("Do Not Delete")) ) != KMessageBox::Yes )
                    continue; // don't delete the temp file
            }
            else if ( ! dest.isLocalFile() )  // no upload when it's already a local file
            {
                if ( KMessageBox::questionYesNo( 0L,
                                                 i18n( "The file\n%1\nhas been modified.\nDo you want to upload the changes?" , dest.toDisplayString()),
                                                 i18n( "File Changed" ), KGuiItem(i18n("Upload")), KGuiItem(i18n("Do Not Upload")) ) == KMessageBox::Yes )
                {
                    qDebug() << "src='" << src << "'  dest='" << dest << "'";
                    // Do it the synchronous way.
                    KIO::CopyJob* job = KIO::copy(QUrl::fromLocalFile(src), dest);
                    if ( !job->exec() )
                    {
                        KMessageBox::error( 0L, job->errorText() );
                        continue; // don't delete the temp file
                    }
                }
            }
        }

        if ((!dest.isLocalFile() || mTempFiles) && exit_code == 0) {
            // Wait for a reasonable time so that even if the application forks on startup (like OOo or amarok)
            // it will have time to start up and read the file before it gets deleted. #130709.
            qDebug() << "sleeping...";
            QThread::currentThread()->sleep(180); // 3 mn
            qDebug() << "about to delete " << src;
            QFile( QFile::encodeName(src) ).remove();
        }
    }

    mExited = true;
    QApplication::exit(exit_code);
}