home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / konq_operations.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-14  |  7.2 KB  |  216 lines

  1. /*  This file is part of the KDE project
  2.     Copyright (C) 2000  David Faure <faure@kde.org>
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  17. */
  18.  
  19. #ifndef __konq_operations_h__
  20. #define __konq_operations_h__
  21.  
  22. #include <kurl.h>
  23. #include <libkonq_export.h>
  24.  
  25. #include <qobject.h>
  26. #include <qevent.h>
  27.  
  28. namespace KIO { class Job; class CopyInfo; }
  29. class QWidget;
  30. class KFileItem;
  31. class KonqMainWindow;
  32.  
  33. /**
  34.  * Implements file operations (move,del,trash,shred,paste,copy,move,link...)
  35.  * for konqueror and kdesktop whatever the view mode is (icon, tree, ...)
  36.  */
  37. class LIBKONQ_EXPORT KonqOperations : public QObject
  38. {
  39.     Q_OBJECT
  40. protected:
  41.     KonqOperations( QWidget * parent );
  42.     virtual ~KonqOperations();
  43.  
  44. public:
  45.     /**
  46.      * Pop up properties dialog for mimetype @p mimeType.
  47.      */
  48.     static void editMimeType( const QString & mimeType );
  49.  
  50.     enum { TRASH, DEL, SHRED, COPY, MOVE, LINK, EMPTYTRASH, STAT, MKDIR, RESTORE, UNKNOWN };
  51.     /**
  52.      * Delete the @p selectedURLs if possible.
  53.      *
  54.      * @param parent parent widget (for error dialog box if any)
  55.      * @param method should be TRASH, DEL or SHRED
  56.      * @param selectedURLs the URLs to be deleted
  57.      */
  58.     static void del( QWidget * parent, int method, const KURL::List & selectedURLs );
  59.  
  60.     /**
  61.      * Copy the @p selectedURLs to the destination @p destURL.
  62.      *
  63.      * @param parent parent widget (for error dialog box if any)
  64.      * @param method should be COPY, MOVE or LINK
  65.      * @param selectedURLs the URLs to copy
  66.      * @param destURL destination of the copy
  67.      *
  68.      * @todo document restrictions on the kind of destination
  69.      */
  70.     static void copy( QWidget * parent, int method, const KURL::List & selectedURLs, const KURL& destURL );
  71.     /**
  72.      * Drop
  73.      * @param destItem destination KFileItem for the drop (background or item)
  74.      * @param destURL destination URL for the drop.
  75.      * @param ev the drop event
  76.      * @param parent parent widget (for error dialog box if any)
  77.      *
  78.      * If destItem is 0L, doDrop will stat the URL to determine it.
  79.      */
  80.     static void doDrop( const KFileItem * destItem, const KURL & destURL, QDropEvent * ev, QWidget * parent );
  81.  
  82.     /**
  83.      * Paste the clipboard contents
  84.      */
  85.     static void doPaste( QWidget * parent, const KURL & destURL, const QPoint &pos );
  86.     static void doPaste( QWidget * parent, const KURL & destURL );
  87.  
  88.     static void emptyTrash();
  89.     static void restoreTrashedItems( const KURL::List& urls );
  90.  
  91.     /**
  92.      * Create a directory
  93.      */
  94.     static void mkdir( QWidget *parent, const KURL & url );
  95.  
  96.     /**
  97.      * Get info about a given URL, and when that's done (it's asynchronous!),
  98.      * call a given slot with the KFileItem * as argument.
  99.      * The KFileItem will be deleted by statURL after calling the slot. Make a copy
  100.      * if you need one !
  101.      */
  102.     static void statURL( const KURL & url, const QObject *receiver, const char *member );
  103.  
  104.     /**
  105.      * Do a renaming.
  106.      * @param parent the parent widget, passed to KonqOperations ctor
  107.      * @param oldurl the current url of the file to be renamed
  108.      * @param name the new name for the file. Shouldn't include '/'.
  109.      */
  110.     static void rename( QWidget * parent, const KURL & oldurl, const QString & name );
  111.  
  112.     /**
  113.      * Do a renaming.
  114.      * @param parent the parent widget, passed to KonqOperations ctor
  115.      * @param oldurl the current url of the file to be renamed
  116.      * @param newurl the new url for the file
  117.      * Use this version if the other one wouldn't work :)  (e.g. because name could
  118.      * be a relative path, including a '/').
  119.      */
  120.     static void rename( QWidget * parent, const KURL & oldurl, const KURL & newurl );
  121.  
  122.     /**
  123.      * Ask for the name of a new directory and create it.
  124.      * @param parent the parent widget
  125.      * @param baseURL the directory to create the new directory in
  126.      */
  127.     static void newDir( QWidget * parent, const KURL & baseURL );
  128.  
  129.    enum ConfirmationType { DEFAULT_CONFIRMATION, SKIP_CONFIRMATION, FORCE_CONFIRMATION };
  130.    /**
  131.     * Ask for confirmation before deleting/trashing @p selectedURLs.
  132.     * @param selectedURLs the urls about to be deleted
  133.     * @param method the type of deletion (DEL for real deletion, anything else for trash)
  134.     * @param confirmation default (based on config file), skip (no confirmation) or force (always confirm)
  135.     * @param widget parent widget for message boxes
  136.     * @return true if confirmed
  137.     */
  138.    static bool askDeleteConfirmation( const KURL::List & selectedURLs, int method, ConfirmationType confirmation, QWidget* widget );
  139.  
  140. signals:
  141.     void statFinished( const KFileItem * item );
  142.     void aboutToCreate(const QPoint &pos, const QValueList<KIO::CopyInfo> &files);
  143.  
  144. protected:
  145.     void _del( int method, const KURL::List & selectedURLs, ConfirmationType confirmation );
  146.     void _restoreTrashedItems( const KURL::List& urls );
  147.     void _statURL( const KURL & url, const QObject *receiver, const char *member );
  148.  
  149.     // internal, for COPY/MOVE/LINK/MKDIR
  150.     void setOperation( KIO::Job * job, int method, const KURL::List & src, const KURL & dest );
  151.  
  152.     struct DropInfo
  153.     {
  154.         DropInfo( uint k, KURL::List & l, const QMap<QString,QString> &m,
  155.                   int x, int y, QDropEvent::Action a ) :
  156.             keybstate(k), lst(l), metaData(m), mousePos(x,y), action(a) {}
  157.         uint keybstate;
  158.         KURL::List lst;
  159.         QMap<QString,QString> metaData;
  160.         QPoint mousePos;
  161.         QDropEvent::Action action;
  162.     };
  163.     // internal, for doDrop
  164.     void setDropInfo( DropInfo * info ) { m_info = info; }
  165.  
  166.     struct KIOPasteInfo // KDE4: remove and use DropInfo instead or a QPoint member
  167.     {
  168.         QByteArray data;  // unused
  169.         KURL destURL;     // unused
  170.         QPoint mousePos;
  171.         QString dialogText; // unused
  172.     };
  173.     void setPasteInfo( KIOPasteInfo * info ) { m_pasteInfo = info; }
  174.  
  175. private:
  176.     QWidget* parentWidget() const;
  177.  
  178. protected slots:
  179.  
  180.     void slotAboutToCreate(KIO::Job *job, const QValueList<KIO::CopyInfo> &files);
  181.     void slotResult( KIO::Job * job );
  182.     void slotStatResult( KIO::Job * job );
  183.     void asyncDrop( const KFileItem * item );
  184.     void doFileCopy();
  185.  
  186. private:
  187.     int m_method;
  188.     //KURL::List m_srcURLs;
  189.     KURL m_destURL;
  190.     // for doDrop
  191.     DropInfo * m_info;
  192.     KIOPasteInfo * m_pasteInfo;
  193. };
  194.  
  195. #include <kio/job.h>
  196.  
  197. /// Restore multiple trashed files
  198. class KonqMultiRestoreJob : public KIO::Job
  199. {
  200.     Q_OBJECT
  201.  
  202. public:
  203.     KonqMultiRestoreJob( const KURL::List& urls, bool showProgressInfo );
  204.  
  205. protected slots:
  206.     virtual void slotStart();
  207.     virtual void slotResult( KIO::Job *job );
  208.  
  209. private:
  210.     const KURL::List m_urls;
  211.     KURL::List::const_iterator m_urlsIterator;
  212.     int m_progress;
  213. };
  214.  
  215. #endif
  216.