summaryrefslogtreecommitdiffabout
path: root/microkde/kglobal.cpp
blob: 9cc5835d74220aa544a120197c63d6f24c33e499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "kglobal.h"
#include "kstandarddirs.h"
#include <qnamespace.h>
#include <qapplication.h>
#include <QDesktopWidget>

KLocale *KGlobal::mLocale = 0;
KConfig *KGlobal::mConfig = 0;
KIconLoader *KGlobal::mIconLoader = 0;
KStandardDirs *KGlobal::mDirs = 0;

QString KGlobal::mAppName = "godot";

KLocale *KGlobal::locale()
{
  if ( !mLocale ) {
    Q_ASSERT(!mAppName.isEmpty());

    mLocale = new KLocale();//mAppName);
  }

  return mLocale;
}

//US
void KGlobal::setLocale(KLocale *kg)
{
    mLocale = kg;
}

KConfig *KGlobal::config()
{
  //mConfig is set inside setAppName. Though it has to be the first function you call.
  return mConfig;
}

KGlobal::Size KGlobal::getDesktopSize()
{
#ifdef DESKTOP_VERSION
  return KGlobal::Desktop;
#else
  if ( QApplication::desktop()->width() <= 320 )
    return KGlobal::Small;
  else if ( QApplication::desktop()->width() > 480)
    return KGlobal::Desktop;
  else
    return KGlobal::Medium;
#endif
}

KGlobal::Orientation KGlobal::getOrientation()
{
  if (QApplication::desktop()->width() > QApplication::desktop()->height())
    return KGlobal::Landscape;
  else
    return KGlobal::Portrait;
}

int KGlobal::getDesktopWidth()
{
  return QApplication::desktop()->width();
}

int KGlobal::getDesktopHeight()
{
  return QApplication::desktop()->height();
}


KIconLoader *KGlobal::iconLoader()
{
  if ( !mIconLoader ) {
    mIconLoader = new KIconLoader();
  }

  return mIconLoader;
}

KStandardDirs *KGlobal::dirs()
{
  if ( !mDirs ) {
    mDirs = new KStandardDirs();
  }

  return mDirs;
}

void KGlobal::setAppName( const QString &appName )
{
  mAppName = appName;

  mConfig = new KConfig( locateLocal("config", mAppName + "rc" ) );
}

//US
QString KGlobal::getAppName()
{
  return mAppName;
}
QString KGlobal::formatMessage ( QString mess, int maxlen  )
{
    //int maxlen = 80;
    if ( maxlen == 0 ) {
        maxlen =  QApplication::desktop()->width()/10;
        if ( maxlen > 32 )
            maxlen = (maxlen * 3) / 4;
        if ( maxlen > 100 )
            maxlen = 100;
    }
    int start = 0;
    int end = mess.length();
    QString retVal = "";
    int nl, space;
    while ( (end - start) > maxlen ) {
        nl = mess.find( "\n", start );
        if ( nl > 0 &&  nl  < start + maxlen ) {
            nl += 1;
            retVal += mess.mid( start, nl - start);
            start = nl;
        } else {
            space = mess.findRev( " ", start + maxlen );
            if ( space < start ) {
                retVal += mess.mid( start, maxlen) +"\n";
                start +=  maxlen ;
            } else {
                retVal += mess.mid( start, space - start ) +"\n";
                start =  space+ 1;
            }
        }
    }
    retVal += mess.mid( start, end - start );
    return retVal;
}
int  KGlobal::knumkeykonv( int k )
{
    int key;
switch( k ) {
 case Qt::Key_Q :
     key = Qt::Key_1;
    break;
 case Qt::Key_W :
     key = Qt::Key_2;
    break;
 case Qt::Key_E :
     key = Qt::Key_3;
    break;
 case Qt::Key_R :
     key = Qt::Key_4;
    break;
 case Qt::Key_T :
     key = Qt::Key_5;
    break;
 case Qt::Key_Z :
     key = Qt::Key_6;
    break;
 case Qt::Key_Y :
     key = Qt::Key_6;
    break;
 case Qt::Key_U :
     key = Qt::Key_7;
    break;
 case Qt::Key_I :
     key = Qt::Key_8;
    break;
 case Qt::Key_O :
     key = Qt::Key_9;
    break;
 case Qt::Key_P :
     key = Qt::Key_0;
    break;
   default:
       key = k;
    break;
  } // switch
 return key;
}