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 / knewmenu.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.0 KB  |  225 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 1998-2000 David Faure <faure@kde.org>
  3.                  2003      Sven Leiber <s.leiber@web.de>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License version 2 as published by the Free Software Foundation.
  8.  
  9.    This library 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 GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __knewmenu_h
  21. #define __knewmenu_h
  22.  
  23. #include <qintdict.h>
  24. #include <qstringlist.h>
  25.  
  26. #include <kaction.h>
  27. #include <kdialogbase.h>
  28. #include <kurl.h>
  29. #include <libkonq_export.h>
  30.  
  31. namespace KIO { class Job; }
  32.  
  33. class KDirWatch;
  34. class KLineEdit;
  35. class KURLRequester;
  36. class QPopupMenu;
  37.  
  38. /**
  39.  * The 'New' submenu, both for the File menu and the RMB popup menu.
  40.  * (The same instance can be used by both).
  41.  * Fills it with 'Folder' and one item per Template.
  42.  * For this you need to connect aboutToShow() of the File menu with slotCheckUpToDate()
  43.  * and to call slotCheckUpToDate() before showing the RMB popupmenu.
  44.  *
  45.  * KNewMenu automatically updates the list of templates if templates are
  46.  * added/updated/deleted.
  47.  *
  48.  * @author David Faure <faure@kde.org>
  49.  * Ideas and code for the new template handling mechanism ('link' desktop files)
  50.  * from Christoph Pickart <pickart@iam.uni-bonn.de>
  51.  */
  52. class LIBKONQ_EXPORT KNewMenu : public KActionMenu
  53. {
  54.   Q_OBJECT
  55. public:
  56.  
  57.     /**
  58.      * Constructor
  59.      */
  60.     KNewMenu( KActionCollection * _collec, const char *name=0L );
  61.     KNewMenu( KActionCollection * _collec, QWidget *parentWidget, const char *name=0L );
  62.     virtual ~KNewMenu();
  63.  
  64.     /**
  65.      * Set the files the popup is shown for
  66.      * Call this before showing up the menu
  67.      */
  68.     void setPopupFiles(KURL::List & _files) {
  69.         popupFiles = _files;
  70.     }
  71.     void setPopupFiles(const KURL & _file) {
  72.         popupFiles.clear();
  73.         popupFiles.append( _file );
  74.     }
  75.  
  76. public slots:
  77.     /**
  78.      * Checks if updating the list is necessary
  79.      * IMPORTANT : Call this in the slot for aboutToShow.
  80.      */
  81.     void slotCheckUpToDate( );
  82.  
  83. protected slots:
  84.     /**
  85.      * Called when New->Directory... is clicked
  86.      */
  87.     void slotNewDir();
  88.  
  89.     /**
  90.      * Called when New->* is clicked
  91.      */
  92.     void slotNewFile();
  93.  
  94.     /**
  95.      * Fills the templates list.
  96.      */
  97.     void slotFillTemplates();
  98.  
  99.     void slotResult( KIO::Job * );
  100.     // Special case (filename conflict when creating a link=url file)
  101.     void slotRenamed( KIO::Job *, const KURL&, const KURL& );
  102.  
  103. private:
  104.  
  105.     /**
  106.      * Fills the menu from the templates list.
  107.      */
  108.     void fillMenu();
  109.  
  110.     /**
  111.      * Opens the desktop files and completes the Entry list
  112.      * Input: the entry list. Output: the entry list ;-)
  113.      */
  114.     void parseFiles();
  115.  
  116.     /**
  117.      * Make the main menus on the startup.
  118.      */
  119.     void makeMenus();
  120.  
  121.     /**
  122.      * For entryType
  123.      * LINKTOTEMPLATE: a desktop file that points to a file or dir to copy
  124.      * TEMPLATE: a real file to copy as is (the KDE-1.x solution)
  125.      * SEPARATOR: to put a separator in the menu
  126.      * 0 means: not parsed, i.e. we don't know
  127.      */
  128.     enum { LINKTOTEMPLATE = 1, TEMPLATE, SEPARATOR };
  129.  
  130.     struct Entry {
  131.         QString text;
  132.         QString filePath; // empty for SEPARATOR
  133.         QString templatePath; // same as filePath for TEMPLATE
  134.         QString icon;
  135.         int entryType;
  136.         QString comment;
  137.     };
  138.     // NOTE: only filePath is known before we call parseFiles
  139.  
  140.     /**
  141.      * List of all template files. It is important that they are in
  142.      * the same order as the 'New' menu.
  143.      */
  144.     static QValueList<Entry> * s_templatesList;
  145.  
  146.     class KNewMenuPrivate;
  147.     KNewMenuPrivate* d;
  148.  
  149.     /**
  150.      * Is increased when templatesList has been updated and
  151.      * menu needs to be re-filled. Menus have their own version and compare it
  152.      * to templatesVersion before showing up
  153.      */
  154.     static int s_templatesVersion;
  155.  
  156.     /**
  157.      * Set back to false each time new templates are found,
  158.      * and to true on the first call to parseFiles
  159.      */
  160.     static bool s_filesParsed;
  161.  
  162.     int menuItemsVersion;
  163.  
  164.     /**
  165.      * When the user pressed the right mouse button over an URL a popup menu
  166.      * is displayed. The URL belonging to this popup menu is stored here.
  167.      */
  168.     KURL::List popupFiles;
  169.  
  170.     /**
  171.      * True when a desktop file with Type=URL is being copied
  172.      */
  173.     bool m_isURLDesktopFile;
  174.     QString m_linkURL; // the url to put in the file
  175.  
  176.     static KDirWatch * s_pDirWatch;
  177. };
  178.  
  179. /**
  180.  * @internal
  181.  * Dialog to ask for a filename and a URL, when creating a link to a URL.
  182.  * Basically a merge of KLineEditDlg and KURLRequesterDlg ;)
  183.  * @author David Faure <faure@kde.org>
  184.  */
  185. class KURLDesktopFileDlg : public KDialogBase
  186. {
  187.     Q_OBJECT
  188. public:
  189.     KURLDesktopFileDlg( const QString& textFileName, const QString& textUrl );
  190.     KURLDesktopFileDlg( const QString& textFileName, const QString& textUrl, QWidget *parent );
  191.     virtual ~KURLDesktopFileDlg() {}
  192.  
  193.     /**
  194.      * @return the filename the user entered (no path)
  195.      */
  196.     QString fileName() const;
  197.     /**
  198.      * @return the URL the user entered
  199.      */
  200.     QString url() const;
  201.  
  202. protected slots:
  203.     void slotClear();
  204.     void slotNameTextChanged( const QString& );
  205.     void slotURLTextChanged( const QString& );
  206. private:
  207.     void initDialog( const QString& textFileName, const QString& defaultName, const QString& textUrl, const QString& defaultUrl );
  208.  
  209.     /**
  210.      * The line edit widget for the fileName
  211.      */
  212.     KLineEdit *m_leFileName;
  213.     /**
  214.      * The URL requester for the URL :)
  215.      */
  216.     KURLRequester *m_urlRequester;
  217.  
  218.     /**
  219.      * True if the filename was manually edited.
  220.      */
  221.     bool m_fileNameEdited;
  222. };
  223.  
  224. #endif
  225.