Example #1
0
void ScanGallery::slotUrlsDropped(QDropEvent *ev, FileTreeViewItem *item)
{
    KUrl::List urls = ev->mimeData()->urls();
    if (urls.isEmpty()) return;

    kDebug() << "onto" << (item==NULL ? "NULL" : item->url().prettyUrl())
             << "srcs" << urls.count() << "first" << urls.first();
    
    if (item==NULL) return;
    KUrl dest = item->url();

    // Check whether the drop is on top of a directory (in which case we
    // want to move/copy into it) or a file (move/copy into its containing
    // directory).
    if (!item->isDir()) dest.setFileName(QString::null);
    dest.adjustPath(KUrl::AddTrailingSlash);
    kDebug() << "resolved destination" << dest;

    // Make the last URL to copy the one to select next
    KUrl nextSel = dest;
    nextSel.addPath(urls.back().fileName(KUrl::ObeyTrailingSlash));
    m_nextUrlToShow = nextSel;

    KIO::Job *job;
    // TODO: top level window as 3rd parameter?
    if (ev->dropAction()==Qt::MoveAction) job = KIO::move(urls, dest);
    else job = KIO::copy(urls, dest);
    connect(job, SIGNAL(result(KJob *)), SLOT(slotJobResult(KJob *)));
}
QString Cache::findCachedPath(KUrl &url)
{
  url.adjustPath(KUrl::RemoveTrailingSlash);
  
  if (m_pathCache.contains(url))
    return m_pathCache[url];
  
  return QString::null;
}
Example #3
0
void ApplicationsProtocol::listDir(const KUrl& url)
{
    QString groupPath = url.path( KUrl::AddTrailingSlash );
    groupPath.remove(0, 1); // remove starting '/'

    KServiceGroup::Ptr grp = KServiceGroup::group(groupPath);

    if (!grp || !grp->isValid()) {
        error(KIO::ERR_DOES_NOT_EXIST, groupPath);
        return;
    }

    unsigned int count = 0;
    KIO::UDSEntry entry;

    foreach (const KSycocaEntry::Ptr &e, grp->entries(true, true)) {
        if (e->isType(KST_KServiceGroup)) {
            KServiceGroup::Ptr g(KServiceGroup::Ptr::staticCast(e));
            QString groupCaption = g->caption();

            kDebug() << "ADDING SERVICE GROUP WITH PATH " << g->relPath();

            // Avoid adding empty groups.
            KServiceGroup::Ptr subMenuRoot = KServiceGroup::group(g->relPath());
            if (subMenuRoot->childCount() == 0)
                continue;

            // Ignore dotfiles.
            if ((g->name().at(0) == '.'))
                continue;

            QString relPath = g->relPath();
            KUrl dirUrl = url; // preserve protocol, whether that's programs:/ or applications:/
            dirUrl.setPath('/' + relPath);
            dirUrl.adjustPath(KUrl::RemoveTrailingSlash);
            kDebug() << "ApplicationsProtocol: adding entry" << dirUrl;
            createDirEntry(entry, groupCaption, dirUrl.url(), "inode/directory", g->icon());

        } else {
            KService::Ptr service(KService::Ptr::staticCast(e));

            kDebug() << "the entry name is" << service->desktopEntryName()
                     << "with path" << service->entryPath();

            if (!service->isApplication()) // how could this happen?
                continue;
            createFileEntry(entry, service, url);
        }

        listEntry(entry, false);
        count++;
    }

    totalSize(count);
    listEntry(entry, true);
    finished();
}
Example #4
0
void QuantaProjectPart::slotTargetFolderSelected(QAction *action, const KUrl& url)
{
  Q_UNUSED(action);
  KUrl u = url;
  u.adjustPath(KUrl::AddTrailingSlash);
  QuantaNetAccess::dircopy(m_fileContextURLs, u, this, false);
  m_browserMenu->deleteLater();
  m_browserMenu = 0L;
}
DirectoryListing Cache::findCached(KUrl &url)
{
  url.adjustPath(KUrl::RemoveTrailingSlash);
  
  if (m_listingCache.contains(url))
    return m_listingCache[url];
    
  DirectoryListing invalid;
  invalid.setValid(false);
  
  return invalid;
}
void Cache::updateDirectoryEntry(Socket *socket, KUrl &path, filesize_t filesize)
{
  KUrl url = socket->getCurrentUrl();
  url.setPath(path.directory());
  url.adjustPath(KUrl::RemoveTrailingSlash);
  
  if (m_listingCache.contains(url)) {
    DirectoryListing listing = m_listingCache[url];
    listing.updateEntry(path.fileName(), filesize);
    
    m_listingCache.insert(url, listing);
  }
}
Example #7
0
/* The absolute URL of the item (if it is a directory), or its parent (if
   it is a file).
*/
KUrl ScanGallery::itemDirectory(const FileTreeViewItem *item) const
{
    if (item==NULL)
    {
        kDebug() << "no item";
        return (KUrl());
    }

    KUrl u = item->url();
    if (!item->isDir()) u.setFileName("");		// not a directory, remove file name
    else u.adjustPath(KUrl::AddTrailingSlash);		// is a directory, ensure ends with "/"
    return (u);
}
Example #8
0
void GvCore::addUrlToRecentFolders(KUrl url)
{
    if (!GwenviewConfig::historyEnabled()) {
        return;
    }
    if (!url.isValid()) {
        return;
    }
    if (url.path() != "") { // This check is a workaraound for bug #312060
        url.adjustPath(KUrl::AddTrailingSlash);
    }
    recentFoldersModel();
    d->mRecentFoldersModel->addUrl(url);
}
Example #9
0
bool FavoritePlacesModel::trigger(int row, const QString &actionId, const QVariant &actionArgument)
{
    QModelIndex idx = index(row, 0);
    KUrl theUrl = idx.data(Fixes::KFilePlacesModel::UrlRole).value<QUrl>();
    if (actionId.isEmpty()) {
        theUrl.adjustPath(KUrl::AddTrailingSlash);
        QString rootName = idx.data(Qt::DisplayRole).toString();
        openSourceRequested("Dir", DirModel::sourceArguments(theUrl, rootName, theUrl));
        return false;
    }

    bool close;
    KFileItem item(KFileItem::Unknown, KFileItem::Unknown, theUrl);
    if (ActionList::handleFileItemAction(item, actionId, actionArgument, &close)) {
        return close;
    }

    return false;
}
Example #10
0
void QuantaProjectPart::slotInsertFolder()
{
  KUrl url = KUrl();
  url = KFileDialog::getExistingUrl(m_projectBase, Koncrete::Core::mainWindow(), i18n("Insert Folder in Project"));

  if (!url.isEmpty())
  {
    if (!m_projectBase.isParentOf(url))
    {
      KUrlRequesterDialog urlRequesterDlg(m_projectBase.pathOrUrl(), Koncrete::Core::mainWindow());
      urlRequesterDlg.setWindowTitle(i18n("%1: Copy to Project", url.pathOrUrl()));
      urlRequesterDlg.urlRequester()->setMode(KFile::Directory | KFile::ExistingOnly);
      urlRequesterDlg.exec();
      KUrl destination = urlRequesterDlg.selectedUrl();
      if (!destination.isEmpty())
      {
        destination.adjustPath(KUrl::AddTrailingSlash);
        QuantaNetAccess::dircopy(url, destination, this, false);
      }
    } else
    {
      KUrl::List urls = ExtFileInfo::allFilesRelative(url, "*");
      QStringList filenames;
      KUrl u = KUrl::relativeUrl(m_projectBase, url);
      QStringList sections = u.path(KUrl::AddTrailingSlash).split('/', QString::SkipEmptyParts);
      QString section;
      for (int i = 0 ; i < sections.count(); i++)
      {
        section += sections[i] + '/';
        filenames += section;
      }
      KUrl::List::ConstIterator end = urls.constEnd();
      for (KUrl::List::ConstIterator it = urls.begin(); it != end; ++it)
      {
        filenames += url.fileName() + '/' + (*it).path();
      }
      addFiles(filenames);
    }
  }
}
void MagnatuneDownloadDialog::downloadButtonClicked( )
{

    if (m_currentDownloadInfo == 0) return;

    QString format = formatComboBox->currentText();
    QString path = downloadTargetURLRequester->url().url();;

    //store to config for next download:
    KConfigGroup config = Amarok::config("Service_Magnatune");
    config.writeEntry( "Download Format", format );
    config.writeEntry( "Download Path", path );
    
    m_currentDownloadInfo->setFormatSelection( format );

    KUrl unpackLocation = downloadTargetURLRequester->url();
    unpackLocation.adjustPath( KUrl::AddTrailingSlash );
    m_currentDownloadInfo->setUnpackUrl( unpackLocation.directory( KUrl::ObeyTrailingSlash ) );

    emit( downloadAlbum( m_currentDownloadInfo ) );

    close();

}
void Cache::addPath(KUrl &url, const QString &target)
{
  url.adjustPath(KUrl::RemoveTrailingSlash);
  m_pathCache[url] = target;
}
void Cache::invalidatePath(KUrl &url)
{
  url.adjustPath(KUrl::RemoveTrailingSlash);
  m_pathCache.remove(url);
}
void Cache::invalidateEntry(KUrl &url)
{
  url.adjustPath(KUrl::RemoveTrailingSlash);
  m_listingCache.remove(url);
}
Example #15
0
void KUrlNavigator::Private::updateButtonVisibility()
{
    if (m_editable) {
        return;
    }

    const int buttonsCount = m_navButtons.count();
    if (buttonsCount == 0) {
        m_dropDownButton->hide();
        return;
    }

    // Subtract all widgets from the available width, that must be shown anyway
    int availableWidth = q->width() - m_toggleEditableMode->minimumWidth();

    if ((m_placesSelector != 0) && m_placesSelector->isVisible()) {
        availableWidth -= m_placesSelector->width();
    }

    if ((m_protocols != 0) && m_protocols->isVisible()) {
        availableWidth -= m_protocols->width();
    }

    // Check whether buttons must be hidden at all...
    int requiredButtonWidth = 0;
    foreach (const KUrlNavigatorButton* button, m_navButtons) {
        requiredButtonWidth += button->minimumWidth();
    }

    if (requiredButtonWidth > availableWidth) {
        // At least one button must be hidden. This implies that the
        // drop-down button must get visible, which again decreases the
        // available width.
        availableWidth -= m_dropDownButton->width();
    }

    // Hide buttons...
    QList<KUrlNavigatorButton*>::const_iterator it = m_navButtons.constEnd();
    const QList<KUrlNavigatorButton*>::const_iterator itBegin = m_navButtons.constBegin();
    bool isLastButton = true;
    bool hasHiddenButtons = false;

    QLinkedList<KUrlNavigatorButton*> buttonsToShow;
    while (it != itBegin) {
        --it;
        KUrlNavigatorButton* button = (*it);
        availableWidth -= button->minimumWidth();
        if ((availableWidth <= 0) && !isLastButton) {
            button->hide();
            hasHiddenButtons = true;
        }
        else {
            // Don't show the button immediately, as setActive()
            // might change the size and a relayout gets triggered
            // after showing the button. So the showing of all buttons
            // is postponed until all buttons have the correct
            // activation state.
            buttonsToShow.append(button);
        }
        isLastButton = false;
    }

    // All buttons have the correct activation state and
    // can be shown now
    foreach (KUrlNavigatorButton* button, buttonsToShow) {
        button->show();
    }

    if (hasHiddenButtons) {
        m_dropDownButton->show();
    } else {
        // Check whether going upwards is possible. If this is the case, show the drop-down button.
        KUrl url = m_navButtons.front()->url();
        url.adjustPath(KUrl::AddTrailingSlash);
        const bool visible = !url.equals(url.upUrl());
        m_dropDownButton->setVisible(visible);
    }
}