Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
Clear Cache should remove all other translations and tafsir in the data
Browse files Browse the repository at this point in the history
folder #454
  • Loading branch information
ragaeeb committed Dec 1, 2015
1 parent 7af6bd6 commit c8d7daf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,16 @@ CREATE INDEX IF NOT EXISTS quotes_index ON quotes(author,suite_id);
CREATE INDEX IF NOT EXISTS explanations_index ON explanations(to_verse_number);
VACUUM;

UPDATE verses SET translation = (SELECT text FROM x.verses WHERE sura=chapter_id AND ayah=verse_id) WHERE EXISTS (SELECT * FROM x.verses WHERE sura=chapter_id AND ayah=verse_id);
UPDATE verses SET translation = (SELECT text FROM x.verses WHERE sura=chapter_id AND ayah=verse_id) WHERE EXISTS (SELECT * FROM x.verses WHERE sura=chapter_id AND ayah=verse_id);

CREATE TABLE IF NOT EXISTS chapters (id INTEGER PRIMARY KEY, transliteration TEXT, translation TEXT);
CREATE TABLE IF NOT EXISTS verses2 (chapter_id INTEGER REFERENCES chapters(id), verse_id INTEGER, translation TEXT);
CREATE TABLE transliteration (chapter_id INTEGER REFERENCES chapters(id), verse_id INTEGER, html TEXT);
INSERT INTO verses2 SELECT sura,ayah,text FROM verses;
DROP TABLE properties;
DROP TABLE verses;
ALTER TABLE verses2 RENAME TO verses;
ATTACH DATABASE 'quran_english.db' AS x;
INSERT INTO chapters SELECT * FROM x.chapters;
INSERT INTO transliteration SELECT * FROM x.transliteration;
VACUUM;
4 changes: 4 additions & 0 deletions assets/QuranHelp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ HelpPage
actionBarAutoHideBehavior: ActionBarAutoHideBehavior.HideOnScroll
videoTutorialUri: "http://youtu.be/YOXtjnNWVZM"

onClearCacheTriggered: {
offloader.clearCachedDB();
}

actions: [
ActionItem
{
Expand Down
5 changes: 5 additions & 0 deletions src/Offloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ void Offloader::searchGoogle(QString const& query)
}


void Offloader::clearCachedDB() {
QtConcurrent::run(&ThreadUtils::clearCachedDB, m_persist->getValueFor(KEY_TRANSLATION).toString());
}


Offloader::~Offloader()
{
}
Expand Down
1 change: 1 addition & 0 deletions src/Offloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private slots:
Q_INVOKABLE void renderMap(bb::cascades::maps::MapView* mapView, QVariantMap const& data);
Q_INVOKABLE void searchGoogle(QString const& query);
void processDownloadedPlugin(QVariantMap const& q, QByteArray const& data);
Q_INVOKABLE void clearCachedDB();
};

} /* namespace quran */
Expand Down
22 changes: 22 additions & 0 deletions src/ThreadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,26 @@ bool ThreadUtils::replaceDatabase(QString const& src)
}


void ThreadUtils::clearCachedDB(QString const& language)
{
LOGGER(language);

QStringList all = QDir::home().entryList( QStringList() << "quran_*.db", QDir::Files | QDir::NoDot | QDir::NoDotDot );
LOGGER(all);

foreach (QString const& current, all)
{

if ( current.startsWith("quran_") ) // translation file
{
QString dbLang = current.split(".").first().split("_").last();

if (language != dbLang) {
QFile::remove( QString("%1/%2").arg( QDir::homePath() ).arg(current) );
}
}
}
}


} /* namespace quran */
1 change: 1 addition & 0 deletions src/ThreadUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct ThreadUtils
static QVariantMap matchSurah(QVariantMap input, QVariantList const& allSurahs);
static QVariantList captureAyatsInBody(QString body, QMap<QString, int> const& chapterToId);
static bool replaceDatabase(QString const& src);
static void clearCachedDB(QString const& language);
};

} /* namespace quran */
Expand Down

0 comments on commit c8d7daf

Please sign in to comment.