Beispiel #1
0
/// Helper to sanely show an error message for a job
void showJobError(KJob *job)
{
    assert(job);
    // we can be called from the KJob::kill, where we are no longer a KIO::Job
    // so better safe than sorry
    KIO::Job *kiojob = qobject_cast<KIO::Job *>(job);
    if (kiojob && kiojob->uiDelegate()) {
        kiojob->uiDelegate()->showErrorMessage();
    } else {
        qCWarning(AKONADIMIME_LOG) << "There is no GUI delegate set for a kjob, and it failed with error:" << job->errorString();
    }
}
void SatellitesComponent::updateTLEs()
{
    int i = 0;
    
    QProgressDialog progressDlg( i18n( "Update TLEs..." ), i18n( "Abort" ), 0, m_groups.count() );
    progressDlg.setWindowModality( Qt::WindowModal );
    progressDlg.setValue( 0 );
        
    foreach ( SatelliteGroup *group, m_groups ) {
        if ( progressDlg.wasCanceled() )
            return;

        if( group->tleUrl().isEmpty() )
            continue;
        
        progressDlg.setLabelText( i18n( "Update %1 satellites", group->name() ) );
        KIO::Job* getJob = KIO::file_copy(group->tleUrl(), group->tleFilename(), -1, KIO::Overwrite | KIO::HideProgressInfo );
        if( getJob->exec() )
        {
            group->readTLE();
            group->updateSatellitesPos();
            progressDlg.setValue( ++i );
        } else
        {
            getJob->uiDelegate()->showErrorMessage();
        }   
    }
}
Beispiel #3
0
void MainWindow::fileSaveAs()
{
    WebTab *w = currentTab();
    KUrl srcUrl = w->url();
    
    // First, try with suggested file name...
    QString name = w->page()->suggestedFileName();

    // Second, with KUrl fileName...
    if (name.isEmpty())
    {
        name = srcUrl.fileName();
    }
    
    // Last chance...
    if(name.isEmpty())
    {
        name = srcUrl.host() + QString(".html");
    }
    
    const QString destUrl = KFileDialog::getSaveFileName(name, QString(), this);
    if (destUrl.isEmpty()) 
        return;
    
    KIO::Job *job = KIO::file_copy(srcUrl, KUrl(destUrl), -1, KIO::Overwrite);
    job->addMetaData("MaxCacheSize", "0");  // Don't store in http cache.
    job->addMetaData("cache", "cache");     // Use entry from cache if available.
    job->uiDelegate()->setAutoErrorHandlingEnabled(true);
}
Beispiel #4
0
void KrTrashHandler::emptyTrash()
{
    QByteArray packedArgs;
    QDataStream stream(&packedArgs, QIODevice::WriteOnly);
    stream << (int)1;
    KIO::Job *job = KIO::special(QUrl(QStringLiteral("trash:/")), packedArgs);
    KNotification::event("Trash: emptied", QString() , QPixmap() , 0l, KNotification::DefaultEvent);
    KIO::JobUiDelegate *ui = static_cast<KIO::JobUiDelegate*>(job->uiDelegate());
    ui->setWindow(krMainWindow);
    QObject::connect(job, SIGNAL(result(KJob *)), ACTIVE_PANEL->func, SLOT(refresh()));
}
Beispiel #5
0
bool ftp_vfs::populateVfsList(const QUrl &origin, bool showHidden)
{
    QString errorMsg;
    if (!origin.isValid())
        errorMsg = i18n("Malformed URL:\n%1", origin.url());
    if (!KProtocolManager::supportsListing(origin)) {
        if (origin.scheme() == "ftp" && KProtocolManager::supportsReading(origin))
            errorMsg = i18n("Krusader does not support FTP access via HTTP.\nIf it is not the case, please check and change the proxy settings in the System Settings.");
        else
            errorMsg = i18n("Protocol not supported by Krusader:\n%1", origin.url());
    }

    if (!errorMsg.isEmpty()) {
        printf("error\n");
        if (!quietMode)
            emit error(errorMsg);
        return false;
    }

    busy = true;

    vfs_origin = origin.adjusted(QUrl::StripTrailingSlash);

    //QTimer::singleShot( 0,this,SLOT(startLister()) );
    listError = false;
    // Open the directory marked by origin
    KIO::Job *job = KIO::listDir(vfs_origin, KIO::HideProgressInfo, showHidden);
    connect(job, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)),
            this, SLOT(slotAddFiles(KIO::Job*, const KIO::UDSEntryList&)));
    connect(job, SIGNAL(redirection(KIO::Job*, const QUrl&)),
            this, SLOT(slotRedirection(KIO::Job*, const QUrl&)));
    connect(job, SIGNAL(permanentRedirection(KIO::Job*, const QUrl&, const QUrl&)),
            this, SLOT(slotPermanentRedirection(KIO::Job*, const QUrl&, const QUrl&)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotListResult(KJob*)));

    if(!parentWindow.isNull()) {
        KIO::JobUiDelegate *ui = static_cast<KIO::JobUiDelegate*>(job->uiDelegate());
        ui->setWindow(parentWindow);
    }

    if (!quietMode) {
        emit startJob(job);
    }

    while (busy && vfs_processEvents());

    if (listError) return false;

    return true;
}
Beispiel #6
0
void
RadialMap::Widget::mousePressEvent(QMouseEvent *e)
{
    //m_tip is hidden already by event filter
    //m_focus is set correctly (I've been strict, I assure you it is correct!)

    if (m_focus && !m_focus->isFake()) {
        const QUrl url   = Widget::url(m_focus->file());
        const bool isDir = m_focus->file()->isDir();

        if (e->button() == Qt::RightButton) {
            QMenu popup;
            popup.setTitle(m_focus->file()->fullPath(m_tree));

            QAction * actKonq = 0, * actKonsole = 0, *actViewMag = 0, * actFileOpen = 0, * actEditDel = 0;

            if (isDir) {
                actKonq = popup.addAction(QIcon::fromTheme("system-file-manager"), i18n("Open File Manager Here"));
                if (url.scheme() == "file")
                    actKonsole = popup.addAction(QIcon::fromTheme("utilities-terminal"), i18n("Open Terminal Here"));

                if (m_focus->file() != m_tree) {
                    popup.addSeparator();
                    actViewMag = popup.addAction(QIcon::fromTheme("zoom-original"), i18n("&Center Map Here"));
                }
            } else
                actFileOpen = popup.addAction(QIcon::fromTheme("document-open"), i18n("&Open"));

            popup.addSeparator();
            actEditDel = popup.addAction(QIcon::fromTheme("edit-delete"), i18n("&Delete"));

            QAction * result = popup.exec(e->globalPos());
            if (result == 0)
                result = (QAction *) - 1;  // sanity

            if (result == actKonq)
                //KRun::runCommand will show an error message if there was trouble
                KRun::runCommand(QString("kfmclient openURL '%1'").arg(url.url()), this);
            else if (result == actKonsole)
                KRun::runCommand(QString("konsole --workdir '%1'").arg(url.url()), this);
            else if (result == actViewMag || result == actFileOpen)
                goto sectionTwo;
            else if (result == actEditDel) {
                const QUrl url = Widget::url(m_focus->file());
                const QString message = (m_focus->file()->isDir()
                                         ? i18n("<qt>The folder at <i>'%1'</i> will be <b>recursively</b> and <b>permanently</b> deleted.</qt>", url.toDisplayString())
                                         : i18n("<qt><i>'%1'</i> will be <b>permanently</b> deleted.</qt>", url.toDisplayString()));
                const int userIntention = KMessageBox::warningContinueCancel(this, message, QString(), KGuiItem(i18n("&Delete"), "edit-delete"));

                if (userIntention == KMessageBox::Continue) {
                    KIO::Job *job = KIO::del(url);
                    KIO::JobUiDelegate *ui = static_cast<KIO::JobUiDelegate*>(job->uiDelegate());
                    ui->setWindow(this);
                    connect(job, SIGNAL(result(KJob*)), SLOT(deleteJobFinished(KJob*)));
                    QApplication::setOverrideCursor(Qt::BusyCursor);
                }
            } else
                //ensure m_focus is set for new mouse position
                sendFakeMouseEvent();

        } else {

        sectionTwo:

            const QRect rect(e->x() - 20, e->y() - 20, 40, 40);

            m_tip.hide(); //user expects this

            if (!isDir || e->button() == Qt::MidButton) {
#if 0 // TODO: PORTME
                KIconEffect::visualActivate(this, rect);
#endif
                new KRun(url, this, true);   //FIXME see above
            } else if (m_focus->file() != m_tree) { //is left mouse button
#if 0 // TODO: PORTME
                KIconEffect::visualActivate(this, rect);
#endif
                emit activated(url);   //activate first, this will cause UI to prepare itself
                if (m_focus)
                    createFromCache((Directory *)m_focus->file());
            }
        }
    }
}
Beispiel #7
0
static bool downloadResource(const KUrl& srcUrl, const KIO::MetaData& metaData = KIO::MetaData(),
                             QWidget * parent = 0, const QString & suggestedName = QString())
{
    KUrl destUrl;

    int result = KIO::R_OVERWRITE;
    const QString fileName((suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName));

    do
    {
        // follow bug:184202 fixes
        destUrl = KFileDialog::getSaveFileName(KUrl(KGlobalSettings::downloadPath().append(fileName)), QString(), parent);

        if (destUrl.isEmpty())
            return false;

        if (destUrl.isLocalFile())
        {
            QFileInfo finfo(destUrl.toLocalFile());
            if (finfo.exists())
            {
                QDateTime now = QDateTime::currentDateTime();
                QPointer<KIO::RenameDialog> dlg = new KIO::RenameDialog(parent,
                        i18n("Overwrite File?"),
                        srcUrl,
                        destUrl,
                        KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP),
                        -1,
                        finfo.size(),
                        now.toTime_t(),
                        finfo.created().toTime_t(),
                        now.toTime_t(),
                        finfo.lastModified().toTime_t()
                                                                       );
                result = dlg->exec();
                delete dlg;
            }
        }
    }
    while (result == KIO::R_CANCEL && destUrl.isValid());

    // Save download history
    DownloadItem *item = rApp->downloadManager()->addDownload(srcUrl.pathOrUrl(), destUrl.pathOrUrl());

    if (!KStandardDirs::findExe("kget").isNull() && ReKonfig::kgetDownload())
    {
        //KGet integration:
        if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget"))
        {
            KToolInvocation::kdeinitExecWait("kget");
        }
        QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main");
        if (!kget.isValid())
            return false;

        QDBusMessage transfer = kget.call(QL1S("addTransfer"), srcUrl.prettyUrl(), destUrl.prettyUrl(), true);
        if (transfer.arguments().isEmpty())
            return true;

        const QString transferPath = transfer.arguments().first().toString();
        item->setKGetTransferDbusPath(transferPath);
        return true;
    }

    KIO::Job *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::Overwrite);
    if (item)
    {
        QObject::connect(job, SIGNAL(percent(KJob *,unsigned long)), item, SLOT(updateProgress(KJob *,unsigned long)));
        QObject::connect(job, SIGNAL(finished(KJob *)), item, SLOT(onFinished(KJob*)));
    }

    if (!metaData.isEmpty())
        job->setMetaData(metaData);

    job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache.
    job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available.
    job->uiDelegate()->setAutoErrorHandlingEnabled(true);
    return true;
}