summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Nicoletti <mirttex85-pk@yahoo.com.br>2008-06-11 18:20:22 -0300
committerDaniel Nicoletti <mirttex85-pk@yahoo.com.br>2008-06-11 18:20:22 -0300
commitab3401ba9b953d148a9eefa9542c4c55f20a857b (patch)
tree32a0ffef15dea6a4ed0e7b198f4263e324acdc84
parent09a5a5d1c9b794f44395297ee819587d33b3538f (diff)
add pkg_item.cpp .h
-rw-r--r--gui/ui/Updater/pkg_item.cpp86
-rw-r--r--gui/ui/Updater/pkg_item.h56
2 files changed, 142 insertions, 0 deletions
diff --git a/gui/ui/Updater/pkg_item.cpp b/gui/ui/Updater/pkg_item.cpp
new file mode 100644
index 0000000..95b6111
--- /dev/null
+++ b/gui/ui/Updater/pkg_item.cpp
@@ -0,0 +1,86 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Daniel Nicoletti *
+ * daniel@whitemoon *
+ * *
+ * This program 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 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "pkg_item.h"
+
+#include <QStringList>
+
+PackageItem::PackageItem(Package *pkg, PackageItem *parent)
+ : parentItem(parent), m_pkg(pkg)
+{
+}
+
+PackageItem::PackageItem()
+ : parentItem(0)
+{
+}
+
+QString PackageItem::name()
+{
+ if (parentItem)
+ if ( m_pkg->name().isEmpty() )
+ return QString::number( childCount() ) + " " + m_pkg->info();
+ else
+ return m_pkg->name() + " - " + m_pkg->version() + " (" + m_pkg->arch() + ")";
+ else
+ return QString();
+}
+
+PackageItem::~PackageItem()
+{
+ qDeleteAll(childItems);
+}
+
+void PackageItem::appendChild(PackageItem *item)
+{
+ childItems.append(item);
+}
+
+PackageItem *PackageItem::child(int row)
+{
+ return childItems.value(row);
+}
+
+int PackageItem::childCount() const
+{
+ return childItems.count();
+}
+
+int PackageItem::columnCount() const
+{
+ return 1;
+}
+
+Package *PackageItem::data() const
+{
+ return m_pkg;
+}
+
+PackageItem *PackageItem::parent()
+{
+ return parentItem;
+}
+
+int PackageItem::row() const
+{
+ if (parentItem)
+ return parentItem->childItems.indexOf(const_cast<PackageItem*>(this));
+
+ return 0;
+}
diff --git a/gui/ui/Updater/pkg_item.h b/gui/ui/Updater/pkg_item.h
new file mode 100644
index 0000000..187d59f
--- /dev/null
+++ b/gui/ui/Updater/pkg_item.h
@@ -0,0 +1,56 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Daniel Nicoletti *
+ * daniel@whitemoon *
+ * *
+ * This program 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 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef PACKAGE_ITEM_H
+#define PACKAGE_ITEM_H
+
+#include "../../../lib/QPackageKit.h"
+
+#include <QList>
+#include <QVariant>
+
+using namespace PackageKit;
+
+/**
+ @author Daniel Nicoletti <daniel@whitemoon>
+*/
+class PackageItem{
+public:
+ PackageItem(Package *pkg, PackageItem *parent = 0);
+ PackageItem();
+
+ ~PackageItem();
+
+ void appendChild(PackageItem *child);
+
+ PackageItem *child(int row);
+ int childCount() const;
+ int columnCount() const;
+ Package *data() const;
+ int row() const;
+ PackageItem *parent();
+ QString name();
+
+private:
+ QList<PackageItem*> childItems;
+ Package *m_pkg;
+ PackageItem *parentItem;
+};
+
+#endif