summaryrefslogtreecommitdiffstats
path: root/kvoctrain/kvoctrain/kvt-core/UsageManager.cpp
blob: 9180d6e4a9394d4acf0dbf74a606f99ace77a3e4 (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
/***************************************************************************

                            manage usage labels

    -----------------------------------------------------------------------

    begin                : Fri Mar 31 20:50:53 MET 1999

    copyright            : (C) 1999-2001 Ewald Arnold
                           (C) 2001 The KDE-EDU team
    email                : kvoctrain@ewald-arnold.de

    -----------------------------------------------------------------------


 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "UsageManager.h"

#include <klocale.h>


#include <iostream>
#include <vector>
using namespace std;

vector<TQString> UsageManager::userUsages;

// user usages are strings like this: #1

struct internalRelation_t
{
  const char *ident,
             *context,
             *shortid,
             *longId;
};

#ifndef I18N_NOOP2
#define I18N_NOOP2(context, str) context, str
#endif

static internalRelation_t InternalUsageRelations [] =
{
  { UL_AM,        0,   I18N_NOOP("Am."),      I18N_NOOP("Americanism")},
  { UL_ABBR,      0,   I18N_NOOP("abbr."),    I18N_NOOP("abbreviation")},
  { UL_ANAT,      0,   I18N_NOOP("anat."),    I18N_NOOP("anatomy")},
  { UL_ASTR,      0,   I18N_NOOP("astr."),    I18N_NOOP("astronomy")},
  { UL_BIOL,      0,   I18N_NOOP("biol."),    I18N_NOOP("biology")},
  { UL_BS,        0,   I18N_NOOP("b.s."),     I18N_NOOP("bad sense")},
  { UL_CONTP,     0,   I18N_NOOP("contp."),   I18N_NOOP("contemptuously")},
  { UL_ECCL,      0,   I18N_NOOP("eccl."),    I18N_NOOP("ecclesiastical")},
  { UL_FIG,       0,   I18N_NOOP("fig."),     I18N_NOOP("figuratively")},
  { UL_GEOL,      0,   I18N_NOOP("geol."),    I18N_NOOP("geology")},
  { UL_HIST,      0,   I18N_NOOP("hist."),    I18N_NOOP("historical")},
  { UL_ICHT,      0,   I18N_NOOP("icht."),    I18N_NOOP("ichthyology")},
  { UL_IFML,      0,   I18N_NOOP("ifml."),    I18N_NOOP("informal")},
  { UL_IRONIC,    0,   I18N_NOOP("iro."),     I18N_NOOP("ironic")},
  { UL_IRR,       0,   I18N_NOOP("irr."),     I18N_NOOP("irregular")},
  { UL_LIT,       0,   I18N_NOOP("lit."),     I18N_NOOP("literary")},
  { UL_META,      0,   I18N_NOOP("metall."),  I18N_NOOP("metallurgy")},
  { UL_METEO,     0,   I18N_NOOP("meteor."),  I18N_NOOP("meteorology")},
  { UL_MIN,       0,   I18N_NOOP("min."),     I18N_NOOP("mineralogy")},
  { UL_MOT,       0,   I18N_NOOP("mot."),     I18N_NOOP("motoring")},
  { UL_MOUNT,     0,   I18N_NOOP("mount."),   I18N_NOOP("mountaineering")},
  { UL_MYT,       0,   I18N_NOOP("myth."),    I18N_NOOP("mythology")},
  { UL_NPR,       0,   I18N_NOOP2("abbreviation: proper name",  "npr."),  I18N_NOOP("proper name")},
  { UL_OPT,       0,   I18N_NOOP("opt."),     I18N_NOOP("optics")},
  { UL_ORN,       0,   I18N_NOOP("orn."),     I18N_NOOP("ornithology")},
  { UL_OS,        0,   I18N_NOOP("o.s."),     I18N_NOOP("oneself")},
  { UL_P,         0,   I18N_NOOP("pers."),    I18N_NOOP("person")},
  { UL_PARL,      0,   I18N_NOOP("parl."),    I18N_NOOP("parliamentary")},
  { UL_PHARM,     0,   I18N_NOOP("pharm."),   I18N_NOOP("pharmacy")},
  { UL_PHLS,      0,   I18N_NOOP("phls."),    I18N_NOOP("philosophy")},
  { UL_PHOT,      0,   I18N_NOOP("phot."),    I18N_NOOP("photography")},
  { UL_PHYS,      0,   I18N_NOOP("phys."),    I18N_NOOP("physics")},
  { UL_PHYSIOL,   0,   I18N_NOOP("physiol."), I18N_NOOP("physiology")},
  { UL_PL,        0,   I18N_NOOP("pl."),      I18N_NOOP("plural")},
  { UL_POET,      0,   I18N_NOOP("poet."),    I18N_NOOP("poetry")},
  { UL_POL,       0,   I18N_NOOP("pol."),     I18N_NOOP("politics")},
  { UL_PROV,      0,   I18N_NOOP("prov."),    I18N_NOOP("provincialism")},
  { UL_PSYCH,     0,   I18N_NOOP("psych."),   I18N_NOOP("psychology")},
  { UL_RHET,      0,   I18N_NOOP("rhet."),    I18N_NOOP("rhetoric")},
  { UL_SURV,      0,   I18N_NOOP("surv."),    I18N_NOOP("surveying")},
  { UL_TEL,       0,   I18N_NOOP("tel."),     I18N_NOOP("telegraphy")},
  { UL_TELEPH,    0,   I18N_NOOP("teleph."),  I18N_NOOP("telephony")},
  { UL_THEA,      0,   I18N_NOOP("thea."),    I18N_NOOP("theater")},
  { UL_TYP,       0,   I18N_NOOP("typ."),     I18N_NOOP("typography")},
  { UL_UNIV,      0,   I18N_NOOP("univ."),    I18N_NOOP("university")},
  { UL_VET,       0,   I18N_NOOP("vet."),     I18N_NOOP("veterinary medicine")},
  { UL_ZO,        0,   I18N_NOOP("zo."),      I18N_NOOP("zoology")},
//{ UL_,          0,   I18N_NOOP(""),         I18N_NOOP("")},
  { 0, 0, 0, 0 } // the end
};


UsageManager::UsageManager ()
{
}


vector<UsageRelation> UsageManager::getRelation ()
{
  vector<UsageRelation> vec;
  for (int i = 0; i < (int) userUsages.size(); i++) {
    TQString s;
    s.setNum(i+1);
    s.insert(0, UL_USER_USAGE);
    vec.push_back(UsageRelation(s, userUsages[i], userUsages[i]));
  }

  internalRelation_t *usage = InternalUsageRelations;
  while (usage->ident != 0) {
    TQString s;
    if (usage->context == 0)
      s = i18n(usage->shortid);
    else
      s = i18n(usage->context, usage->shortid);
    vec.push_back(UsageRelation(usage->ident,
                                s,
                                i18n(usage->longId)));
    usage++;
  }

  return vec;
}


bool UsageManager::contains (const TQString& label, const TQString& collection)
{
   TQString s = collection;
   int pos;
   while ((pos = s.find(UL_USAGE_DIV)) >= 0) {
     if (s.left(pos) == label)
       return true;
     s.remove (0, pos+1);
   }

   return s == label;
}


void UsageManager::setUsageNames (vector<TQString> names)
{
  userUsages = names;
}