Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit d10a2042 authored by Julien Wintz's avatar Julien Wintz
Browse files

Adding a query mechanism.

parent 274de09e
Pipeline #205499 failed with stage
in 0 seconds
......@@ -40,6 +40,7 @@ public:
void addField(QString, QString);
void addResultType(QString);
void fetch(void);
void clear(void);
int count(void);
QString at(int) const;
......@@ -51,6 +52,10 @@ private:
QNetworkRequest *request = nullptr;
QNetworkAccessManager *manager = nullptr;
private:
int counter = 0;
bool dirty = true;
private:
static QString prefix_url;
......@@ -67,6 +72,19 @@ dtkReferenceFetcher::dtkReferenceFetcher(void)
this->url = prefix_url;
this->request = new QNetworkRequest;
this->manager = new QNetworkAccessManager;
connect(this->manager, &QNetworkAccessManager::finished, [&] (QNetworkReply *reply) -> void
{
QString contents = reply->readAll();
QJsonDocument proxy = QJsonDocument::fromJson(qPrintable(contents));
this->document = QJsonDocument(proxy["response"]["docs"].toArray());
qDebug() << Q_FUNC_INFO << document.toJson();
dirty = false;
});
}
dtkReferenceFetcher::~dtkReferenceFetcher()
......@@ -77,8 +95,6 @@ dtkReferenceFetcher::~dtkReferenceFetcher()
void dtkReferenceFetcher::addField(QString name_field, QString value_field)
{
static int counter = 0;
if(counter++)
this->url += "&";
......@@ -92,21 +108,25 @@ void dtkReferenceFetcher::addResultType(QString result_type)
void dtkReferenceFetcher::fetch(void)
{
qDebug() << this->url;
dirty = true;
request->setUrl(QUrl(this-> url));
manager->get(*(this->request));
connect(this->manager, &QNetworkAccessManager::finished, [&] (QNetworkReply *reply) -> void
{
QString contents = reply->readAll();
while(dirty)
qApp->processEvents();
QJsonDocument proxy = QJsonDocument::fromJson(qPrintable(contents));
qApp->processEvents();
}
this->document = QJsonDocument(proxy["response"]["docs"].toArray());
});
void dtkReferenceFetcher::clear(void)
{
this->url = prefix_url;
while(this->document.isEmpty())
qApp->processEvents();
this->counter = 0;
}
int dtkReferenceFetcher::count(void)
......@@ -627,53 +647,84 @@ void dtkReferenceFetcherDialog::setFetcher(dtkReferenceFetcher *fetcher)
}
// /////////////////////////////////////////////////////////////////////////////
// main
//
// /////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
class dtkReferenceSearchBar : public QLineEdit
{
dtkThemesEngine::instance()->apply();
Q_OBJECT
QApplication application(argc, argv);
application.setApplicationName("dtkWidgetsReferences");
application.setOrganizationName("inria");
application.setOrganizationDomain("fr");
public:
dtkReferenceSearchBar(QWidget *parent = nullptr);
// /////////////////////////////////////////////////////////////////////////////
// PoC
// /////////////////////////////////////////////////////////////////////////////
public:
QSize sizeHint(void) const;
public slots:
void polish(void);
protected:
void paintEvent(QPaintEvent *event);
};
dtkReferenceSearchBar::dtkReferenceSearchBar(QWidget *parent) : QLineEdit(parent)
{
QStringList completions;
completions << "email_s";
completions << "authFirstName_t";
completions << "authFullName_t";
completions << "authLastName_t";
completions << "text";
QCompleter *completer = new QCompleter(completions, this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
// QNetworkRequest request;
// request.setUrl(QUrl("https://api.archives-ouvertes.fr/search/?q=authLastName_s:Wintz&wt=json"));
this->setCompleter(completer);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
// QNetworkAccessManager manager;
// manager.get(request);
connect(dtkThemesEngine::instance(), SIGNAL(changed()), this, SLOT(polish()));
}
QSize dtkReferenceSearchBar::sizeHint(void) const
{
return QSize(100, 32);
}
void dtkReferenceSearchBar::polish(void)
{
this->setStyleSheet(QString("background: %1; border-radius: 0px; padding-left: 32px;").arg(dtkThemesEngine::instance()->value("@base6")));
}
void dtkReferenceSearchBar::paintEvent(QPaintEvent *event)
{
QLineEdit::paintEvent(event);
// QObject::connect(&manager, &QNetworkAccessManager::finished, [&] (QNetworkReply *reply) -> void
// {
// QJsonDocument document = QJsonDocument::fromJson(qPrintable(reply->readAll()));
dtkFontAwesome::instance()->initFontAwesome();
dtkFontAwesome::instance()->setDefaultOption("color", dtkThemesEngine::instance()->value("@fg"));
// qDebug() << "Request lead to" << document["response"]["numFound"].toVariant().toInt() << "results";
QPainter painter(this);
painter.drawPixmap(5, 5, 22, 22, dtkFontAwesome::instance()->icon(fa::search).pixmap(22, 22));
}
// application.quit();
// });
// /////////////////////////////////////////////////////////////////////////////
// main
// /////////////////////////////////////////////////////////////////////////////
// QWebEnginePage *page = new QWebEnginePage;
// page->setHtml("<h1>Maya la plus ....</h1><br/><br/><p>There will be some results</p>");
// page->setVisible(true);
int main(int argc, char **argv)
{
dtkThemesEngine::instance()->apply();
// QWebEngineView *view_t = new QWebEngineView;
// view_t->setPage(page);
// view_t->setHtml("<html><body><h1>Maya la plus ....</h1><br/><br/><p>There will be some results</p></body></html>");
// view_t->show();
// view_t->raise();
QApplication application(argc, argv);
application.setApplicationName("dtkWidgetsReferences");
application.setOrganizationName("inria");
application.setOrganizationDomain("fr");
// /////////////////////////////////////////////////////////////////////////////
// Fetcher (Logic Part)
// /////////////////////////////////////////////////////////////////////////////
dtkReferenceFetcher fetcher;
fetcher.addField("authLastName_s", "Kloczko");
fetcher.addField("authLastName_t", "Kloczko");
fetcher.addResultType("json");
fetcher.fetch();
......@@ -699,6 +750,9 @@ int main(int argc, char **argv)
view_l.setAlternatingRowColors(true);
view_l.setFixedWidth(80);
dtkReferenceSearchBar *search = new dtkReferenceSearchBar;
search->setText("authLastName_t:Kloczko");
dtkReferenceFetcherDialog fetcher_dialog;
fetcher_dialog.setFetcher(&fetcher);
fetcher_dialog.setFixedHeight(400);
......@@ -706,6 +760,7 @@ int main(int argc, char **argv)
QVBoxLayout *layout_i = new QVBoxLayout;
layout_i->setContentsMargins(0, 0, 0, 0);
layout_i->setSpacing(0);
layout_i->addWidget(search);
layout_i->addWidget(&view_a);
layout_i->addWidget(&fetcher_dialog);
......@@ -749,6 +804,21 @@ int main(int argc, char **argv)
// Connections
// /////////////////////////////////////////////////////////////////////////////
QObject::connect(search, &QLineEdit::returnPressed, [&] (void) -> void
{
fetcher.clear();
fetcher.addField(search->text().split(":").at(0), search->text().split(":").at(1));
fetcher.addResultType("json");
fetcher.fetch();
qDebug() << fetcher.document.toJson();
model.load(fetcher.document); // TODO: Beurk
view_l.setModel(&model);
view_a.setModel(0);
});
QObject::connect(&view_l, &QListView::clicked, [&] (const QModelIndex &index) -> void
{
int row = index.row();
......
......@@ -140,5 +140,6 @@ private:
QDebug operator<<(QDebug debug, const dtkWidgetsMenuBar &c);
QDebug operator<<(QDebug debug, dtkWidgetsMenuBar *c);
//
// dtkWidgetsMenuBar.h ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment