gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3016 - gnunet-qt/src/plugins/fs


From: durner
Subject: [GNUnet-SVN] r3016 - gnunet-qt/src/plugins/fs
Date: Fri, 16 Jun 2006 10:16:49 -0700 (PDT)

Author: durner
Date: 2006-06-16 10:16:40 -0700 (Fri, 16 Jun 2006)
New Revision: 3016

Added:
   gnunet-qt/src/plugins/fs/fshelper.cc
   gnunet-qt/src/plugins/fs/fshelper.h
   gnunet-qt/src/plugins/fs/searchModel.cc
   gnunet-qt/src/plugins/fs/searchModel.h
Modified:
   gnunet-qt/src/plugins/fs/fs-search.cc
   gnunet-qt/src/plugins/fs/fs-search.h
   gnunet-qt/src/plugins/fs/fs.pro.in
Log:
add column headers to search result trees

Modified: gnunet-qt/src/plugins/fs/fs-search.cc
===================================================================
--- gnunet-qt/src/plugins/fs/fs-search.cc       2006-06-16 17:12:30 UTC (rev 
3015)
+++ gnunet-qt/src/plugins/fs/fs-search.cc       2006-06-16 17:16:40 UTC (rev 
3016)
@@ -24,13 +24,27 @@
  * @author Nils Durner
  */
 
+#include <QHeaderView>
+#include <QMenu>
+#include <extractor.h>
+
+#include "fshelper.h"
 #include "fs-search.h"
 
 GFSSearch::GFSSearch() : QWidget()
 {
+  QHeaderView *header;
+  model = new GFSSearchModel();
+
   setupUi(this);
+
+  treeResults->setModel(model);
+  header = treeResults->header();
+  header->setContextMenuPolicy(Qt::CustomContextMenu);
   
   connect(pbClose, SIGNAL(clicked(bool)), this, SLOT(closeClicked()));
+  connect(header, SIGNAL(customContextMenuRequested(const QPoint &)), this,
+    SLOT(headerRightClicked(const QPoint &)));
 }
 
 void GFSSearch::closeClicked()
@@ -43,4 +57,44 @@
 
 }
 
+void GFSSearch::headerRightClicked(const QPoint &pos)
+{
+  EXTRACTOR_KeywordType typeItem;
+  QAction *item;
+  QList<EXTRACTOR_KeywordType> curCols = model->columns();
+  
+  QMenu *menu = new QMenu(treeResults->header());
+  menu->move(pos);
+  
+  typeItem = EXTRACTOR_getHighestKeywordTypeNumber();
+  while(typeItem >= (EXTRACTOR_KeywordType) 0)
+  {
+    QAction *action;
+    QString strItem = metaTypeName(typeItem);
+    
+    if (strItem != "")
+    {
+      action = menu->addAction(strItem);
+      action->setCheckable(true);
+      action->setData(QVariant((int) typeItem));
+      
+      if (curCols.contains(typeItem))
+        action->setChecked(true);
+    }
+    
+    typeItem = (EXTRACTOR_KeywordType) ((int) typeItem - 1);
+  }
+  
+  item = menu->exec();
+  if (item)
+  {
+    if (item->isChecked())
+      model->addColumn((EXTRACTOR_KeywordType) item->data().toInt());
+    else
+      model->removeColumn((EXTRACTOR_KeywordType) item->data().toInt());
+  }
+  
+  delete menu;
+}
+
 /* fs-search.cc */

Modified: gnunet-qt/src/plugins/fs/fs-search.h
===================================================================
--- gnunet-qt/src/plugins/fs/fs-search.h        2006-06-16 17:12:30 UTC (rev 
3015)
+++ gnunet-qt/src/plugins/fs/fs-search.h        2006-06-16 17:16:40 UTC (rev 
3016)
@@ -27,6 +27,7 @@
 #ifndef SEARCHRESULTS_H_
 #define SEARCHRESULTS_H_
 
+#include "searchModel.h"
 #include "ui_fs-search-result.h"
 
 class GFSSearch : public QWidget, protected Ui::ResultWnd
@@ -36,12 +37,16 @@
 public:
   GFSSearch();
   void clear();
-  
+
 signals:
   void closeSearchWnd(class GFSSearch *wnd);
-  
+
+protected:
+  GFSSearchModel *model;
+
 protected slots:
   void closeClicked();
+  void headerRightClicked(const QPoint &pos);
 };
 
 #endif /*SEARCHRESULTS_H_*/

