Example #1
0
void BaseTreeView::slotDelete()
{
  if (!currentKFileTreeViewItem()) return;
  KURL url = currentURL();
  if (currentKFileTreeViewItem()->isDir())
    url.adjustPath(+1);
  QuantaNetAccess::del(url, m_parent, true);
}
Example #2
0
void KURLCompletion::MyURL::init(const QString &url, const QString &cwd)
{
    // Save the original text
    m_url = url;

    // Non-const copy
    QString url_copy = url;

    // Special shortcuts for "man:" and "info:"
    if(url_copy[0] == '#')
    {
        if(url_copy[1] == '#')
            url_copy.replace(0, 2, QString("info:"));
        else
            url_copy.replace(0, 1, QString("man:"));
    }

    // Look for a protocol in 'url'
    QRegExp protocol_regex = QRegExp("^[^/\\s\\\\]*:");

    // Assume "file:" or whatever is given by 'cwd' if there is
    // no protocol.  (KURL does this only for absoute paths)
    if(protocol_regex.search(url_copy) == 0)
    {
        m_kurl = new KURL(url_copy);
        m_isURL = true;
    }
    else // relative path or ~ or $something
    {
        m_isURL = false;
        if(cwd.isEmpty())
        {
            m_kurl = new KURL();
            if(!QDir::isRelativePath(url_copy) || url_copy[0] == '$' || url_copy[0] == '~')
                m_kurl->setPath(url_copy);
            else
                *m_kurl = url_copy;
        }
        else
        {
            KURL base = KURL::fromPathOrURL(cwd);
            base.adjustPath(+1);

            if(!QDir::isRelativePath(url_copy) || url_copy[0] == '~' || url_copy[0] == '$')
            {
                m_kurl = new KURL();
                m_kurl->setPath(url_copy);
            }
            else // relative path
            {
                // m_kurl = new KURL( base, url_copy );
                m_kurl = new KURL(base);
                m_kurl->addPath(url_copy);
            }
        }
    }
}
Example #3
0
void BaseTreeView::itemRenamed(const KURL& oldURL, const KURL& newURL)
{
  KFileTreeViewItem *curItem = currentKFileTreeViewItem();
  if (! curItem) return;

  if (curItem->isDir())
  {
    KURL n = newURL;
    n.adjustPath(1);
    KURL o = oldURL;
    o.adjustPath(1);
    emit renamed(o, n);
  }
  else
  {
    emit renamed(oldURL, newURL);
  }
}
Example #4
0
KURL CopyTo::copy(const KURL& urlToCopy, const KURL& destination)
{
    m_destList.clear();
    KURL targetDirURL = KURL();
    if ( destination.isEmpty() )
    {
        targetDirURL = m_InitialDirUrl;
    } else
    {
        targetDirURL = destination;
    }
    targetDirURL.adjustPath(1);

    bool doCopy = true;
    if (!QExtFileInfo::exists(targetDirURL, false, 0L))
    {
        doCopy = QExtFileInfo::createDir(targetDirURL, 0L);
    }

    KURL destURL;
    if (doCopy)
    {
        KIO::UDSEntry entry;
        KIO::NetAccess::stat(urlToCopy, entry, 0);
        KFileItem item(entry, urlToCopy, false, true);
        destURL = targetDirURL;
        destURL.setPath(destURL.path(1) + urlToCopy.fileName(false));
        if (item.isDir())
            destURL.adjustPath(1);

        KIO::CopyJob *job = KIO::copy(urlToCopy, destURL, true);
        connect( job, SIGNAL(result( KIO::Job *)),
                 SLOT  (slotResult( KIO::Job *)));

        QString path = destURL.path();
        if (path != "." && path != "..")
            m_destList.append(destURL);
    }

    return destURL;
}
Example #5
0
void BaseTreeView::doRename(KFileTreeViewItem* kftvi, const QString & newName)
{
  if (! kftvi)
    return;

  KURL oldURL = kftvi->url();
  KURL newURL = oldURL;

  if (kftvi->isDir())
  {
    newURL.setPath(QFileInfo(oldURL.path(-1)).dirPath() + '/' + newName + '/');
    oldURL.adjustPath(1);
  } else
  {
    newURL.setFileName(newName);
  }
  if ( oldURL != newURL )
  {
    bool proceed = true;
    if (QExtFileInfo::exists(newURL, false, this))
    {
      proceed = KMessageBox::warningContinueCancel(this, i18n("<qt>The file <b>%1</b> already exists.<br>Do you want to overwrite it?</qt>").arg(newURL.prettyURL(0, KURL::StripFileProtocol)),i18n("Overwrite"), i18n("Overwrite")) == KMessageBox::Continue;
    }
    if (proceed)
    {
    //start the rename job
      oldURL.adjustPath(-1);
      newURL.adjustPath(-1);
      if (!QuantaNetAccess::file_move(oldURL, newURL, -1, true, false, m_parent, true))
      {
        kftvi->setText(0, kftvi->fileItem()->text());  // reset the text
      }
    } else
    {
       kftvi->setText(0, kftvi->fileItem()->text());  // reset the text
    }
  }
}
Example #6
0
void QExtFileInfo::slotNewEntries(KIO::Job *job, const KIO::UDSEntryList& udsList)
{
  KURL url = static_cast<KIO::ListJob *>(job)->url();
  url.adjustPath(-1);
  // avoid creating these QStrings again and again
  static const QString& dot = KGlobal::staticQString(".");
  static const QString& dotdot = KGlobal::staticQString("..");

  KIO::UDSEntryListConstIterator it = udsList.begin();
  KIO::UDSEntryListConstIterator end = udsList.end();
  KURL itemURL;
  for ( ; it != end; ++it )
  {
    QString name;

    // find out about the name
    KIO::UDSEntry::ConstIterator entit = (*it).begin();
    for( ; entit != (*it).end(); ++entit )
      if ( (*entit).m_uds == KIO::UDS_NAME )
      {
        name = (*entit).m_str;
        break;
      }

    if ( ! name.isEmpty() && name != dot && name != dotdot)
    {
      KFileItem* item = new KFileItem( *it, url, false, true );
      itemURL = item->url();
      if (item->isDir()) itemURL.adjustPath(1);
      for ( QPtrListIterator<QRegExp> filterIt( lstFilters ); filterIt.current(); ++filterIt )
      if ( filterIt.current()->exactMatch( item->text() ) )
           dirListItems.append(itemURL);
      delete item;
    }
  }
}
Example #7
0
KURL::List CopyTo::copy(const KURL::List& sourceList, const KURL& destination )
{
    m_listCopy = true;
    m_destList.clear();
    KURL targetDirURL = KURL();
    if ( destination.isEmpty() )
    {
        targetDirURL = m_InitialDirUrl;
    } else
    {
        targetDirURL = destination;
    }
    bool doCopy = true;
    if (!QExtFileInfo::exists(targetDirURL, false, 0L))
    {
        doCopy = QExtFileInfo::createDir(targetDirURL, 0L);
    }

    KIO::UDSEntry entry;
    if (doCopy)
    {
        QString path;
        for (uint i = 0; i < sourceList.count(); i++)
        {
            KURL srcURL = sourceList[i];
            KIO::NetAccess::stat(srcURL, entry, 0);
            KFileItem item(entry, srcURL, false, true);
            KURL u = targetDirURL;
            u.setPath(targetDirURL.path(1) + srcURL.fileName());
            if (item.isDir())
                u.adjustPath(1);
            path = u.path();
            if (path != "." && path != "..")
                m_destList.append(u);
        }

        KIO::CopyJob *job = KIO::copy(sourceList, targetDirURL, true);
        connect( job, SIGNAL(result( KIO::Job *)),
                 SLOT  (slotResult( KIO::Job *)));
    }

    return m_destList;

}
/** No descriptions */
void ProjectNewLocal::slotAddFolder()
{
//TODO/FIXME: This returns null if the selected directory is not on the local disk.
//I think this is a KDE bug
  QExtFileInfo::createDir(baseURL, this);
  KURL dirURL ;
  dirURL = KFileDialog::getExistingURL(
           baseURL.url(),  this, i18n("Insert Folder in Project"));

  if ( !dirURL.isEmpty() )
  {
    dirURL.adjustPath(1);

    KURL sdir = dirURL;
    sdir = QExtFileInfo::toRelative( sdir, baseURL, false);

    if ( sdir.path().startsWith("..") || sdir.path().startsWith("/") )
    {

      KURLRequesterDlg *urlRequesterDlg = new KURLRequesterDlg( baseURL.prettyURL(), this, "");
      urlRequesterDlg->setCaption(i18n("%1: Copy to Project").arg(dirURL.prettyURL(0, KURL::StripFileProtocol)));
      urlRequesterDlg->urlRequester()->setMode( KFile::Directory | KFile::ExistingOnly);
      urlRequesterDlg->exec();
      KURL destination = urlRequesterDlg->selectedURL();
      delete urlRequesterDlg;

      if ( !destination.isEmpty())
      {
        CopyTo *dlg = new CopyTo( baseURL);
        connect(dlg, SIGNAL(addFilesToProject(const KURL::List&)),
                     SLOT  (slotInsertFolderAfterCopying(const KURL::List&)));
        connect(dlg, SIGNAL(deleteDialog(CopyTo *)),
                     SLOT  (slotDeleteCopyToDialog(CopyTo *)));
        dirURL = dlg->copy(dirURL, destination);
        return;
      } else
      {
        return;
      }
    }

    slotInsertFolderAfterCopying(dirURL);
  }
}
Example #9
0
/** create a relative short url based in baseURL*/
KURL QExtFileInfo::toRelative(const KURL& urlToConvert,const KURL& baseURL)
{
  KURL resultURL = urlToConvert;
  if (urlToConvert.protocol() == baseURL.protocol())
  {
    QString path = urlToConvert.path();
    QString basePath = baseURL.path(1);
    if (path.startsWith("/"))
    {
      path.remove(0, 1);
      basePath.remove(0, 1);
      if ( basePath.right(1) != "/" ) basePath.append("/");

      int pos=0;
      int pos1=0;
      for (;;)
      {
        pos=path.find("/");
        pos1=basePath.find("/");
        if ( pos<0 || pos1<0 ) break;
        if ( path.left(pos+1 ) == basePath.left(pos1+1) )
        {
          path.remove(0, pos+1);
          basePath.remove(0, pos1+1);
        }
        else
          break;
      };

      if ( basePath == "/" ) basePath="";
      int level = basePath.contains("/");
      for (int i=0; i<level; i++)
      {
        path="../"+path;
      };
    }

    resultURL.setPath(QDir::cleanDirPath(path));
  }

  if (urlToConvert.path().endsWith("/")) resultURL.adjustPath(1);
  return resultURL;
}
void ProjectNewGeneral::slotLinePrjFile( const QString & )
{

  bool valid = !(linePrjFile->text().isEmpty() ||
                 linePrjName->text().isEmpty() ||
                 linePrjDir ->text().isEmpty() ||
                 linePrjTmpl->text().isEmpty() ||
                 linePrjToolbar->text().isEmpty());
  KURL url;
  QString s = lineHost->text();
  if (! s.isEmpty())
    url.setHost(s);

  s = lineUser->text();
  if (! s.isEmpty())
    url.setUser(s);
  s = linePasswd->text();
  if (! s.isEmpty())
    url.setPass(s);

  s = linePort->text();
  if (! s.isEmpty())
    url.setPort(linePort->text().toInt());

  url.setProtocol(comboProtocol->currentText());
  if (url.protocol() == i18n("Local")) url.setProtocol("file");
  url.setPath(linePrjDir->text());
  url.adjustPath(1);
  if (!url.path().startsWith("/")) url.setPath("/"+url.path());

  if (url.isValid())
  {
    emit setBaseURL(url);
    baseUrl = url;
    if (baseUrl.isLocalFile())
    {
      s = QExtFileInfo::canonicalPath(baseUrl.path());
      if (!s.isEmpty())
        baseUrl.setPath(s);
    }
  }
  emit enableNextButton( this, valid );
}
Example #11
0
void Project::slotAddDirectory(const KURL& p_dirURL, bool showDlg)
{
  KURL dirURL = p_dirURL;
  if ( hasProject() && !dirURL.isEmpty() )
  {
    dirURL.adjustPath(1);
    if ( !d->baseURL.isParentOf(dirURL) )
    {
      KURL destination = d->baseURL;
      if (showDlg)
      {
        KURLRequesterDlg *urlRequesterDlg = new KURLRequesterDlg( d->baseURL.prettyURL(), d->m_mainWindow, "");
        urlRequesterDlg->setCaption(i18n("%1: Copy to Project").arg(dirURL.prettyURL(0, KURL::StripFileProtocol)));
        urlRequesterDlg->urlRequester()->setMode( KFile::Directory | KFile::ExistingOnly);
        urlRequesterDlg->exec();
        destination = urlRequesterDlg->selectedURL();
        delete urlRequesterDlg;
      }
      if ( (showDlg == false) ||
            (!destination.isEmpty()) )
      {
        CopyTo *dlg = new CopyTo(d->baseURL);
        connect(dlg, SIGNAL(addFilesToProject(const KURL::List&)),
                     SLOT  (slotInsertFilesAfterCopying(const KURL::List&)));
        connect(dlg, SIGNAL(deleteDialog(CopyTo *)), d,
                     SLOT  (slotDeleteCopytoDlg(CopyTo *)));
        //if ( rdir.right(1) == "/" ) rdir.remove( rdir.length()-1,1);
        dirURL = dlg->copy(dirURL, destination);
        return;
      }
      else
      {
        return;
      }
    }
    d->insertFiles( dirURL, "*" );
  //And again, insert now directly the directory name into the project.
  //It's important if rdir doesn't contain any files or subdirectories.
    d->insertFiles(dirURL);
    emit reloadTree( &(d->m_projectFiles), false, QStringList() );
  }
}
Example #12
0
/** convert relative filename to absolute */
KURL QExtFileInfo::toAbsolute(const KURL& urlToConvert,const KURL& baseURL)
{
  KURL resultURL = urlToConvert;
  if (urlToConvert.protocol() == baseURL.protocol() && !urlToConvert.path().startsWith("/"))
  {
    int pos;
    QString cutname = urlToConvert.path();
    QString cutdir = baseURL.path(1);
    while ( (pos = cutname.find("../")) >=0 )
    {
       cutname.remove( 0, pos+3 );
       cutdir.remove( cutdir.length()-1, 1 );
       cutdir.remove( cutdir.findRev('/')+1 , 1000);
    }
    resultURL.setPath(QDir::cleanDirPath(cutdir+cutname));
  }

  if (urlToConvert.path().endsWith("/")) resultURL.adjustPath(1);
  return resultURL;
}