Added new data object class FilePathObject and updated
authorMikko Keinänen <mikko.keinanen@gmail.com>
Mon, 24 May 2010 21:02:05 +0000 (00:02 +0300)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Mon, 24 May 2010 21:02:05 +0000 (00:02 +0300)
EmuFrontFileObject. Also added database creation for this data object
type.

src/dataobjects/emufrontfileobject.cpp
src/dataobjects/emufrontfileobject.h
src/dataobjects/filepathobject.cpp [new file with mode: 0644]
src/dataobjects/filepathobject.h [new file with mode: 0644]
src/db/dbcreator.cpp
src/emufront.pro

index a8f5176..be7b46b 100644 (file)
@@ -23,9 +23,14 @@ EmuFrontFileObject::EmuFrontFileObject() : EmuFrontObject()
 { }
 
 EmuFrontFileObject::EmuFrontFileObject(int id, QString name, QString filename)
-    : EmuFrontObject(id, name), filename(filename)
+    : EmuFrontObject(id, name), filename(filename), filetype(0)
 {}
 
+EmuFrontFileObject::EmuFrontFileObject(int id, QString name, QString filename, int filetype)
+    : EmuFrontObject(id, name), filename(filename), filetype(filetype)
+{}
+
+
 /*EmuFrontFileObject::EmuFrontFileObject(const EmuFrontFileObject&pl)
     : EmuFrontObject(pl.id, pl.name), filename(pl.filename)
 {
index 1dc9055..4293d2f 100644 (file)
@@ -27,17 +27,32 @@ class EmuFrontFileObject : public EmuFrontObject
 public:
     EmuFrontFileObject();
     EmuFrontFileObject( int id, QString name, QString filename);
+    EmuFrontFileObject( int id, QString name, QString filename, int filetype);
+
     // No need for these as long we use QString (see Implicit Data Sharing)
     /*EmuFrontFileObject(const EmuFrontFileObject&);
     EmuFrontFileObject &operator=(const EmuFrontFileObject&);
     virtual ~EmuFrontFileObject();*/
+
     const QString getFilename() const
     { return filename; }
     void setFilename(QString filename)
     { this->filename = filename; }
+    int getFiletype() const
+    { return filetype; }
+    void setFiletype(int t)
+    { filetype = t; }
+
+    enum {
+        FileType_MediaImageContainer = 1,
+        FileType_ScreenShot = 2,
+        FileType_PlatformIconPath = 3,
+        FileType_MediaTypeIconPath = 4
+    };
 
-private:
+protected:
     QString filename;
+    int filetype;
 };
 
 #endif // EMUFRONTFILEOBJECT_H
