Skip to content

Commit

Permalink
Some changes for portability, among others for windows ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElTh0r0 committed Dec 30, 2011
1 parent b9e489d commit 125c2c2
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 52 deletions.
16 changes: 9 additions & 7 deletions CInterwiki.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@

CInterWiki::CInterWiki(const QApplication *pApp)
{
QFile XmlFile;

// Debug and "no instal" option
#if defined(NO_INSTALL) || !defined(QT_NO_DEBUG)
QFile XmlFile(pApp->applicationDirPath() + "/iWikiLinks/iWikiLinks.xml");
// Release
#else
QFile XmlFile("/usr/share/" + pApp->applicationName().toLower() + "/iWikiLinks/iWikiLinks.xml");
#endif
// Path from normal installation
if (QFile::exists("/usr/share/" + pApp->applicationName().toLower() + "/iWikiLinks/iWikiLinks.xml")) {
XmlFile.setFileName("/usr/share/" + pApp->applicationName().toLower() + "/iWikiLinks/iWikiLinks.xml");
}
// No installation: Use app path
else {
XmlFile.setFileName(pApp->applicationDirPath() + "/iWikiLinks/iWikiLinks.xml");
}

// Check if file exist and it's readable
if (!XmlFile.open(QFile::ReadOnly | QFile::Text)) {
Expand Down
86 changes: 51 additions & 35 deletions CInyokaEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,15 @@ void CInyokaEdit::createActions()
for (int i = 0; i < myInterWikiLinks->getInterwikiLinksGroups().size(); i++) {
iWikiLinksActions << emptyActionList;
for (int j = 0; j < myInterWikiLinks->getInterwikiLinksNames()[i].size(); j++) {
// Debug and "no instal" option
#if defined(NO_INSTALL) || !defined(QT_NO_DEBUG)
iWikiLinksActions[i] << new QAction(QIcon(pApp->applicationDirPath() + "/iWikiLinks/" + myInterWikiLinks->getInterwikiLinksIcons()[i][j]), myInterWikiLinks->getInterwikiLinksNames()[i][j], this);
// Release
#else
iWikiLinksActions[i] << new QAction(QIcon("/usr/share/" + pApp->applicationName().toLower() + "/iWikiLinks/" + myInterWikiLinks->getInterwikiLinksIcons()[i][j]), myInterWikiLinks->getInterwikiLinksNames()[i][j], this);
#endif
// Path from normal installation
if (QFile::exists("/usr/share/" + pApp->applicationName().toLower() + "/iWikiLinks")) {
iWikiLinksActions[i] << new QAction(QIcon("/usr/share/" + pApp->applicationName().toLower() + "/iWikiLinks/" + myInterWikiLinks->getInterwikiLinksIcons()[i][j]), myInterWikiLinks->getInterwikiLinksNames()[i][j], this);
}
// No installation: Use app path
else {
iWikiLinksActions[i] << new QAction(QIcon(pApp->applicationDirPath() + "/iWikiLinks/" + myInterWikiLinks->getInterwikiLinksIcons()[i][j]), myInterWikiLinks->getInterwikiLinksNames()[i][j], this);
}

mySigMapInterWikiLinks->setMapping(iWikiLinksActions[i][j], QString::number(i) + "," + QString::number(j));
connect(iWikiLinksActions[i][j], SIGNAL(triggered()), mySigMapInterWikiLinks, SLOT(map()));
}
Expand Down Expand Up @@ -570,14 +572,15 @@ void CInyokaEdit::createMenus()
}

// Insert interwiki-links menu
for (int i = 0; i < myInterWikiLinks->getInterwikiLinksGroups().size(); i++) {
// Debug and "no instal" option
#if defined(NO_INSTALL) || !defined(QT_NO_DEBUG)
iWikiGroups.append(ui->iWikiMenu->addMenu(QIcon(pApp->applicationDirPath() + "/iWikiLinks/" + myInterWikiLinks->getInterwikiLinksGroupIcons()[i]), myInterWikiLinks->getInterwikiLinksGroups()[i]));
// Release
#else
iWikiGroups.append(ui->iWikiMenu->addMenu(QIcon("/usr/share/" + pApp->applicationName().toLower() + "/iWikiLinks/" + myInterWikiLinks->getInterwikiLinksGroupIcons()[i]), myInterWikiLinks->getInterwikiLinksGroups()[i]));
#endif
for (int i = 0; i < myInterWikiLinks->getInterwikiLinksGroups().size(); i++) {
// Path from normal installation
if (QFile::exists("/usr/share/" + pApp->applicationName().toLower() + "/iWikiLinks")) {
iWikiGroups.append(ui->iWikiMenu->addMenu(QIcon("/usr/share/" + pApp->applicationName().toLower() + "/iWikiLinks/" + myInterWikiLinks->getInterwikiLinksGroupIcons()[i]), myInterWikiLinks->getInterwikiLinksGroups()[i]));
}
// No installation: Use app path
else {
iWikiGroups.append(ui->iWikiMenu->addMenu(QIcon(pApp->applicationDirPath() + "/iWikiLinks/" + myInterWikiLinks->getInterwikiLinksGroupIcons()[i]), myInterWikiLinks->getInterwikiLinksGroups()[i]));
}
iWikiGroups[i]->addActions(iWikiLinksActions[i]);
}

Expand Down Expand Up @@ -648,13 +651,14 @@ void CInyokaEdit::DownloadStyles(const QDir myDirectory)
if (QMessageBox::Yes== iRet){
try
{
// Debug and "no instal" option
#if defined(NO_INSTALL) || !defined(QT_NO_DEBUG)
myArticleDownloadProgress = new CProgressDialog(pApp->applicationDirPath() + "/GetInyokaStyles", pApp->applicationName(), this, myDirectory.absolutePath());
// Release
#else
myArticleDownloadProgress = new CProgressDialog("/usr/share/" + pApp->applicationName().toLower() + "/GetInyokaStyles", pApp->applicationName(), this, myDirectory.absolutePath());
#endif
// Path from normal installation
if (QFile::exists("/usr/share/" + pApp->applicationName().toLower() + "/GetInyokaStyles")) {
myArticleDownloadProgress = new CProgressDialog("/usr/share/" + pApp->applicationName().toLower() + "/GetInyokaStyles", pApp->applicationName(), this, myDirectory.absolutePath());
}
// No installation: Use app path
else {
myArticleDownloadProgress = new CProgressDialog(pApp->applicationDirPath() + "/GetInyokaStyles", pApp->applicationName(), this, myDirectory.absolutePath());
}
}
catch (std::bad_alloc& ba)
{
Expand Down Expand Up @@ -1196,6 +1200,8 @@ void CInyokaEdit::clearRecentFiles(){

void CInyokaEdit::checkSpelling()
{

#if not defined _WIN32
QString dictPath = "/usr/share/hunspell/" + mySettings->getSpellCheckerLanguage();
if (!QFile::exists(dictPath + ".dic") || !QFile::exists(dictPath + ".aff")) {
QMessageBox::critical(this, pApp->applicationName(), "Error: Spell checker dictionary file does not exist!");
Expand Down Expand Up @@ -1292,28 +1298,38 @@ void CInyokaEdit::checkSpelling()
checkDialog = NULL;

QMessageBox::information(this, pApp->applicationName(), tr("Spell check has finished."));

// Windows
#else
QMessageBox::information(this, pApp->applicationName(), tr("Spell checker is currently not supported for windows."));
#endif
}

// -----------------------------------------------------------------------------------------------
// Report a bug via Apport to Launchpad
// Report a bug

void CInyokaEdit::reportBug(){

// Start apport
QProcess procApport;
procApport.start("ubuntu-bug " + pApp->applicationName().toLower());

if (!procApport.waitForStarted()) {
QMessageBox::critical(this, pApp->applicationName(), tr("Error while starting Apport."));
return;
// Ubuntu: Using Apport
if (QFile::exists("/usr/bin/ubuntu-bug")) {
// Start apport
QProcess procApport;
procApport.start("ubuntu-bug " + pApp->applicationName().toLower());

if (!procApport.waitForStarted()) {
QMessageBox::critical(this, pApp->applicationName(), tr("Error while starting Apport."));
return;
}
if (!procApport.waitForFinished()) {
QMessageBox::critical(this, pApp->applicationName(), tr("Error while executing Apport."));
return;
}
}
if (!procApport.waitForFinished()) {
QMessageBox::critical(this, pApp->applicationName(), tr("Error while executing Apport."));
return;
// Not Ubuntu: Load Launchpad bug tracker
else {
QDesktopServices::openUrl(QUrl("https://bugs.launchpad.net/inyokaedit"));
}
}


// -----------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions CInyokaEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
#include "CProgressDialog.h"
#include "qtfindreplacedialog/finddialog.h"
#include "qtfindreplacedialog/findreplacedialog.h"

// Spell checker currently not under windows
#if not defined _WIN32
#include "CSpellChecker.h"
#include "CSpellCheckDialog.h"
#endif

// Qt classes
class QComboBox;
Expand Down
2 changes: 1 addition & 1 deletion CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void CSettings::readSettings(){
LastOpenedDir = mySettingsObject->value("LastOpenedDir", QDir::homePath()).toString();
bAutomaticImageDownload = mySettingsObject->value("AutomaticImageDownload", false).toBool();
sConfVersion = mySettingsObject->value("ConfVersion", "0.0.0").toString();
bShowStatusbar = mySettingsObject->value("ShowStatusbar", true).toBool();
bShowStatusbar = mySettingsObject->value("ShowStatusbar", false).toBool();
sSpellCheckerLanguage = mySettingsObject->value("SpellCheckerLanguage", "de_DE").toString();

// Font settings
Expand Down
17 changes: 10 additions & 7 deletions inyokaedit.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
CProgressDialog.h \
CSettings.h \
CInterwiki.h \
CParser.h \
CSpellChecker.h \
CParser.h
unix {
HEADERS += CSpellChecker.h \
CSpellCheckDialog.h
}

SOURCES += main.cpp \
CInyokaEdit.cpp \
Expand All @@ -26,9 +28,11 @@
CProgressDialog.cpp \
CSettings.cpp \
CInterwiki.cpp \
CParser.cpp \
CSpellChecker.cpp \
CParser.cpp
unix {
SOURCES += CSpellChecker.cpp \
CSpellCheckDialog.cpp
}

RESOURCES = inyokaeditresources.qrc

Expand All @@ -46,9 +50,8 @@
CODECFORSRC = UTF-8
CODECFORTR = UTF-8

unix {
LIBS += -lhunspell
}

TRANSLATIONS += lang/inyokaedit_de.ts

# After changing defines clean all and run qmake again
#DEFINES += NO_INSTALL
12 changes: 10 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ int main(int argc, char *argv[])

// Load global translation
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
// Try to load Qt translation
if (!qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
// If it fails search in application dircetory
qtTranslator.load("qt_" + QLocale::system().name(), app.applicationDirPath() + "/lang");
}
app.installTranslator(&qtTranslator);

// Load app translation if it exists
QTranslator myAppTranslator;
myAppTranslator.load(app.applicationName().toLower() + "_" + QLocale::system().name(), "/usr/share/" + app.applicationName().toLower() + "/lang");
// Try to load app translation (normal installation)
if (!myAppTranslator.load(app.applicationName().toLower() + "_" + QLocale::system().name(), "/usr/share/" + app.applicationName().toLower() + "/lang")){
// If it fails search in application dircetory
qtTranslator.load(app.applicationName().toLower() + "_" + QLocale::system().name(), app.applicationDirPath() + "/lang");
}
app.installTranslator(&myAppTranslator);

// New object of InyokaEdit
Expand Down

0 comments on commit 125c2c2

Please sign in to comment.