Modified: gnunet-qt/src/plugins/fs/fs.pro.in
===================================================================
--- gnunet-qt/src/plugins/fs/fs.pro.in  2006-06-16 17:12:30 UTC (rev 3015)
+++ gnunet-qt/src/plugins/fs/fs.pro.in  2006-06-16 17:16:40 UTC (rev 3016)
@@ -2,12 +2,12 @@
 TARGET = libgnunetqtmodule_fs
 INCLUDEPATH = ../../include .
 DLLDESTDIR = .
-LIBS = -L../../common -lgnunetqt_common
+LIBS = -L../../common -lgnunetqt_common -lextractor -lgnunetutil
 QMAKE_LFLAGS += -shared @LDFLAGS@
 QMAKE_LIBS += @LIBS@
 QMAKE_CFLAGS += @CPPFLAGS@
 QMAKE_CXXFLAGS += @CXXFLAGS@
 
-SOURCES = fs.cc fs-search.cc
-HEADERS = fs.h fs-search.h ../../include/gnunet_qt_common.h
+SOURCES = fshelper.cc fs.cc fs-search.cc searchModel.cc
+HEADERS = fshelper.h fs.h fs-search.h searchModel.h 
../../include/gnunet_qt_common.h
 FORMS = fs.ui fs-search-result.ui

Added: gnunet-qt/src/plugins/fs/fshelper.cc
===================================================================
--- gnunet-qt/src/plugins/fs/fshelper.cc        2006-06-16 17:12:30 UTC (rev 
3015)
+++ gnunet-qt/src/plugins/fs/fshelper.cc        2006-06-16 17:16:40 UTC (rev 
3016)
@@ -0,0 +1,51 @@
+/*
+     This file is part of gnunet-qt.
+     (C) 2006 Nils Durner (and other contributing authors)
+
+     gnunet-qt 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, or (at your
+     option) any later version.
+
+     gnunet-qt 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 GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/plugins/fs/fshelper.cc
+ * @brief Helper functions for FS
+ * @author Nils Durner
+ */
+
+#include "fshelper.h"
+
+/**
+ * @brief Get the name of a given keyword/metadata type
+ * @param type the keyword/metadata type
+ * @returns the name
+ */
+QString metaTypeName(EXTRACTOR_KeywordType type)
+{
+    if (type == EXTRACTOR_THUMBNAIL_DATA)
+      return QObject::tr("Preview");
+    else if (type == EXTRACTOR_UNKNOWN)
+      return QObject::tr("Unclassified");
+    else if (type == EXTRACTOR_getHighestKeywordTypeNumber() + 1)
+      return QObject::tr("Metadata");
+    else
+    {
+      GString 
strCol(GString(EXTRACTOR_getKeywordTypeAsString((EXTRACTOR_KeywordType) type)));
+      strCol.proper();
+      
+      return strCol;
+    }  
+}
+
+/* end of fshelper.cc */

Added: gnunet-qt/src/plugins/fs/fshelper.h
===================================================================
--- gnunet-qt/src/plugins/fs/fshelper.h 2006-06-16 17:12:30 UTC (rev 3015)
+++ gnunet-qt/src/plugins/fs/fshelper.h 2006-06-16 17:16:40 UTC (rev 3016)
@@ -0,0 +1,42 @@
+/*
+     This file is part of gnunet-qt.
+     (C) 2006 Nils Durner (and other contributing authors)
+
+     gnunet-qt 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, or (at your
+     option) any later version.
+
+     gnunet-qt 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 GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/plugins/fs/fshelper.h
+ * @brief Helper functions for FS
+ * @author Nils Durner
+ */
+
+#ifndef FSHELPER_H_
+#define FSHELPER_H_
+
+#include <extractor.h>
+#include "gnunet_qt_common.h"
+
+/**
+ * @brief Get the name of a given keyword/metadata type
+ * @param type the keyword/metadata type
+ * @returns the name
+ */
+QString metaTypeName(EXTRACTOR_KeywordType type);
+
+#endif /*FSHELPER_H_*/
+
+/* end of fshelper.h */

