otr: removed TLV parsing code (i still has to fix SMP queries in callback)
[dyskinesia.git] / src / main.cpp
blob1edb99394ed0b029887a771355ddf274873151e3
1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://sam.zoy.org/wtfpl/COPYING for more details.
9 */
10 #include <ctype.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <unistd.h>
16 #ifdef USE_OTR
17 extern "C" {
18 # include <libotr/proto.h>
20 #endif
22 #include <QtCore>
23 #include <QDebug>
25 #include <QApplication>
26 #include <QFile>
27 #include <QTcpSocket>
28 #include <QUrl>
30 #ifdef USE_STATIC_PICPLUGS
31 # include <QtPlugin>
32 Q_IMPORT_PLUGIN(qgif4)
33 Q_IMPORT_PLUGIN(qjpeg4)
34 Q_IMPORT_PLUGIN(qmng4)
35 Q_IMPORT_PLUGIN(qico4)
36 Q_IMPORT_PLUGIN(qsvg4)
37 Q_IMPORT_PLUGIN(qtiff4)
38 #endif
40 #include "psycvars.h"
41 #include "psycpkt.h"
42 #include "psycproto.h"
44 #include "chatform.h"
46 #include "dlogf.h"
48 #include "dysversion.h"
50 #include "main.h"
53 static void fixTextCodec () {
54 QTextCodec *kc;
55 #ifdef WIN32
56 kc = QTextCodec::codecForName("windows-1251");
57 if (!kc) return;
58 QTextCodec::setCodecForCStrings(kc);
59 QTextCodec::setCodecForLocale(kc);
60 #else
61 const char *ll = getenv("LANG");
62 if (!ll || !ll[0]) ll = getenv("LC_CTYPE");
63 if (ll && ll[0] && (strcasestr(ll, "utf-8") || strcasestr(ll, "utf8"))) return;
64 kc = QTextCodec::codecForName("koi8-r");
65 if (!kc) return;
66 QTextCodec::setCodecForCStrings(kc);
67 QTextCodec::setCodecForLocale(kc);
68 #endif
72 bool debugOutput = false;
74 static void myMessageOutput (QtMsgType type, const char *msg) {
75 switch (type) {
76 case QtDebugMsg: if (debugOutput) fprintf(stderr, "Debug: %s\n", msg); break;
77 case QtWarningMsg: if (debugOutput) fprintf(stderr, "Warning: %s\n", msg); break;
78 case QtCriticalMsg: fprintf(stderr, "Critical: %s\n", msg); break;
79 case QtFatalMsg: fprintf(stderr, "Fatal: %s\n", msg); abort();
84 static void setDebugOutput (int argc, char *argv[]) {
85 qInstallMsgHandler(myMessageOutput);
87 for (int f = 1; f < argc; ++f) {
88 if (strcmp(argv[f], "-goobers") == 0) {
89 debugOutput = 1;
90 for (int c = f; c < argc; ++c) argv[c] = argv[c+1];
91 argv[--argc] = NULL;
92 --f;
95 dlogfSetStdErr(debugOutput?1:0);
96 dlogfSetFile(debugOutput?"debug.log":NULL);
97 dlogf("Dyskinesia v%d.%d.%d.%d log initialized", DYS_VERSION_HI, DYS_VERSION_MID, DYS_VERSION_LO, DYS_BUILD);
101 int main (int argc, char *argv[]) {
102 setDebugOutput(argc, argv);
104 QApplication app(argc, argv);
106 fixTextCodec();
108 QCoreApplication::setOrganizationName("Vampire Avalon");
109 QCoreApplication::setOrganizationDomain("ketmar.no-ip.org"); // fuck macz
110 QCoreApplication::setApplicationName("Dyskinesia");
112 #ifdef USE_OTR
113 OTRL_INIT;
114 #endif
116 ChatForm *f = new ChatForm();
117 f->show();
118 return app.exec();