diff --git a/src/dataobjects/filepathobject.cpp b/src/dataobjects/filepathobject.cpp
new file mode 100644 (file)
index 0000000..5d088e6
--- /dev/null
@@ -0,0 +1,47 @@
+#include "filepathobject.h"
+
+FilePathObject::FilePathObject()
+{
+}
+
+FilePathObject::FilePathObject(int id, QString name, QString filename, int filetype)
+    : EmuFrontFileObject(id, name, filename, filetype), platform(0), mediaType(0)
+ {}
+
+ FilePathObject::FilePathObject(int id, QString name, QString filename,
+     int filetype, Platform *plf, MediaType *med)
+    : EmuFrontFileObject(id, name, filename, filetype), platform(plf), mediaType(med)
+ {}
+
+FilePathObject::~FilePathObject()
+{
+    if (platform) delete platform;
+    if (mediaType) delete mediaType;
+}
+
+FilePathObject::FilePathObject(const FilePathObject &fpobj)
+    : EmuFrontFileObject(fpobj.id, fpobj.name, fpobj.filename, fpobj.filetype)
+{
+    // Note: no need to deep copy members of type QString
+    // QString uses Implicit Data Sharing (http://doc.trolltech.com/4.0/shclass.html)
+    Platform *p = fpobj.platform;
+    platform = new Platform(p->getId(), p->getName(), p->getFilename());
+    MediaType *mt = fpobj.mediaType;
+    mediaType = new MediaType(mt->getId(), mt->getName(), mt->getFilename());
+}
+
+FilePathObject& FilePathObject::operator =(const FilePathObject &fpobj)
+{
+    if (this == &fpobj) return *this;
+    id = fpobj.id;
+    name = fpobj.name;
+    filename = fpobj.filename;
+    filetype = fpobj.filetype;
+    if (platform) delete platform;
+    Platform *p = fpobj.platform;
+    platform = new Platform(p->getId(), p->getName(), p->getFilename());
+    if (mediaType) delete mediaType;
+    MediaType *mt = fpobj.mediaType;
+    mediaType = new MediaType(mt->getId(), mt->getName(), mt->getFilename());
+    return (*this);
+}
diff --git a/src/dataobjects/filepathobject.h b/src/dataobjects/filepathobject.h
new file mode 100644 (file)
index 0000000..a1cf24a
--- /dev/null
@@ -0,0 +1,52 @@
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Foobar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef FILEPATHOBJECT_H
+#define FILEPATHOBJECT_H
+
+#include "emufrontfileobject.h"
+#include "platform.h"
+#include "mediatype.h"
+
+class FilePathObject : public EmuFrontFileObject
+{
+public:
+    FilePathObject();
+    ~FilePathObject();
+    FilePathObject(int id, QString name, QString filename, int filetype);
+    FilePathObject(int id, QString name, QString filename, int filetype, Platform*, MediaType*);
+    FilePathObject(const FilePathObject &);
+    FilePathObject& operator=(const FilePathObject &);
+
+    Platform* getPlatform() const
+    { return platform; }
+    MediaType* getMediaType() const
+    { return mediaType; }
+    void setPlatform(Platform *plf)
+    { platform = plf; }
+    void setMediaType(MediaType *med)
+    { mediaType = med; }
+
+private:
+    Platform *platform;
+    MediaType *mediaType;
+
+};
+
+#endif // FILEPATHOBJECT_H
index b3e4295..f3ec981 100644 (file)
@@ -41,45 +41,49 @@ bool DbCreator::createDB()
 
     try
     {
-        if (!tableExists("platform"))
-        {
+        /*if (!tableExists("platform"))
+        {*/
             qDebug() << "Creating table platform";
-            ret = query.exec("create table platform "
+            ret = query.exec("create table if not exists platform "
                              "(id integer primary key, "
                              "name varchar(30), "
                              "filename varchar(125))");
             if (!ret) throw QString("platform.");
-        }
+        /*}
         if (!tableExists("mediatype"))
-        {
-            qDebug() << "Creating table mediatype";
-            ret = query.exec("create table mediatype "
+        {*/
+            qDebug() << "Creating table mediatype ";
+            ret = query.exec("create table if not exists mediatype "
                              "(id integer primary key, "
                              "name varchar(30), "
                              "filename varchar(125))");
             if (!ret) throw QString("mediatype.");
-        }
+        /*}
         if (!tableExists("filetype"))
-        {
-            qDebug() << "Creating table filetype";
-            ret = query.exec("create table filetype "
+        {*/
+            /*qDebug() << "Creating table filetype";
+            ret = query.exec("create table filetype if not exists"
                              "(id integer primary key, "
                              "name varchar(30))");
             if (!ret) throw QString("filetype.");
             query.exec("insert into filetype (id, name) values (1, 'media image container')");
             query.exec("insert into filetype (id, name) values (2, 'screenshot')");
             query.exec("insert into filetype (id, name) values (3, 'platform icon')");
-            query.exec("insert into filetype (id, name) values (4, 'media type icon')");
-        }
-        /*if (!tableExists("filepath"))
-    {
-        qDebug() << "Creating table filepath";
-        query.exec("create table filepath "
-                    "(id integer primary key, "
-                    "name varchar(255))");
+            query.exec("insert into filetype (id, name) values (4, 'media type icon')");*/
+        /*}
+        if (!tableExists("filepath"))
+        {*/
+            qDebug() << "Creating table filepath";
+            query.exec("create table filepath "
+                       "(id integer primary key, "
+                       "name text, "
+                       "filetypeid integer, "
+                       "platformid integer, "
+                       "mediatypeid integer, "
+                       "lastscanned numeric)");
 
-        if (!ret) throw QString("filepath");
-    }*/
+            if (!ret) throw QString("filepath");
+        //}
     }
     catch (QString tbl)
     {
index 23af652..0437342 100644 (file)
@@ -27,7 +27,8 @@ HEADERS += mainwindow.h \
     dataobjects/emufrontfileobject.h \
     dataobjects/mediatype.h \
     db/dbmediatype.h \
-    dialogs/mediatypenamedialog.h
+    dialogs/mediatypenamedialog.h \
+    dataobjects/filepathobject.h
 SOURCES += main.cpp \
     mainwindow.cpp \
     db/databasemanager.cpp \
@@ -44,4 +45,5 @@ SOURCES += main.cpp \
     dataobjects/emufrontfileobject.cpp \
     dataobjects/mediatype.cpp \
     db/dbmediatype.cpp \
-    dialogs/mediatypenamedialog.cpp
+    dialogs/mediatypenamedialog.cpp \
+    dataobjects/filepathobject.cpp