Added: gnunet-qt/src/plugins/fs/searchModel.cc
===================================================================
--- gnunet-qt/src/plugins/fs/searchModel.cc     2006-06-16 17:12:30 UTC (rev 
3015)
+++ gnunet-qt/src/plugins/fs/searchModel.cc     2006-06-16 17:16:40 UTC (rev 
3016)
@@ -0,0 +1,123 @@
+/*
+     This file is part of gnunet-qt.
+     (C) 2006 Nils Durner (and other contributing authors)
+
+     gnunet-qt 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, or (at your
+     option) any later version.
+
+     gnunet-qt 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 GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/plugins/fs/searchModel.cc
+ * @brief MVC model for search results
+ * @author Nils Durner
+ */
+
+#include <QStringList>
+#include <extractor.h>
+#include <GNUnet/gnunet_util.h>
+
+#include "gnunet_qt_common.h"
+#include "fshelper.h"
+#include "searchModel.h"
+
+
+QVariant GFSSearchModel::headerData(int section, Qt::Orientation orientation,
+    int role) const
+{
+  if (role == Qt::DisplayRole)
+    return QVariant(metaTypeName((EXTRACTOR_KeywordType) colTypes[section]));
+  else
+    return QVariant();
+}
+
+GFSSearchModel::GFSSearchModel() : QAbstractItemModel()
+{
+  void *columns = NULL;
+  
+  if (stateReadContent("gnunet-qt-fs-search-columns", &columns) != -1)
+  {
+    int count;
+    QStringList lst = QString((char *) columns).split(";");
+    
+    count = lst.count();
+    while(count)
+    {
+      colTypes.append((EXTRACTOR_KeywordType) lst.takeFirst().toInt());
+      
+      count--;
+    }
+
+    FREE(columns);
+  }
+  else
+  {
+    colTypes.append(EXTRACTOR_FILENAME);
+    colTypes.append(EXTRACTOR_SIZE);
+    colTypes.append(EXTRACTOR_MIMETYPE);
+    colTypes.append((EXTRACTOR_KeywordType) 
(EXTRACTOR_getHighestKeywordTypeNumber() + 1));
+    colTypes.append(EXTRACTOR_THUMBNAIL_DATA);
+  }
+}
+
+QModelIndex GFSSearchModel::index(int row, int column,
+  const QModelIndex &parent) const
+{
+  return parent.child(row, column);
+}
+
+QModelIndex GFSSearchModel::parent(const QModelIndex &index) const
+{
+  return QModelIndex();
+}
+
+int GFSSearchModel::rowCount(const QModelIndex &parent) const
+{
+  return 0;
+}
+
+int GFSSearchModel::columnCount(const QModelIndex &parent) const
+{
+  return ((const QList<EXTRACTOR_KeywordType>) colTypes).count();
+}
+
+QVariant GFSSearchModel::data(const QModelIndex &index, int role) const
+{
+  return QVariant();
+}
+
+const QList<EXTRACTOR_KeywordType> &GFSSearchModel::columns()
+{
+  return colTypes;
+}
+
+void GFSSearchModel::addColumn(EXTRACTOR_KeywordType type)
+{
+  int col = columnCount();
+  
+  beginInsertColumns(QModelIndex(), col, col);
+  colTypes.append(type);
+  endInsertColumns();
+}
+
+void GFSSearchModel::removeColumn(EXTRACTOR_KeywordType type)
+{
+  int col = colTypes.indexOf(type);
+  
+  beginRemoveColumns(QModelIndex(), col, col);
+  colTypes.removeAt(col);
+  endRemoveColumns();
+}
+
+/* end of searchModel.cc */

Added: gnunet-qt/src/plugins/fs/searchModel.h
===================================================================
--- gnunet-qt/src/plugins/fs/searchModel.h      2006-06-16 17:12:30 UTC (rev 
3015)
+++ gnunet-qt/src/plugins/fs/searchModel.h      2006-06-16 17:16:40 UTC (rev 
3016)
@@ -0,0 +1,57 @@
+/*
+     This file is part of gnunet-qt.
+     (C) 2006 Nils Durner (and other contributing authors)
+
+     gnunet-qt 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, or (at your
+     option) any later version.
+
+     gnunet-qt 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 GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/plugins/fs/searchModel.h
+ * @brief MVC model for search results
+ * @author Nils Durner
+ */
+
+#ifndef SEARCHMODEL_H_
+#define SEARCHMODEL_H_
+
+#include <QAbstractItemModel>
+#include <QMouseEvent>
+#include <extractor.h>
+
+class GFSSearchModel : public QAbstractItemModel
+{
+  Q_OBJECT
+  
+public:
+  GFSSearchModel();
+  QVariant headerData(int section, Qt::Orientation orientation,
+    int role = Qt::DisplayRole) const;
+  QModelIndex index(int row, int column, const QModelIndex &parent =
+    QModelIndex()) const;
+  QModelIndex parent(const QModelIndex &index) const;
+  int rowCount(const QModelIndex &parent = QModelIndex()) const;
+  int columnCount(const QModelIndex &parent = QModelIndex()) const;
+  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+  const QList<EXTRACTOR_KeywordType> &columns();
+  void addColumn(EXTRACTOR_KeywordType type);
+  void removeColumn(EXTRACTOR_KeywordType type);
+protected:
+  QString columnName(EXTRACTOR_KeywordType type) const;
+
+  QList<EXTRACTOR_KeywordType> colTypes;
+};
+
+#endif /*SEARCHMODEL_H_*/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]