[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3082 - gnunet-qt/src/plugins/fs
From: |
durner |
Subject: |
[GNUnet-SVN] r3082 - gnunet-qt/src/plugins/fs |
Date: |
Sat, 1 Jul 2006 03:33:27 -0700 (PDT) |
Author: durner
Date: 2006-07-01 03:33:10 -0700 (Sat, 01 Jul 2006)
New Revision: 3082
Added:
gnunet-qt/src/plugins/fs/ecrsuri.cc
gnunet-qt/src/plugins/fs/ecrsuri.h
Modified:
gnunet-qt/src/plugins/fs/fs-search.cc
gnunet-qt/src/plugins/fs/fs-search.h
gnunet-qt/src/plugins/fs/fs.cc
gnunet-qt/src/plugins/fs/fs.h
gnunet-qt/src/plugins/fs/fs.pro.in
gnunet-qt/src/plugins/fs/fs.ui
gnunet-qt/src/plugins/fs/searchModel.cc
gnunet-qt/src/plugins/fs/searchModel.h
gnunet-qt/src/plugins/fs/searchesModel.cc
gnunet-qt/src/plugins/fs/searchesModel.h
Log:
basic FS searches
Added: gnunet-qt/src/plugins/fs/ecrsuri.cc
===================================================================
--- gnunet-qt/src/plugins/fs/ecrsuri.cc 2006-07-01 10:32:03 UTC (rev 3081)
+++ gnunet-qt/src/plugins/fs/ecrsuri.cc 2006-07-01 10:33:10 UTC (rev 3082)
@@ -0,0 +1,104 @@
+/*
+ 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/ecrsuri.h
+ * @brief Wrapper for ECRS_URI
+ * @author Nils Durner
+ */
+
+#include "ecrsuri.h"
+#include "gnunet_qt_common.h"
+
+GFSEcrsUri::GFSEcrsUri()
+{
+ ecrsUri = NULL;
+}
+
+GFSEcrsUri::GFSEcrsUri(const GFSEcrsUri &src)
+{
+ ecrsUri = ECRS_dupUri(src.ecrsUri);
+}
+
+GFSEcrsUri::~GFSEcrsUri()
+{
+ if (ecrsUri)
+ ECRS_freeUri(ecrsUri);
+}
+
+const ECRS_URI *GFSEcrsUri::uri()
+{
+ return ecrsUri;
+}
+
+bool GFSEcrsUri::operator==(const GFSEcrsUri &rvalue)
+{
+ return ecrsUri && rvalue.ecrsUri && ECRS_equalsUri(ecrsUri, rvalue.ecrsUri);
+}
+
+GFSEcrsUri &GFSEcrsUri::operator=(const GFSEcrsUri &src)
+{
+ if (ecrsUri)
+ ECRS_freeUri(ecrsUri);
+
+ ecrsUri = ECRS_dupUri(src.ecrsUri);
+
+ return *this;
+}
+
+QString GFSEcrsUri::toString()
+{
+ char *dhead, *desc;
+ QString strRet;
+
+ if (!ecrsUri)
+ return QString();
+
+ desc = ECRS_uriToString(ecrsUri);
+ if (!desc)
+ return QString();
+
+ GNUNETQT_ASSERT(strlen(desc) >= strlen(ECRS_URI_PREFIX));
+
+ dhead = desc + strlen(ECRS_URI_PREFIX);
+ if (strncmp(dhead, ECRS_SEARCH_INFIX, strlen(ECRS_SEARCH_INFIX)) == 0)
+ strRet = dhead + strlen(ECRS_SEARCH_INFIX);
+ else if (strncmp(dhead, ECRS_SUBSPACE_INFIX, strlen(ECRS_SUBSPACE_INFIX) ==
0))
+ strRet = dhead + strlen(ECRS_SUBSPACE_INFIX);
+
+ FREE(desc);
+
+ return strRet;
+}
+
+GFSEcrsUri::GFSEcrsUri(const ECRS_URI *uri)
+{
+ ecrsUri = ECRS_dupUri(uri);
+}
+
+GFSEcrsUri &GFSEcrsUri::operator=(const ECRS_URI *uri)
+{
+ if (ecrsUri)
+ ECRS_freeUri(ecrsUri);
+
+ ecrsUri = ECRS_dupUri(uri);
+}
+
+/* end of ecrsuri.cc */
Added: gnunet-qt/src/plugins/fs/ecrsuri.h
===================================================================
--- gnunet-qt/src/plugins/fs/ecrsuri.h 2006-07-01 10:32:03 UTC (rev 3081)
+++ gnunet-qt/src/plugins/fs/ecrsuri.h 2006-07-01 10:33:10 UTC (rev 3082)
@@ -0,0 +1,53 @@
+/*
+ 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/ecrsuri.h
+ * @brief Wrapper for ECRS_URI
+ * @author Nils Durner
+ */
+
+#ifndef ECRSURI_H_
+#define ECRSURI_H_
+
+#include <QString>
+#include <GNUnet/gnunet_ecrs_lib.h>
+
+class GFSEcrsUri
+{
+public:
+ GFSEcrsUri();
+ GFSEcrsUri(const ECRS_URI *uri);
+ GFSEcrsUri(const GFSEcrsUri &src);
+ ~GFSEcrsUri();
+
+ const ECRS_URI *uri();
+ QString toString();
+
+ bool operator==(const GFSEcrsUri &rvalue);
+ GFSEcrsUri &operator=(const GFSEcrsUri &src);
+ GFSEcrsUri &operator=(const ECRS_URI *src);
+protected:
+ ECRS_URI *ecrsUri;
+};
+
+#endif /*ECRSURI_H_*/
+
+/* end of ecrsuri.h */
Modified: gnunet-qt/src/plugins/fs/fs-search.cc
===================================================================
--- gnunet-qt/src/plugins/fs/fs-search.cc 2006-07-01 10:32:03 UTC (rev
3081)
+++ gnunet-qt/src/plugins/fs/fs-search.cc 2006-07-01 10:33:10 UTC (rev
3082)
@@ -31,10 +31,10 @@
#include "fshelper.h"
#include "fs-search.h"
-GFSSearch::GFSSearch(QTabWidget *tab) : QWidget()
+GFSSearch::GFSSearch(QTabWidget *tab, struct FSUI_Context *fsuiContext) :
QWidget()
{
QHeaderView *header;
- model = new GFSSearchModel();
+ model = new GFSSearchModel(fsuiContext);
setupUi(this);
@@ -42,12 +42,13 @@
header = treeResults->header();
header->setContextMenuPolicy(Qt::CustomContextMenu);
this->tab = tab;
+ this->fsuiContext = fsuiContext;
connect(pbClose, SIGNAL(clicked(bool)), this, SLOT(closeClicked()));
connect(header, SIGNAL(customContextMenuRequested(const QPoint &)), this,
SLOT(headerRightClicked(const QPoint &)));
- connect(model, SIGNAL(resultsChanged(QString &, int)), this,
- SLOT(resultsChanged(QString &, int)));
+ connect(model, SIGNAL(resultsChanged(GFSEcrsUri &, int)), this,
+ SLOT(resultsChanged(GFSEcrsUri &, int)));
}
void GFSSearch::closeClicked()
@@ -100,17 +101,17 @@
delete menu;
}
-void GFSSearch::resultsChanged(QString &strSearch, int searchResults)
+void GFSSearch::resultsChanged(GFSEcrsUri &uri, int searchResults)
{
tab->setTabText(tab->indexOf(this),
strSearch + " (" + QString::number(searchResults) + ")");
- emit searchChanged(strSearch, searchResults);
+ emit searchChanged(uri, searchResults);
}
-void GFSSearch::start(QString &strSearch, QString &strNS, int anonymity)
+void GFSSearch::start(GFSEcrsUri &uri, int anonymity)
{
- this->strSearch = strSearch;
- model->startSearch(strSearch, strNS, anonymity);
+ strSearch = uri.toString();
+ model->startSearch(uri, anonymity);
}
QString &GFSSearch::searchText()
Modified: gnunet-qt/src/plugins/fs/fs-search.h
===================================================================
--- gnunet-qt/src/plugins/fs/fs-search.h 2006-07-01 10:32:03 UTC (rev
3081)
+++ gnunet-qt/src/plugins/fs/fs-search.h 2006-07-01 10:33:10 UTC (rev
3082)
@@ -28,6 +28,7 @@
#define SEARCHRESULTS_H_
#include <QTabWidget>
+#include <GNUnet/gnunet_fsui_lib.h>
#include "searchModel.h"
#include "ui_fs-search-result.h"
@@ -37,23 +38,24 @@
Q_OBJECT
public:
- GFSSearch(QTabWidget *tab);
+ GFSSearch(QTabWidget *tab, struct FSUI_Context *fsuiContext);
QString &searchText();
void clear();
- void start(QString &strSearch, QString &strNS, int anonymity);
+ void start(GFSEcrsUri &uri, int anonymity);
signals:
void closeSearchWnd(class GFSSearch *wnd);
- void searchChanged(QString &strSearch, int searchResults);
+ void searchChanged(GFSEcrsUri &uri, int searchResults);
protected:
GFSSearchModel *model;
QTabWidget *tab;
QString strSearch;
+ struct FSUI_Context *fsuiContext;
protected slots:
void closeClicked();
void headerRightClicked(const QPoint &pos);
- void resultsChanged(QString &strSearch, int searchResults);
+ void resultsChanged(GFSEcrsUri &uri, int searchResults);
};
#endif /*SEARCHRESULTS_H_*/
Modified: gnunet-qt/src/plugins/fs/fs.cc
===================================================================
--- gnunet-qt/src/plugins/fs/fs.cc 2006-07-01 10:32:03 UTC (rev 3081)
+++ gnunet-qt/src/plugins/fs/fs.cc 2006-07-01 10:33:10 UTC (rev 3082)
@@ -26,14 +26,38 @@
#include <QLineEdit>
#include <QMessageBox>
+#include <GNUnet/gnunet_fsui_lib.h>
#include "fs.h"
#include "fs-search.h"
+#include "ecrsuri.h"
+static void *fsuiEventProcessor(void *cls, const FSUI_Event *event, void
*model)
+{
+ switch (event->type)
+ {
+ case FSUI_search_result:
+ ((GFSSearchModel *) model)->addResult(event->data.SearchResult.searchURI,
+ &event->data.SearchResult.fi);
+ break;
+ default:
+ BREAK();
+ /* FIXME: display/log error */
+ break;
+ }
+
+ return NULL;
+}
+
GFSPlugin::GFSPlugin() : GPlugin()
{
setupUi(this);
+ qRegisterMetaType<GFSEcrsUri>("GFSEcrsUri&");
+
+ // FSUI
+ fsuiContext = FSUI_start("gnunet_qt", YES, fsuiEventProcessor, NULL);
+
// Status tab
treeSearches->setModel(&searchesModel);
treeDownloads->setModel(&downloadsModel);
@@ -44,19 +68,24 @@
connect(cmbSearchFor->lineEdit(), SIGNAL(returnPressed()), this,
SLOT(searchClicked()));
tabResults->removeTab(0); // created by Qt Designer
- (addSearchWnd(tr("Search results")))->setEnabled(false);
+ (addSearchWnd(tr("Search results")))->setEnabled(false);
}
+GFSPlugin::~GFSPlugin()
+{
+ FSUI_stop(fsuiContext);
+}
+
GFSSearch *GFSPlugin::addSearchWnd(QString strLabel)
{
GFSSearch *ret;
- ret = new GFSSearch(tabResults);
+ ret = new GFSSearch(tabResults, fsuiContext);
connect(ret, SIGNAL(closeSearchWnd(GFSSearch *)), this,
SLOT(closeSearchClicked(GFSSearch *)));
- connect(ret, SIGNAL(searchChanged(QString &, int)),
- &searchesModel, SLOT(searchChanged(QString &, int)));
+ connect(ret, SIGNAL(searchChanged(GFSEcrsUri &, int)),
+ &searchesModel, SLOT(searchChanged(GFSEcrsUri &, int)));
ret->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tabResults->addTab(ret, strLabel);
@@ -68,7 +97,9 @@
GFSSearch *searchWnd;
int tab;
QString strSearch, strNS;
-
+ ECRS_URI *uri;
+ GFSEcrsUri ecrsUri;
+
strSearch = cmbSearchFor->lineEdit()->text();
if (strSearch == "")
{
@@ -99,8 +130,33 @@
}
tabResults->setCurrentIndex(tab);
- searchWnd->start(strSearch, strNS, spinAnon->value());
+
+ /* Create URI */
+ if (strNS.length())
+ {
+ QString strUri;
+ char *ustring;
+
+ strUri = QString(ECRS_URI_PREFIX) + ECRS_SUBSPACE_INFIX + strNS + "/" +
+ strSearch;
+ ustring = strUri.toLocal8Bit().data();
+ uri = ECRS_stringToUri(ustring);
+ if (!uri)
+ LOG(LOG_ERROR,
+ tr("Failed to create namespace URI from `%s'.\n").toLocal8Bit().data(),
+ ustring);
+ }
+ else
+ uri = FSUI_parseCharKeywordURI(strSearch.toLocal8Bit().data());
+ if (uri == NULL)
+ return;
+
+ /* Start search */
+ ecrsUri = uri;
+ searchWnd->start(ecrsUri, spinAnon->value());
+ ECRS_freeUri(uri);
+
tabResults->setUpdatesEnabled(true);
}
Modified: gnunet-qt/src/plugins/fs/fs.h
===================================================================
--- gnunet-qt/src/plugins/fs/fs.h 2006-07-01 10:32:03 UTC (rev 3081)
+++ gnunet-qt/src/plugins/fs/fs.h 2006-07-01 10:33:10 UTC (rev 3082)
@@ -40,10 +40,12 @@
public:
GFSPlugin();
+ ~GFSPlugin();
protected:
GFSSearchesModel searchesModel;
GFSDownloadsModel downloadsModel;
GFSUploadsModel uploadsModel;
+ struct FSUI_Context *fsuiContext;
GFSSearch *addSearchWnd(QString strLabel);
protected slots:
Modified: gnunet-qt/src/plugins/fs/fs.pro.in
===================================================================
--- gnunet-qt/src/plugins/fs/fs.pro.in 2006-07-01 10:32:03 UTC (rev 3081)
+++ gnunet-qt/src/plugins/fs/fs.pro.in 2006-07-01 10:33:10 UTC (rev 3082)
@@ -2,20 +2,22 @@
TARGET = @address@hidden
INCLUDEPATH = ../../include .
DLLDESTDIR = .
-LIBS = -L../../common -lgnunetqt_common -lextractor -lgnunetutil
+LIBS = -L../../common -lgnunetqt_common -lextractor -lgnunetutil -lgnunetecrs
-lgnunetfsui
QMAKE_LFLAGS += -shared @LDFLAGS@
QMAKE_LIBS += @LIBS@
QMAKE_CFLAGS += @CPPFLAGS@
QMAKE_CXXFLAGS += @CXXFLAGS@
-SOURCES = fshelper.cc \
+SOURCES = ecrsuri.cc \
+ fshelper.cc \
fs.cc \
fs-search.cc \
searchesModel.cc \
downloadsModel.cc \
uploadsModel.cc \
searchModel.cc
-HEADERS = fshelper.h \
+HEADERS = ecrsuri.h \
+ fshelper.h \
fs.h \
fs-search.h \
searchesModel.h \
Modified: gnunet-qt/src/plugins/fs/fs.ui
===================================================================
--- gnunet-qt/src/plugins/fs/fs.ui 2006-07-01 10:32:03 UTC (rev 3081)
+++ gnunet-qt/src/plugins/fs/fs.ui 2006-07-01 10:33:10 UTC (rev 3082)
@@ -37,7 +37,7 @@
<attribute name="icon" >
<iconset resource="..\..\..\pixmaps\pixmaps.qrc"
>:/pixmaps/info.png</iconset>
</attribute>
- <layout class="QHBoxLayout" >
+ <layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
@@ -45,66 +45,48 @@
<number>6</number>
</property>
<item>
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>0</number>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
</property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <widget class="QGroupBox" name="groupBox_2" >
- <property name="title" >
- <string>Active searches</string>
+ <widget class="QGroupBox" name="groupBox_2" >
+ <property name="title" >
+ <string>Active searches</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
</property>
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <widget class="QTreeView" name="treeSearches" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>4</hsizetype>
- <vsizetype>7</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="maximumSize" >
- <size>
- <width>200</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="alternatingRowColors" >
- <bool>true</bool>
- </property>
- <property name="selectionMode" >
- <enum>QAbstractItemView::NoSelection</enum>
- </property>
- <property name="rootIsDecorated" >
- <bool>false</bool>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QTreeView" name="treeSearches" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>7</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alternatingRowColors" >
+ <bool>true</bool>
+ </property>
+ <property name="selectionMode" >
+ <enum>QAbstractItemView::NoSelection</enum>
+ </property>
+ <property name="rootIsDecorated" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
<widget class="QGroupBox" name="groupBox_3" >
<property name="title" >
<string>Active downloads</string>
@@ -192,8 +174,6 @@
</item>
</layout>
</widget>
- </item>
- <item>
<widget class="QGroupBox" name="groupBox_4" >
<property name="title" >
<string>Active uploads</string>
@@ -259,8 +239,8 @@
</item>
</layout>
</widget>
- </item>
- </layout>
+ </widget>
+ </widget>
</item>
</layout>
</widget>
Modified: gnunet-qt/src/plugins/fs/searchModel.cc
===================================================================
--- gnunet-qt/src/plugins/fs/searchModel.cc 2006-07-01 10:32:03 UTC (rev
3081)
+++ gnunet-qt/src/plugins/fs/searchModel.cc 2006-07-01 10:33:10 UTC (rev
3082)
@@ -24,15 +24,19 @@
* @author Nils Durner
*/
+#include <QMessageBox>
#include <QStringList>
#include <extractor.h>
#include <GNUnet/gnunet_util.h>
+#include <GNUnet/gnunet_fsui_lib.h>
#include "gnunet_qt_common.h"
#include "fshelper.h"
#include "searchModel.h"
+
+
QVariant GFSSearchModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
@@ -42,9 +46,11 @@
return QVariant();
}
-GFSSearchModel::GFSSearchModel() : QAbstractItemModel()
+GFSSearchModel::GFSSearchModel(struct FSUI_Context *context) :
QAbstractItemModel()
{
void *columns = NULL;
+
+ qRegisterMetaType<QModelIndex>("QModelIndex");
if (stateReadContent("gnunet-qt-fs-search-columns", &columns) != -1)
{
@@ -69,12 +75,14 @@
colTypes.append((EXTRACTOR_KeywordType)
(EXTRACTOR_getHighestKeywordTypeNumber() + 1));
colTypes.append(EXTRACTOR_THUMBNAIL_DATA);
}
+
+ fsuiContext = context;
}
QModelIndex GFSSearchModel::index(int row, int column,
const QModelIndex &parent) const
{
- return parent.child(row, column);
+ return createIndex(row, column);
}
QModelIndex GFSSearchModel::parent(const QModelIndex &index) const
@@ -84,7 +92,10 @@
int GFSSearchModel::rowCount(const QModelIndex &parent) const
{
- return 0;
+ if (parent.row() == -1 && parent.column() == -1)
+ return searchResults.count();
+ else
+ return 0;
}
int GFSSearchModel::columnCount(const QModelIndex &parent) const
@@ -94,6 +105,43 @@
QVariant GFSSearchModel::data(const QModelIndex &index, int role) const
{
+ int row, col;
+
+ row = index.row();
+ col = index.column();
+
+ if (row > rowCount() - 1 || col > columnCount() - 1)
+ return QVariant();
+
+ if (role == Qt::DisplayRole)
+ {
+ EXTRACTOR_KeywordType type;
+ GFSSearchResult result;
+ QList<QByteArray> metaData;
+ QList<QByteArray>::iterator iter;
+ QString strMetaData;
+ bool first = true;
+
+ type = (EXTRACTOR_KeywordType) colTypes[index.column()];
+ if (type == EXTRACTOR_THUMBNAIL_DATA)
+ return QVariant(); // FIXME
+
+ result = searchResults[row];
+ metaData = result.metaData.values(type);
+
+ for(iter = metaData.begin(); iter != metaData.end(); iter++)
+ {
+ if (!first)
+ strMetaData += "\n";
+ else
+ first = false;
+
+ strMetaData += QString((*iter).data());
+ }
+
+ return QVariant(strMetaData);
+ }
+
return QVariant();
}
@@ -120,9 +168,47 @@
endRemoveColumns();
}
-void GFSSearchModel::startSearch(QString &strSearch, QString &strNS, int
anonymity)
+void GFSSearchModel::startSearch(GFSEcrsUri &uri, int anonymity)
{
- emit resultsChanged(strSearch, 0);
+ emit resultsChanged(uri, 0);
+
+ FSUI_startSearch(fsuiContext, anonymity, uri.uri(), this);
}
+static int fsMetaDataIterator(EXTRACTOR_KeywordType type, const char *data,
+ void *closure)
+{
+ ((GFSMetaData *) closure)->insert(type, QByteArray(data));
+
+ return OK;
+}
+
+void GFSSearchModel::addResult(const ECRS_URI *searchUri, const ECRS_FileInfo
*fileInfo)
+{
+ GFSSearchResult searchResult;
+ unsigned char *thumb;
+ unsigned int len;
+ GFSEcrsUri uri(searchUri);
+ int rowCount;
+
+ searchResult.uri = GFSEcrsUri(fileInfo->uri);
+ ECRS_getMetaData(fileInfo->meta, fsMetaDataIterator,
+ (void *) &searchResult.metaData);
+
+ len = ECRS_getThumbnailFromMetaData(fileInfo->meta, &thumb);
+ if (len)
+ {
+ searchResult.metaData.insert(EXTRACTOR_THUMBNAIL_DATA,
+ QByteArray((const char *) thumb, len));
+ FREE(thumb);
+ }
+
+ rowCount = searchResults.count();
+ beginInsertRows(index(-1, -1), rowCount, rowCount);
+ searchResults.append(searchResult);
+ endInsertRows();
+
+ emit resultsChanged(uri, (int) searchResults.count());
+}
+
/* end of searchModel.cc */
Modified: gnunet-qt/src/plugins/fs/searchModel.h
===================================================================
--- gnunet-qt/src/plugins/fs/searchModel.h 2006-07-01 10:32:03 UTC (rev
3081)
+++ gnunet-qt/src/plugins/fs/searchModel.h 2006-07-01 10:33:10 UTC (rev
3082)
@@ -29,14 +29,28 @@
#include <QAbstractItemModel>
#include <QMouseEvent>
+#include <QByteArray>
+#include <QMultiHash>
+#include <QList>
#include <extractor.h>
+#include "ecrsUri.h"
+
+typedef QMultiHash<EXTRACTOR_KeywordType, QByteArray> GFSMetaData;
+
+class GFSSearchResult
+{
+public:
+ GFSEcrsUri uri;
+ GFSMetaData metaData;
+};
+
class GFSSearchModel : public QAbstractItemModel
{
Q_OBJECT
public:
- GFSSearchModel();
+ GFSSearchModel(struct FSUI_Context *context);
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent =
@@ -48,14 +62,18 @@
const QList<EXTRACTOR_KeywordType> &columns();
void addColumn(EXTRACTOR_KeywordType type);
void removeColumn(EXTRACTOR_KeywordType type);
+ void addResult(const ECRS_URI *searchUri, const ECRS_FileInfo *fileInfo);
- void startSearch(QString &strSearch, QString &strNS, int anonymity);
+ void startSearch(GFSEcrsUri &uri, int anonymity);
signals:
- void resultsChanged(QString &strSearch, int searchResults);
+ void resultsChanged(GFSEcrsUri &uri, int searchResults);
protected:
+ struct FSUI_Context *fsuiContext;
+
QString columnName(EXTRACTOR_KeywordType type) const;
QList<EXTRACTOR_KeywordType> colTypes;
+ QList<GFSSearchResult> searchResults;
};
#endif /*SEARCHMODEL_H_*/
Modified: gnunet-qt/src/plugins/fs/searchesModel.cc
===================================================================
--- gnunet-qt/src/plugins/fs/searchesModel.cc 2006-07-01 10:32:03 UTC (rev
3081)
+++ gnunet-qt/src/plugins/fs/searchesModel.cc 2006-07-01 10:33:10 UTC (rev
3082)
@@ -87,29 +87,35 @@
return QVariant();
}
-void GFSSearchesModel::searchChanged(QString &strSearch, int searchResults)
+void GFSSearchesModel::searchChanged(GFSEcrsUri &uri, int searchResults)
{
int idx = 0;
GFSSearchResultList::iterator it = results.begin();
+
while(it != results.end())
{
- if (it->strSearch == strSearch)
+ if (it->uri == uri)
{
it->count = searchResults;
dataChanged(index(idx, 0), index(idx, 0));
+ break;
}
it++;
idx++;
}
+ /* Search not in model yet */
if (it == results.end())
{
GFSSearchResultCount result;
beginInsertRows(index(-1, -1), idx, idx);
- result.strSearch = strSearch;
+ result.strSearch = uri.toString();
+ result.uri = uri;
result.count = searchResults;
+
+ /* Add to model */
results.append(result);
endInsertRows();
}
@@ -133,4 +139,15 @@
}
}
+GFSSearchesModel::GFSSearchResultCount::GFSSearchResultCount()
+{
+}
+
+GFSSearchesModel::GFSSearchResultCount::GFSSearchResultCount(const
GFSSearchesModel::GFSSearchResultCount &src)
+{
+ strSearch = src.strSearch;
+ uri = src.uri;
+ count = src.count;
+}
+
/* end of searchesModel.cc */
Modified: gnunet-qt/src/plugins/fs/searchesModel.h
===================================================================
--- gnunet-qt/src/plugins/fs/searchesModel.h 2006-07-01 10:32:03 UTC (rev
3081)
+++ gnunet-qt/src/plugins/fs/searchesModel.h 2006-07-01 10:33:10 UTC (rev
3082)
@@ -30,6 +30,8 @@
#include <QAbstractItemModel>
#include <QList>
+#include "ecrsuri.h"
+
class GFSSearchesModel : public QAbstractItemModel
{
Q_OBJECT
@@ -46,14 +48,19 @@
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
void searchClosed(QString &strSearch);
public slots:
- void searchChanged(QString &strSearch, int searchResults);
+ void searchChanged(GFSEcrsUri &uri, int searchResults);
protected:
- typedef struct
+ class GFSSearchResultCount
{
- QString strSearch;
- int count;
- } GFSSearchResultCount;
+ public:
+ GFSSearchResultCount();
+ GFSSearchResultCount(const GFSSearchesModel::GFSSearchResultCount &src);
+ QString strSearch;
+ GFSEcrsUri uri;
+ int count;
+ };
+
typedef QList<GFSSearchResultCount> GFSSearchResultList;
GFSSearchResultList results;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3082 - gnunet-qt/src/plugins/fs,
durner <=