Example #1
0
void FileSelectDlg::updateSizeLabels()
{
	//calculate free disk space

	KURL sdir = KURL(m_downloadLocation -> url());
	while( sdir.isValid() && sdir.isLocalFile() && (!sdir.isEmpty())  && (! QDir(sdir.path()).exists()) ) 
	{
		sdir = sdir.upURL();
	}
	
	Uint64 bytes_free = 0;
	if (!FreeDiskSpace(sdir.path(),bytes_free))
	{
		FreeDiskSpace(tc->getDataDir(),bytes_free);
	}
	
	Uint64 bytes_to_download = 0;
	if (root)
		bytes_to_download = root->bytesToDownload();
	else
		bytes_to_download = tc->getStats().total_bytes;

	lblFree->setText(kt::BytesToString(bytes_free));
	lblRequired->setText(kt::BytesToString(bytes_to_download));

	if (bytes_to_download > bytes_free)
		lblStatus->setText("<font color=\"#ff0000\">" + kt::BytesToString(-1*(long long)(bytes_free - bytes_to_download)) + i18n(" short!"));
	else
		lblStatus->setText(kt::BytesToString(bytes_free - bytes_to_download));
}
void DolphinView::rename(const KURL& source, const QString& newName)
{
    bool ok = false;

    if (newName.isEmpty() || (source.fileName() == newName)) {
        return;
    }

    KURL dest(source.upURL());
    dest.addPath(newName);

    const bool destExists = KIO::NetAccess::exists(dest,
                                                   false,
                                                   Dolphin::mainWin().activeView());
    if (destExists) {
        // the destination already exists, hence ask the user
        // how to proceed...
        KIO::RenameDlg renameDialog(this,
                                    i18n("File Already Exists"),
                                    source.path(),
                                    dest.path(),
                                    KIO::M_OVERWRITE);
        switch (renameDialog.exec()) {
            case KIO::R_OVERWRITE:
                // the destination should be overwritten
                ok = KIO::NetAccess::file_move(source, dest, -1, true);
                break;

            case KIO::R_RENAME: {
                // a new name for the destination has been used
                KURL newDest(renameDialog.newDestURL());
                ok = KIO::NetAccess::file_move(source, newDest);
                break;
            }

            default:
                // the renaming operation has been canceled
                reload();
                return;
        }
    }
    else {
        // no destination exists, hence just move the file to
        // do the renaming
        ok = KIO::NetAccess::file_move(source, dest);
    }

    if (ok) {
        m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.").arg(source.fileName(), dest.fileName()),
                                DolphinStatusBar::OperationCompleted);

        DolphinCommand command(DolphinCommand::Rename, source, dest);
        UndoManager::instance().addCommand(command);
    }
    else {
        m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.").arg(source.fileName(), dest.fileName()),
                                DolphinStatusBar::Error);
        reload();
    }
}
Example #3
0
void KuickShow::delayAction(DelayedRepeatEvent *event)
{
    if (m_delayedRepeatItem)
        return;

    m_delayedRepeatItem = event;

    KURL url = event->viewer->currentFile()->url();
//    QFileInfo fi( event->viewer->filename() );
//    start.setPath( fi.dirPath( true ) );
    initGUI( url.upURL() );

    // see eventFilter() for explanation and similar code
    if ( fileWidget->dirLister()->isFinished() &&
         fileWidget->dirLister()->rootItem() )
    {
        fileWidget->setCurrentItem( url.fileName() );
        QTimer::singleShot( 0, this, SLOT( doReplay()));
    }
    else
    {
        fileWidget->setInitialItem( url.fileName() );
        connect( fileWidget, SIGNAL( finished() ),
                 SLOT( doReplay() ));
    }
}
Example #4
0
//FIXME crash on shutdown
void KateFileSelector::setActiveDocumentDir()
{
//   kdDebug(13001)<<"KateFileSelector::setActiveDocumentDir()"<<endl;
  KURL u = mainwin->activeDocumentUrl();
//   kdDebug(13001)<<"URL: "<<u.prettyURL()<<endl;
  if (!u.isEmpty())
    setDir( u.upURL() );
//   kdDebug(13001)<<"... setActiveDocumentDir() DONE!"<<endl;
}
Example #5
0
void Project::insertFile(const KURL& nameURL, bool repaint )
{
  if (d->excludeRx.exactMatch(nameURL.path()))
      return;
  KURL url = nameURL;

  if ( !d->baseURL.isParentOf(url) )
  {
    KURLRequesterDlg *urlRequesterDlg = new KURLRequesterDlg( d->baseURL.prettyURL(), d->m_mainWindow, "");
    urlRequesterDlg->setCaption(i18n("%1: Copy to Project").arg(nameURL.prettyURL(0, KURL::StripFileProtocol)));
    urlRequesterDlg->urlRequester()->setMode( KFile::Directory | KFile::ExistingOnly);
    urlRequesterDlg->exec();
    KURL destination = urlRequesterDlg->selectedURL();
    if (destination.isLocalFile())
    {
      QDir dir(destination.path());
      destination.setPath(dir.canonicalPath());
    }
    delete urlRequesterDlg;
    if ( !destination.isEmpty() )
    {
      CopyTo *dlg = new CopyTo(d->baseURL);
      connect(dlg, SIGNAL(deleteDialog(CopyTo*)), d,
                   SLOT(slotDeleteCopytoDlg(CopyTo*)));
      url = dlg->copy( nameURL, destination );
    }
    else  // Copy canceled, addition aborted
    {
      return;
    }
  }
  QDomElement  el;
  while ( d->baseURL.isParentOf(url) )
  {
    if ( !d->m_projectFiles.contains(url) )
    {
      el = d->dom.createElement("item");
      el.setAttribute("url", QuantaCommon::qUrl( QExtFileInfo::toRelative(url, d->baseURL) ));
      d->dom.firstChild().firstChild().appendChild( el );
      KURL u = url.upURL();
      ProjectURL *parentURL = d->m_projectFiles.find(u);
      int uploadStatus = 1;
      if (parentURL)
        uploadStatus = parentURL->uploadStatus;
      d->m_projectFiles.insert( new ProjectURL(url, "", uploadStatus, false, el) );
    }
    url.setPath(url.directory(false));
  }
  emit eventHappened("after_project_add", url.url(), QString::null);
  setModified();
  if ( repaint )
  {
    emit reloadTree( &(d->m_projectFiles), false, QStringList());
    emit newStatus();
  }
}
Example #6
0
void DirectoryAdder::add(const KURL &dir)
{
	if (dir.upURL().equals(currentJobURL, true))
	{
		// We are a subdir of our currentJobURL and need to get listed next,
		// NOT after all the other dirs that are on the same level as
		// currentJobURL!
		lastAddedSubDirectory = pendingAddDirectories.insert(lastAddedSubDirectory, dir);
		lastAddedSubDirectory++;
	}
	else
	{
		pendingAddDirectories.append(dir);
	}
	addNextPending();
}
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!)

   enum { Konqueror, Konsole, Center, Open, Copy, Delete };

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

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

         if (isDir) {
            popup.insertItem( SmallIconSet( "konqueror" ), i18n( "Open &Konqueror Here" ), Konqueror );

            if( url.protocol() == "file" )
               popup.insertItem( SmallIconSet( "konsole" ), i18n( "Open &Konsole Here" ), Konsole );

            if (m_focus->file() != m_tree) {
               popup.insertSeparator();
               popup.insertItem( SmallIconSet( "viewmag" ), i18n( "&Center Map Here" ), Center );
            }
         }
         else
            popup.insertItem( SmallIconSet( "fileopen" ), i18n( "&Open" ), Open );

         popup.insertSeparator();
         popup.insertItem( SmallIconSet( "editcopy" ), i18n( "&Copy to clipboard" ), Copy );

         popup.insertSeparator();
         popup.insertItem( SmallIconSet( "editdelete" ), i18n( "&Delete" ), Delete );

         switch (popup.exec( e->globalPos(), 1 )) {
            case Konqueror:
                //KRun::runCommand will show an error message if there was trouble
                KRun::runCommand( QString( "kfmclient openURL \"%1\"" ).arg( url.url() ) );
                break;

            case Konsole:
                // --workdir only works for local file paths
                KRun::runCommand( QString( "konsole --workdir \"%1\"" ).arg( url.path() ) );
                break;

            case Center:
            case Open:
                goto section_two;

            case Copy:
                QApplication::clipboard()->setData( new KURLDrag( KURL::List( url ) ) );
                break;

            case Delete:
            {
                const KURL url = Widget::url( m_focus->file() );
                const QString message = m_focus->file()->isDirectory()
                        ? i18n( "<qt>The directory at <i>'%1'</i> will be <b>recursively</b> and <b>permanently</b> deleted." )
                        : i18n( "<qt><i>'%1'</i> will be <b>permanently</b> deleted." );
                const int userIntention = KMessageBox::warningContinueCancel(
                        this, message.arg( url.prettyURL() ),
                        QString::null, KGuiItem( i18n("&Delete"), "editdelete" ) );

                if (userIntention == KMessageBox::Continue) {
                    KIO::Job *job = KIO::del( url );
                    job->setWindow( this );
                    connect( job, SIGNAL(result( KIO::Job* )), SLOT(deleteJobFinished( KIO::Job* )) );
                    QApplication::setOverrideCursor( KCursor::workingCursor() );
                }
            }

            default:
                //ensure m_focus is set for new mouse position
                sendFakeMouseEvent();
         }
      }
      else { // not right mouse button

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

         m_tip->hide(); // user expects this

         if (!isDir || e->button() == Qt::MidButton) {
            KIconEffect::visualActivate( this, rect );
            new KRun( url, this, true ); //FIXME see above
         }
         else if (m_focus->file() != m_tree) { // is left click
            KIconEffect::visualActivate( this, rect );
            emit activated( url ); //activate first, this will cause UI to prepare itself
            createFromCache( (Directory *)m_focus->file() );
         }
         else
            emit giveMeTreeFor( url.upURL() );
      }
   }
}
void URLNavigator::setURL(const KURL& url)
{
    QString urlStr(url.prettyURL());

    if (url.protocol() == "zip") {
       bool stillInside = false;
       if (KMimeType::findByPath(url.url(-1))
           ->is("application/x-zip")) {
           stillInside = true;
       }
       else {
           KURL url1 = url.upURL();
           while (url1 != url1.upURL()) {
               if (KMimeType::findByPath(url1.url(-1))
                   ->is("application/x-zip")) {
                   stillInside = true;
                   break;
               }
               url1 = url1.upURL();
           }
       }
       if (!stillInside)
       {
           // Drop the zip:/ protocol since we are not in the zip anymore
           urlStr = url.path();
       }
    }
    else if (url.protocol() == "tar")
    {
       bool stillInside = false;
       KMimeType::Ptr kmp = 
           KMimeType::findByPath(url.url(-1));
       if (kmp->is("application/x-tar") ||
           kmp->is("application/x-tarz") ||
           kmp->is("application/x-tbz") || 
           kmp->is("application/x-tgz") || 
           kmp->is("application/x-tzo")
           ) {
           stillInside = true;
       }
       else {
           KURL url1 = url.upURL();
           while (url1 != url1.upURL()) {
               KMimeType::Ptr kmp =
                   KMimeType::findByPath(url1.url(-1));
               if (kmp->is("application/x-tar") ||
                   kmp->is("application/x-tarz") ||
                   kmp->is("application/x-tbz") || 
                   kmp->is("application/x-tgz") || 
                   kmp->is("application/x-tzo")
                   ) {
                   stillInside = true;
                   break;
               }
               url1 = url1.upURL();
           }
       }
       if (!stillInside)
       {
           // Drop the tar:/ protocol since we are not in the tar anymore
           urlStr = url.path();
       }
    }


    if (urlStr.at(0) == '~') {
        // replace '~' by the home directory
        urlStr.remove(0, 1);
        urlStr.insert(0, QDir::home().path());
    }

    const KURL transformedURL(urlStr);

    if (m_historyIndex > 0) {
        // Check whether the previous element of the history has the same URL.
        // If yes, just go forward instead of inserting a duplicate history
        // element.
        const KURL& nextURL = m_history[m_historyIndex - 1].url();
        if (transformedURL == nextURL) {
            goForward();
            return;
        }
    }

    const KURL& currURL = m_history[m_historyIndex].url();
    if (currURL == transformedURL) {
        // don't insert duplicate history elements
        return;
    }

    updateHistoryElem();

    const QValueListIterator<URLNavigator::HistoryElem> it = m_history.at(m_historyIndex);
    m_history.insert(it, HistoryElem(transformedURL));
    updateContent();
    emit urlChanged(transformedURL);
    emit historyChanged();

    // Prevent an endless growing of the history: remembering
    // the last 100 URLs should be enough...
    if (m_historyIndex > 100) {
        m_history.erase(m_history.begin());
        --m_historyIndex;
    }
}