1 /*****************************************************************************
2 * This file is a part of QStarDict, a StarDict clone written with using Qt *
3 * swac.cpp - Plugin for words audio collections SWAC *
4 * Copyright (C) 2008 Nicolas Vion <nico@picapo.net> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License along *
17 * with this program; if not, write to the Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
19 *****************************************************************************/
23 #include <QMessageBox>
24 #include <QStringList>
25 #include <QSqlDatabase>
30 Swac::Swac(QObject *parent) : QObject(parent)
32 db = new QSqlDatabase();
33 *db = QSqlDatabase::addDatabase("QSQLITE", QLatin1String("swac"));
34 db->setDatabaseName(QDir::homePath() + "/.swac/swac.db");
42 QSqlDatabase::removeDatabase("swac");
45 QStringList Swac::availableDicts() const
48 QSqlQuery query = db->exec("SELECT packid FROM packages;");
51 result << query.value(0).toString();
56 void Swac::setLoadedDicts(const QStringList &dicts)
58 QStringList available = Swac::availableDicts();
59 m_loadedDicts.clear();
60 for (QStringList::const_iterator i = dicts.begin(); i != dicts.end(); ++i)
62 if (available.contains(*i))
67 Swac::DictInfo Swac::dictInfo(const QString &dict)
69 QSqlQuery query = db->exec("SELECT name, format, version, organization, readme FROM packages WHERE packid = \'" + dict + "\' LIMIT 1;");
72 return DictInfo(query.value(0).toString(), dict, query.value(3).toString(), "<pre>" + query.value(4).toString() + "</pre>");
74 return DictInfo("", dict, "", "");
78 QSqlQuery Swac::search(const QString &dict, const QString &word, const QString &fields, const int limit) {
81 "SELECT " + fields + " "
82 + "FROM alphaidx" + " "
83 + "INNER JOIN sounds ON alphaidx.sounds_idx = sounds.idx "
84 + "INNER JOIN packages ON sounds.packages_idx = packages.idx "
85 + "WHERE packages.packid = ?1 AND alphaidx.str = ?2 "
86 + "LIMIT " + QString::number(limit) +";"
88 query.addBindValue(dict);
89 query.addBindValue(word);
96 bool Swac::isTranslatable(const QString &dict, const QString &word)
98 QSqlQuery query = search(dict, word, "SWAC_TEXT", 1);
102 Swac::Translation Swac::translate(const QString &dict, const QString &word)
104 QSqlQuery query = search(dict, word, "SWAC_TEXT, packages.path, filename, SWAC_SPEAK_NAME", 128);
110 article += "<br/>\n";
111 article += "<img src=':/icons/sound.png'/> <a href=\"" + query.value(1).toString() + query.value(2).toString() + "\">" + query.value(0).toString() + "</a>";
115 return Translation(word, dict, article);
118 QStringList Swac::findSimilarWords(const QString &dict, const QString &word)
120 return QStringList();
123 int Swac::execSettingsDialog(QWidget *parent)
125 return QMessageBox::information(parent, "SWAC Plugin for QStarDict",
126 "To install new packages, please, use the <b>swac-get</b> command line program.\n"
127 "More information about swac-get is available on <a href='http://shtooka.net/'>Shtooka Project Homepage</A>." );
130 Q_EXPORT_PLUGIN2(swac, Swac)
132 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc