[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/graphics/kcoloredit/src
From:       Percy Camilo Triveño Aucahuasi <orgyforever () gmail ! com>
Date:       2008-09-01 1:00:57
Message-ID: 1220230857.932939.29279.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 855530 by aucahuasi:

* Refactoring PaletteDialog, KColorEdit and PaletteDocument:
Now we use KUrl instead QString/Parse methods ... 


 M  +36 -25    app/kcoloredit.cpp  
 M  +8 -8      app/kcoloredit.h  
 M  +2 -9      app/main.cpp  
 M  +17 -25    core/palettedocument.cpp  
 M  +6 -10     core/palettedocument.h  
 M  +21 -21    dialog/palettedialog.cpp  
 M  +8 -8      dialog/palettedialog.h  
 M  +2 -0      widgets/multipagewidget.cpp  


--- trunk/extragear/graphics/kcoloredit/src/app/kcoloredit.cpp #855529:855530
@@ -17,7 +17,7 @@
 *  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.                 *
 *********************************************************************************/
 
-// BIGGGGGGGGG TODO her ... recent files etc etc refactor this clase ... use kurl in \
docueent ... +// BIGGGGGGGGG TODO here ... recent files etc etc refactor this clase
 
 #include "kcoloredit.h"
 
@@ -51,17 +51,15 @@
 {
 }
 
-void KColorEditMainWnd::openPaletteFile(const QString & file)
+void KColorEditMainWnd::openPaletteFile(const KUrl & url)
 {
-    QString fileNameFromDialog = file;
-
     QString tmpFile;
 
-    if (!fileNameFromDialog.isEmpty())
+    if (!url.path().isEmpty())
     {
-        if (KIO::NetAccess::download(fileNameFromDialog, tmpFile, this))
+        if (KIO::NetAccess::download(url, tmpFile, this))
         {
-            if (m_paletteDocument->openPaletteFile(tmpFile))
+            if (m_paletteDocument->openFile(KUrl(tmpFile)))
             {
                 m_paletteDetailView->setModel(m_paletteDocument->model());
                 m_paletteDetailView->updatePaletteDetails();
@@ -91,24 +89,37 @@
 
 void KColorEditMainWnd::newFile()
 {
+    KColorEditMainWnd * newWnd = new KColorEditMainWnd();
+    newWnd->show();
 }
 
-void KColorEditMainWnd::openFile(const KUrl & url)
+void KColorEditMainWnd::registerRecentFile(const KUrl & url)
 {
-    QString fileNameFromDialog;
-
-    if (url.fileName().isEmpty())
-        fileNameFromDialog = PaletteDialog::getOpenPaletteName();
+    if (m_paletteDocument->openFile(url))
+        m_recentFilesAction->addUrl(url);
     else
-        fileNameFromDialog = url.fileName();
+        m_recentFilesAction->removeUrl(url);
+}
 
+void KColorEditMainWnd::openFile()
+{
+    KUrl fileNameFromDialog = PaletteDialog::getOpenUrl();
+
+    //if (url.fileName().isEmpty())
+    //    fileNameFromDialog = 
+    //else
+//     {
+//         //fileNameFromDialog = url.fileName();
+//         m_recentFilesAction->addUrl( KUrl(fileNameFromDialog) );
+//     }
+
     QString tmpFile;
 
     if (!fileNameFromDialog.isEmpty())
     {
         if (KIO::NetAccess::download(fileNameFromDialog, tmpFile, this))
         {
-            if (m_paletteDocument->openPaletteFile(tmpFile))
+            if (m_paletteDocument->openFile(KUrl(tmpFile)))
             {
                 m_paletteDetailView->setModel(m_paletteDocument->model());
                 m_paletteDetailView->updatePaletteDetails();
@@ -122,6 +133,9 @@
                     \
m_paletteDocument->model()->setData(m_paletteDocument->model()->index(0, 0), \
m_paletteDocument->model()->index(0, 0).data());  
                 updateTittleWhenOpenSaveDoc();
+
+                // TODO WARNING
+                //registerRecentFile(KUrl(tmpFile));
             }
             else
                 KMessageBox::error(this, m_paletteDocument->lastErrorString());
@@ -135,9 +149,9 @@
 
 void KColorEditMainWnd::saveFile()
 {
-    if(!m_paletteDocument->fullPathFileName().isEmpty())
+    if(!m_paletteDocument->url().fileName().isEmpty())
     {
-        if (!m_paletteDocument->saveFileAs(m_paletteDocument->fullPathFileName()))
+        if (!m_paletteDocument->saveFileAs(m_paletteDocument->url()))
             KMessageBox::error(this, m_paletteDocument->lastErrorString());
         else
             updateTittleWhenOpenSaveDoc();
@@ -172,11 +186,6 @@
     }
 }
 
-void KColorEditMainWnd::newWindow()
-{
-    KColorEditMainWnd * newWnd = new KColorEditMainWnd();
-    newWnd->show();
-}
 
 /*
 // TODO
@@ -267,7 +276,7 @@
 
 void KColorEditMainWnd::updateTittleWhenChangeDocState()
 {
-    setWindowTitle(QString("KColorEdit") + " - " + m_paletteDocument->fileName() + \
i18n(" [modified]")); +    setWindowTitle(QString("KColorEdit") + " - " + \
m_paletteDocument->url().fileName() + i18n(" [modified]"));  }
 
 void KColorEditMainWnd::setupWidgets()
@@ -401,9 +410,11 @@
     KStandardAction::save   (this, SLOT( saveFile()   ), actionCollection());
     KStandardAction::saveAs (this, SLOT( saveFileAs() ), actionCollection());
 
-    KStandardAction::openRecent(this, SLOT( openFile(KUrl) ), actionCollection());
+    m_recentFilesAction = KStandardAction::openRecent(this, SLOT( \
registerRecentFile(KUrl) ), actionCollection()); +    \
//KStandardAction::openRecent(this, SLOT( openFile(KUrl) ), actionCollection()); +    \
connect( m_recentFilesAction, SIGNAL( triggered() ), this, SLOT( openFile() ) );  
-    KStandardAction::openNew(this, SLOT( newWindow()       ), actionCollection());
+    KStandardAction::openNew(this, SLOT( newFile()       ), actionCollection());
     // TODO print
     //KStandardAction::print      (this, SLOT( slotFilePrint()           ), \
actionCollection());  // TODO settings
@@ -414,7 +425,7 @@
 void KColorEditMainWnd::updateTittleWhenOpenSaveDoc()
 {
     // setup the window title acording to the file name
-    setWindowTitle(QString("KColorEdit") + " - " + m_paletteDocument->fileName());
+    setWindowTitle(QString("KColorEdit") + " - " + \
m_paletteDocument->url().fileName());  }
 
 #include "kcoloredit.moc"
--- trunk/extragear/graphics/kcoloredit/src/app/kcoloredit.h #855529:855530
@@ -25,6 +25,8 @@
 
 class QDockWidget;
 
+class KRecentFilesAction;
+
 class PaletteDocument;
 class PaletteDetailView;
 class PaletteBriefView;
@@ -39,18 +41,15 @@
         explicit KColorEditMainWnd(QWidget * parent = 0, Qt::WindowFlags f = \
KDE_DEFAULT_WINDOWFLAGS);  ~KColorEditMainWnd();
 
-        void openPaletteFile(const QString & file);
+        void openPaletteFile(const KUrl & url);
 
-    public slots:
+    private slots:
         void newFile();
-        void openFile(const KUrl & url = KUrl());
+        void openFile();
+        void registerRecentFile(const KUrl & url);
         void saveFile();
         void saveFileAs();
 
-        void newWindow();
-        // TODO settings
-        //void settingsPreferences();
-
         void cleanPalette();
         void generateColorNames();
         void completeColorNames();
@@ -65,7 +64,6 @@
         void moveBegin();
         void moveEnd();
 
-    private slots:
         void updateTittleWhenChangeDocState();
         void updateTittleWhenOpenSaveDoc();
 
@@ -76,6 +74,8 @@
         QString appName() const;
 
     private:
+        KRecentFilesAction * m_recentFilesAction;
+
         PaletteDocument * m_paletteDocument;
 
         PaletteBriefView * m_paletteBriefView;
--- trunk/extragear/graphics/kcoloredit/src/app/main.cpp #855529:855530
@@ -25,21 +25,14 @@
 #include <KAboutData>
 #include <KIcon>
 
-inline KAboutData kcoloreditAboutData( const char * name, const char * iname )
+int main(int argc, char * argv[])
 {
-    KAboutData about(name, 0, ki18n(iname), "1.99.50 (KColorEdit 2.0 Beta 2)",
+    KAboutData about("kcoloredit", 0, ki18n(I18N_NOOP("KColorEdit")), "1.99.50 \
                (KColorEdit 2.0 Beta 2)",
         ki18n(I18N_NOOP("KColorEdit, great tool for editing color palettes.")),
         KAboutData::License_GPL, ki18n("(C) 2008, Percy Camilo Triveño Aucahuasi\n" \
                "(C) 2000, Artur Rataj"));
     about.addAuthor(ki18n("Percy Camilo Triveño Aucahuasi"), ki18n("Current \
                maintainer - Upgraded and developed the new version."), \
                "orgyforever@gmail.com");
     about.addAuthor(ki18n("Artur Rataj"), ki18n("Former maintainer - Created \
KColorEdit"), "art@zeus.polsl.gliwice.pl");  
-    return about;
-}
-
-int main(int argc, char * argv[])
-{
-    KAboutData about = kcoloreditAboutData("kcoloredit", I18N_NOOP("KColorEdit"));
-
     KCmdLineArgs::init(argc, argv, &about);
 
     KCmdLineOptions options;
--- trunk/extragear/graphics/kcoloredit/src/core/palettedocument.cpp #855529:855530
@@ -33,7 +33,6 @@
 PaletteDocument::PaletteDocument(QObject * parent)
     : QObject(parent)
     , m_model(new PaletteModel(this))
-    , m_fullPathFile(QString())
     , m_documentType(PaletteDocument::KDEType)
 {
     connect(m_model, SIGNAL( dataChanged(QModelIndex, QModelIndex) ), SLOT( \
updatePaletteDocument() )); @@ -44,25 +43,10 @@
 {
 }
 
-QString PaletteDocument::fullPathFileName() const
+bool PaletteDocument::openFile(const KUrl & url)
 {
-    return m_fullPathFile;
-}
+    QFile file(url.path());
 
-QString PaletteDocument::fileName() const
-{
-    return m_file;
-}
-
-PaletteModel * PaletteDocument::model()
-{
-    return m_model;
-}
-
-bool PaletteDocument::openPaletteFile(const QString & fileName)
-{
-    QFile file(fileName);
-
     //NOTE
     // Checking errors
 
@@ -179,17 +163,16 @@
 
     extractDescriptionFromModel();
 
-    m_fullPathFile = fileName;
-    m_file = m_fullPathFile.split('/')[m_fullPathFile.split('/').count() - 1];
-
     file.close();
 
+    m_url = url;
+
     return true;
 }
 
-bool PaletteDocument::saveFileAs(const QString & fileName)
+bool PaletteDocument::saveFileAs(const KUrl & url)
 {
-    KSaveFile saveFile(fileName);
+    KSaveFile saveFile(url.path());
 
     // Checking errors
     if (!saveFile.open())
@@ -252,17 +235,26 @@
         return false;
     }
 
-    m_fullPathFile = fileName;
-    m_file = m_fullPathFile.split('/')[m_fullPathFile.split('/').count() - 1];
+    m_url = url;
 
     return true;
 }
 
+KUrl PaletteDocument::url() const
+{
+    return m_url;
+}
+
 PaletteDocument::DocumentType PaletteDocument::type() const
 {
     return m_documentType;
 }
 
+PaletteModel * PaletteDocument::model()
+{
+    return m_model;
+}
+
 QString PaletteDocument::lastErrorString() const
 {
     return m_lastErrorString;
--- trunk/extragear/graphics/kcoloredit/src/core/palettedocument.h #855529:855530
@@ -20,7 +20,7 @@
 #ifndef PALETTE_DOCUMENT_H
 #define PALETTE_DOCUMENT_H
 
-#include <QtCore/QObject>
+#include <KUrl>
 
 class PaletteModel;
 
@@ -34,16 +34,13 @@
         PaletteDocument(QObject * parent = 0);
         ~PaletteDocument();
 
-        QString fullPathFileName() const;
-        QString fileName() const;
-
-        PaletteModel * model();
-
-        bool openPaletteFile(const QString & fileName);
+        bool openFile(const KUrl & url);
         bool saveFile();
-        bool saveFileAs(const QString & fileName);
+        bool saveFileAs(const KUrl & url);
 
+        KUrl url() const;
         PaletteDocument::DocumentType type() const;
+        PaletteModel * model();
 
         QString lastErrorString() const;
 
@@ -57,9 +54,8 @@
         void extractDescriptionFromModel();
 
     private:
+        KUrl m_url;
         PaletteModel * m_model;
-        QString m_fullPathFile;
-        QString m_file;
         QString m_lastErrorString;
         PaletteDocument::DocumentType m_documentType;
 };
--- trunk/extragear/graphics/kcoloredit/src/dialog/palettedialog.cpp #855529:855530
@@ -35,7 +35,8 @@
 //BEGIN public class CollectionGrid
 
 CollectionGrid::CollectionGrid(const QString & collection, QWidget * parent)
-    : KColorCells(parent, 0, 0), m_collection(collection)
+    : KColorCells(parent, 0, 0)
+    , m_collection(collection)
     , m_isEmpty(true)
 {
     setCursor(KCursor("hand2"));
@@ -82,7 +83,7 @@
 // this construct need a lot of explanation .. hehehe i think :P
 CollectionsWidget::CollectionsWidget(QWidget * parent) : QWidget(parent)
 {
-    QString emptyStr = i18n("\n[Empty]");
+    QString emptyStr = '\n' + i18n("[Empty]");
 
     QHBoxLayout * layout = new QHBoxLayout(this);
 
@@ -102,7 +103,7 @@
 
         layout->addLayout(collectionLayout);
 
-        connect(m_collections[i], SIGNAL( collectionClicked(QString) ), this, SLOT( \
chooseCollection(QString) )); +        connect(m_collections[i], SIGNAL( \
collectionClicked(QString) ), SLOT( chooseCollection(QString) ));  }
 }
 
@@ -138,21 +139,21 @@
 
 //BEGIN public class PaletteDialog
 
-QString PaletteDialog::getOpenPaletteName(QWidget * parent)
+KUrl PaletteDialog::getOpenUrl(QWidget * parent)
 {
     PaletteDialog paletteDialog(parent);
 
-    QString fileName;
+    KUrl tmpUrl;
 
     if (paletteDialog.exec() == QDialog::Accepted)
     {
-        fileName = paletteDialog.paletteName();
+        tmpUrl = paletteDialog.paletteUrl();
 
         if (paletteDialog.isKdePalette())
-            fileName = KStandardDirs::locate("config", "colors/"+fileName);
+            tmpUrl = KUrl(KStandardDirs::locate("config", "colors/"+ \
tmpUrl.path()));  }
 
-    return fileName;
+    return tmpUrl;
 }
 
 PaletteDialog::PaletteDialog(QWidget * parent, Qt::WFlags flags) : KDialog(parent, \
flags), m_isKdePalette(false) @@ -185,20 +186,20 @@
 
     setMainWidget(m_mainWidget);
 
-    connect(m_mainWidget, SIGNAL( currentChanged(int)), this, SLOT( \
                updateDialogBtns(int) ));
-    connect(m_collectionsWidget, SIGNAL( selectedCollection(QString) ), this, SLOT( \
                selectKdePaletteName(QString) ));
-    connect(m_fileWidget, SIGNAL( accepted() ), this, SLOT( selectFileName() ));
+    connect(m_mainWidget, SIGNAL( currentChanged(int)), SLOT( updateDialogBtns(int) \
)); +    connect(m_collectionsWidget, SIGNAL( selectedCollection(QString) ), SLOT( \
selectKdePalette(QString) )); +    connect(m_fileWidget, SIGNAL( accepted() ), SLOT( \
selectUrl() ));  connect(this, SIGNAL( okClicked() ), m_fileWidget, SLOT( slotOk() \
                ));
-    connect(this, SIGNAL( okClicked() ), this, SLOT( selectFileName() ));
+    connect(this, SIGNAL( okClicked() ), SLOT( selectUrl() ));
 }
 
 PaletteDialog::~PaletteDialog()
 {
 }
 
-QString PaletteDialog::paletteName() const
+KUrl PaletteDialog::paletteUrl() const
 {
-    return m_paletteName;
+    return m_paletteUrl;
 }
 
 bool PaletteDialog::isKdePalette() const
@@ -225,25 +226,24 @@
     }
 }
 
-void PaletteDialog::selectKdePaletteName(const QString & paletteName)
+void PaletteDialog::selectKdePalette(const QString & kdePalette)
 {
     m_isKdePalette = true;
 
-    m_paletteName = paletteName;
+    m_paletteUrl = KUrl(kdePalette);
 
-        // set the dialog return to acepted and close the dialog
-
+    // Return to acepted and close the dialog
     accept();
 }
 
-void PaletteDialog::selectFileName()
+void PaletteDialog::selectUrl()
 {
     m_isKdePalette = false;
 
-        // fill the filename field of KFileWidget
+    // Fill the filename field of KFileWidget
     m_fileWidget->accept();
 
-    m_paletteName = m_fileWidget->selectedFile();
+    m_paletteUrl = m_fileWidget->selectedUrl();
 
     accept();
 }
--- trunk/extragear/graphics/kcoloredit/src/dialog/palettedialog.h #855529:855530
@@ -63,8 +63,8 @@
         void chooseCollection(const QString & collection);
 
     private:
-        QList< QLabel * > m_headers;
-        QList< CollectionGrid * > m_collections;
+        QList<QLabel *> m_headers;
+        QList<CollectionGrid *> m_collections;
 };
 
 class PaletteDialog : public KDialog
@@ -72,18 +72,18 @@
     Q_OBJECT
 
     public:
-        static QString getOpenPaletteName(QWidget * parent = 0);
+        static KUrl getOpenUrl(QWidget * parent = 0);
 
         explicit PaletteDialog(QWidget * parent = 0, Qt::WFlags flags = 0);
         ~PaletteDialog();
 
-        QString paletteName() const;
+        KUrl paletteUrl() const;
         bool isKdePalette() const;
 
-    public slots:
+    private slots:
         void updateDialogBtns(int tabIndex);
-        void selectKdePaletteName(const QString & paletteName);
-        void selectFileName();
+        void selectKdePalette(const QString & kdePalette);
+        void selectUrl();
 
     private:
         KTabWidget * m_mainWidget;
@@ -91,7 +91,7 @@
         CollectionsWidget * m_collectionsWidget;
         KFileWidget * m_fileWidget;
 
-        QString m_paletteName; // contain the kde palette name or the file name \
selected +        KUrl m_paletteUrl; // Contain the url of the palette file (custom \
                palette or KDE palette)
         bool m_isKdePalette; // tell me if m_paletteName is a kdepalette or a sigle \
file name  };
 
--- trunk/extragear/graphics/kcoloredit/src/widgets/multipagewidget.cpp \
#855529:855530 @@ -147,3 +147,5 @@
         currentWidget->setWindowTitle(newTitle);
     emit pageTitleChanged(newTitle);
 }
+
+#include "multipagewidget.moc"


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic