Permalink
Browse files

Initial commit - prototype search for multiple docsets

  • Loading branch information...
0 parents commit 57d0dfc16610198647a7fa9c42bc516715f2deee @jkozera committed Jan 19, 2013
@@ -0,0 +1,2 @@
+zeal-build-Desktop-Debug/
+zeal/zeal.pro.user
@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+
+ return a.exec();
+}
@@ -0,0 +1,51 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+#include "zeallistmodel.h"
+#include "zealsearchmodel.h"
+#include <zealdocsetsregistry.h>
+
+#include <iostream>
+using namespace std;
+
+#include <QStandardPaths>
+#include <QMessageBox>
+#include <QDir>
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ auto dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+ auto dataDir = QDir(dataLocation);
+ if(!dataDir.cd("docsets")) {
+ QMessageBox::critical(this, "No docsets directory found",
+ QString("'docsets' directory not found in '%1'").arg(dataLocation));
+ } else {
+ for(auto subdir : dataDir.entryInfoList()) {
+ if(subdir.isDir() && !subdir.isHidden()) {
+ docsets->addDocset(subdir.absoluteFilePath());
+ }
+ }
+ }
+ ui->setupUi(this);
+ ui->treeView->setModel(&zealList);
+ ui->treeView->setColumnHidden(1, true);
+ connect(ui->treeView, &QTreeView::activated, [&](const QModelIndex& index) {
+ ui->webView->setUrl("file://" + index.sibling(index.row(), 1).data().toString());
+ });
+ connect(ui->lineEdit, &QLineEdit::textChanged, [&](const QString& text) {
+ if(!text.isEmpty()) {
+ zealSearch.setQuery(text);
+ ui->treeView->setModel(&zealSearch);
+ ui->treeView->reset();
+ ui->treeView->setColumnHidden(1, true);
+ } else {
+ ui->treeView->setModel(&zealList);
+ }
+ });
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
@@ -0,0 +1,26 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include "zeallistmodel.h"
+#include "zealsearchmodel.h"
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+private:
+ Ui::MainWindow *ui;
+ ZealListModel zealList;
+ ZealSearchModel zealSearch;
+};
+
+#endif // MAINWINDOW_H
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>1050</width>
+ <height>579</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QSplitter" name="splitter">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QWidget" name="">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLineEdit" name="lineEdit"/>
+ </item>
+ <item>
+ <widget class="QTreeView" name="treeView">
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectItems</enum>
+ </property>
+ <property name="indentation">
+ <number>10</number>
+ </property>
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWebView" name="webView">
+ <property name="url">
+ <url>
+ <string>about:blank</string>
+ </url>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>1050</width>
+ <height>26</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>QWebView</class>
+ <extends>QWidget</extends>
+ <header>QtWebKit/QWebView</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
@@ -0,0 +1,28 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2013-01-18T22:28:41
+#
+#-------------------------------------------------
+
+QT += core gui widgets webkitwidgets sql
+
+
+TARGET = zeal
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+ mainwindow.cpp \
+ zeallistmodel.cpp \
+ zealsearchmodel.cpp \
+ zealdocsetsregistry.cpp
+
+HEADERS += mainwindow.h \
+ zeallistmodel.h \
+ zealsearchmodel.h \
+ zealdocsetsregistry.h
+
+FORMS += mainwindow.ui
+
+
+QMAKE_CXXFLAGS += -std=c++11
@@ -0,0 +1,14 @@
+#include "zealdocsetsregistry.h"
+
+ZealDocsetsRegistry* ZealDocsetsRegistry::m_Instance;
+
+ZealDocsetsRegistry* docsets = ZealDocsetsRegistry::instance();
+
+void ZealDocsetsRegistry::addDocset(const QString& path) {
+ auto dir = QDir(path);
+ auto db = QSqlDatabase::addDatabase("QSQLITE", dir.dirName());
+ db.setDatabaseName(dir.filePath("index.sqlite"));
+ db.open();
+ dbs.insert(dir.dirName(), db);
+ dirs.insert(dir.dirName(), dir);
+}
@@ -0,0 +1,64 @@
+#ifndef ZEALDOCSETSREGISTRY_H
+#define ZEALDOCSETSREGISTRY_H
+
+#include <QMutex>
+#include <QtSql/QSqlDatabase>
+#include <QDir>
+#include <QMap>
+#include <iostream>
+using namespace std;
+
+class ZealDocsetsRegistry
+{
+public:
+ static ZealDocsetsRegistry* instance()
+ {
+ static QMutex mutex;
+ if (!m_Instance)
+ {
+ mutex.lock();
+
+ if (!m_Instance)
+ m_Instance = new ZealDocsetsRegistry;
+
+ mutex.unlock();
+ }
+
+ return m_Instance;
+ }
+
+ void addDocset(const QString& path);
+
+ int count() const {
+ return dbs.count();
+ }
+
+ QSqlDatabase& db(const QString& name) {
+ return dbs[name];
+ }
+
+ const QDir& dir(const QString& name) {
+ return dirs[name];
+ }
+
+ QStringList names() const {
+ return dbs.keys();
+ }
+
+private:
+ ZealDocsetsRegistry() {
+ }
+
+ ZealDocsetsRegistry(const ZealDocsetsRegistry&); // hide copy constructor
+ ZealDocsetsRegistry& operator=(const ZealDocsetsRegistry&); // hide assign op
+ // we leave just the declarations, so the compiler will warn us
+ // if we try to use those two functions by accident
+
+ static ZealDocsetsRegistry* m_Instance;
+ QMap<QString, QSqlDatabase> dbs;
+ QMap<QString, QDir> dirs;
+};
+
+extern ZealDocsetsRegistry* docsets;
+
+#endif // ZEALDOCSETSREGISTRY_H
Oops, something went wrong.

0 comments on commit 57d0dfc

Please sign in to comment.