-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdxclustert.cpp
More file actions
1440 lines (1360 loc) · 36.8 KB
/
dxclustert.cpp
File metadata and controls
1440 lines (1360 loc) · 36.8 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
dxcluster.cpp - description
-------------------
begin : jan 2015
copyright : (C) 2015 by Jaime Robles
email : jaime@robles.es
***************************************************************************/
/*****************************************************************************
* This file is part of Kluster. *
* *
* Kluster 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 3 of the License, or *
* (at your option) any later version. *
* *
* Kluster is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Kluster. If not, see <http://www.gnu.org/licenses/>. *
* *
*****************************************************************************/
#include "dxclustert.h"
DXClusterTWidget::DXClusterTWidget(const QString _dir, QWidget *parent )
{
appDir = _dir;
}
DXClusterTWidget::DXClusterTWidget(const QString _dir, const QString &clusterToConnect, const int portToConnect, QWidget *parent )
: QWidget(parent)
{
qDebug() << "DXClusterTWidget::DXClusterTWidget" << endl;
appDir = _dir;
world = new World(appDir);
world->create(appDir);
dxcView = new QListView();
inputCommand = new QLineEdit();
sendButton = new QPushButton();
clearButton = new QPushButton;
dxcMainTabWidget = new QTabWidget;
tcpSocket = new QTcpSocket(this);
//http://www.qrz.com/db/EA4TV
server = clusterToConnect;
port = portToConnect;
//model = new QStandardItemModel(0,6,this); //2 Rows and 6 Columns
model = new QStandardItemModel(this);
initClass();
//dxcView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
dxcView->setModel(model);
QHBoxLayout *bottonLayout = new QHBoxLayout;
//bottonLayout->addSpacerItem(new QSpacerItem(10,0,QSizePolicy::Expanding,QSizePolicy::Maximum));
//bottonLayout->addSpacerItem(new QSpacerItem(10,0,QSizePolicy::Expanding,QSizePolicy::Maximum));
bottonLayout->addWidget(inputCommand);
bottonLayout->addWidget(clearButton);
bottonLayout->addWidget(sendButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(dxcMainTabWidget);
//mainLayout->addWidget(dxcView);
mainLayout->addLayout(bottonLayout);
setLayout(mainLayout);
}
DXClusterTWidget::~DXClusterTWidget()
{
}
void DXClusterTWidget::initClass()
{
//dxcView->setHorizontalHeader(QHeaderView::setStretchLastSection(true));
//treeView->header()->setStretchLastSection(false);
//treeView->header()->setResizeMode(1, QHeaderView::Stretch);
int i = dxcMainTabWidget->addTab(dxcView, tr("Spots"));
//(dxcView->horizontalHeader())->setStretchLastSection(true);
inputCommand->setToolTip(tr("Enter the commands to be sent to the DXCluster server"));
sendButton->setToolTip(tr("Click to send to the DXCluster server"));
//clearButton->setToolTip(tr("Click to clear the input box"));
sendButton->setText(tr("Connect"));
clearButton->setText(tr("Clear"));
dxClusterConnected = false;
dxClusterAlreadyConnected = false;
showhf = true;
showvhf = true;
showwarc = true;
showann = true;
showwwv = true;
showwcy = true;
connect(sendButton , SIGNAL(clicked()), this, SLOT(slotClusterSendToServer()) );
connect(inputCommand, SIGNAL(textChanged(QString)), this, SLOT(slotClusterInputTextChanged()) );
//connect(dxClusterListWidget, SIGNAL(itemDoubleClicked ( QListWidgetItem *)), this, SLOT(slotClusterDXClusterWidgetItemDoubleClicked( QListWidgetItem * )) );
//connect(dxClusterListWidget, SIGNAL(itemEntered ( QListWidgetItem *)), this, SLOT(slotClusterDXClusterWidgetItemEntered( QListWidgetItem * )) );
//connect(dxClusterListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(slotClusterDXClusterWidgetItemSelected() ) );
}
void DXClusterTWidget::slotClusterDisplayError(QAbstractSocket::SocketError socketError)
{
qDebug() << "DXClusterTWidget:displayError:" << endl;
switch (socketError) {
case QAbstractSocket::RemoteHostClosedError:
break;
case QAbstractSocket::HostNotFoundError:
QMessageBox::warning(this, tr("Kluster DXCluster"),
tr("The host was not found. Please check:\n\n"
"- your network connection;\n"
"- the host name and port settings."));
break;
case QAbstractSocket::ConnectionRefusedError:
QMessageBox::warning(this, tr("Kluster DXCluster"),
tr("The connection was refused by the peer. "
"Make sure the DXCluster server is running, "
"and check that the host name and port "
"settings are correct."));
break;
default:
QMessageBox::warning(this, tr("Kluster DXCluster"),
tr("The following error occurred: %1.")
.arg(tcpSocket->errorString()));
}
}
void DXClusterTWidget::slotClusterDataArrived()
{
qDebug() << "DXClusterTWidget::slotClusterDataArrived" << endl;
QStringList qs;
QString flagFileName = QString();
QString dxClusterString = QString();
QString dxCall = QString();
QString dxFrequency = QString();
QString spotBand = QString();
QString spotter = QString();
QString comment = QString();
QString time = QString();
bool endsTime = false;
QDate qdate = QDate::currentDate();
QString date = qdate.toString("dd-MMM");
spotBand = "-1";
//bool isADXSpot = false;
while ( tcpSocket->canReadLine() ) {
dxClusterString = tcpSocket->readLine();
dxClusterString = dxClusterString.simplified().toUtf8();
QStringList tokens = dxClusterString.split(" ", QString::SkipEmptyParts);
if (tokens.size()<2){
return;
}
// It is a "DX de SP0TTER FREC DXCALL"
//0 = DX, 1 = de, 2 = spotter, 3 = Freq, 4 = dxcall, 5 = comment
qDebug() << "DXClusterTWidget::slotClusterDataArrived: " << "DXCLUSTER->" << dxClusterString << endl;
if ((tokens[0] == "DX") && (tokens[1] == "de"))
{
qDebug() << "DXClusterTWidget::slotClusterDataArrived: DX DE" << endl;
spotter = tokens[2];
spotter.truncate(spotter.size() - 1);
dxFrequency = tokens[3];
// Convert KHz to MHz..
dxFrequency = QString::number( (dxFrequency.toFloat())/1000, 'f', 3);
dxCall = tokens[4];
qDebug() << "DXClusterTWidget::slotClusterDataArrived: tokens: " << QString::number(tokens.count()) << endl;
time = tokens.last();
endsTime = time.contains("Z", Qt::CaseInsensitive);
if (endsTime)
{
qDebug() << "DXClusterTWidget::slotClusterDataArrived: ends with Z - " << tokens.last() << endl;
}
else
{
qDebug() << "DXClusterTWidget::slotClusterDataArrived: does not end with Z, it is locator - " << tokens.last() << endl;
time = tokens[(tokens.count())-2];
}
//DX de JA1HOX: 7003.0 UN7GP 2059Z 6
//DX de JA1HOX: 7003.0 UN7GP 2059Z IN80 7
//DX de JA1HOX: 7003.0 UN7GP TNS 2059Z 7
//DX de JA1HOX: 7003.0 UN7GP Tnx boris 2059Z 8
//DX de JA1HOX: 7003.0 UN7GP Tnx boris 2059Z IN80 9
//0 1 2 3 4 5 6 7 8
if (tokens.count() != 6)
{
if( (tokens.count() == 7) && (endsTime))
{}
}
qDebug() << "DXClusterTWidget::slotClusterDataArrived: Comment: " << comment << endl;
flagFileName = getFlagFromDX(dxCall);
addSpotToList(spotter, dxFrequency, dxCall, comment, date, time);
}
else if ((tokens[0] == "To") && (tokens[1] == "ALL"))
{
qDebug() << "DXClusterTWidget::slotClusterDataArrived: TO ALL" << endl;
//dxSpotColor = awards->getDefaultColor();
}
else
{
qDebug() << "DXClusterTWidget::slotClusterDataArrived: DEFAULT" << endl;
//dxSpotColor = awards->getDefaultColor();
}
}
qDebug() << "DXClusterTWidget::slotClusterDataArrived - (end): " << dxClusterString << endl;
}
void DXClusterTWidget::slotClusterSocketConnected()
{
qDebug() << "DXClusterTWidget::slotClusterSocketConnected" << endl;
QListWidgetItem *item = new QListWidgetItem();
//item->setForeground(QBrush(awards->getDefaultColor()));
item->setText(tr("Connected to server"));
//dxClusterListWidget->insertItem(0,item);
// dxClusterSpotItem * item = new dxClusterSpotItem(dxclusterListWidget, i18n("Connected to server"), awards->getDefaultColor());
dxClusterConnected = true;
inputCommand->setFocus(Qt::OtherFocusReason);
if (( dxClusterConnected ) && (!dxClusterAlreadyConnected) ){
bool ok;
QString callsignText = QInputDialog::getText(this, tr("Kluster message"), tr("Enter your callsign to connect to the cluster:"), QLineEdit::Normal, "", &ok);
QString passwordText = QInputDialog::getText(this, tr("Kluster message"), tr("Enter your password to connect to the cluster(just enter if no pasword!):"), QLineEdit::Normal, "", &ok);
QTextStream os(tcpSocket);
if ( callsignText.length() > 2 && ok ) {
os << callsignText << "\n";
//TODO: Check the DXCluster answer and enter the password if needed.
sendButton->setText(tr("Disconnect"));
clearButton->setText(tr("Clear"));
dxClusterAlreadyConnected = true;
} else {
os << tr("Not logged on, you may to enter your callsign again.") << "\n";
dxClusterAlreadyConnected = false;
}
inputCommand->setEnabled(true);
inputCommand->setToolTip(tr("Enter here the commands to be sent to the DX-Cluster server"));
}
}
void DXClusterTWidget::slotClusterSocketConnectionClosed()
{
qDebug() << "DXClusterTWidget::slotClusterSocketConnectionClosed" << endl;
QListWidgetItem *item = new QListWidgetItem();
//item->setForeground(QBrush(awards->getDefaultColor()));
item->setText(tr("Connection closed by the server"));
//dxClusterListWidget->insertItem(0,item);
dxClusterConnected = false;
dxClusterAlreadyConnected = false;
sendButton->setText(tr("Connect"));
inputCommand->setDisabled(true);
inputCommand->setToolTip(tr("Click on Connect to connect to the DX-Cluster server"));
//connect(inputCommand, SIGNAL(returnPressed()), this, SLOT(slotClusterSendToServer()) );
disconnect (inputCommand, SIGNAL(returnPressed()), this, SLOT(slotClusterSendToServer()) );
}
void DXClusterTWidget::slotClusterSendToServer()
{
qDebug() << "DXClusterTWidget::slotClusterSendToServer()" << endl;
if (!dxClusterConnected)
{
connectToDXCluster();
return; // If we try to connect...
}
if ( inputCommand ->text().length() < 1 )
{
qDebug() << "DXClusterTWidget::slotClusterSendToServer() - Vacio..." << endl;
QTextStream os(tcpSocket);
os << "bye\n";
return;
}
// write to the server
QTextStream os(tcpSocket);
os << inputCommand ->text() << "\n";
inputCommand ->clear();
}
void DXClusterTWidget::slotClusterClearLineInput()
{
qDebug() << "DXClusterTWidget::slotClusterClearLineInput" << endl;
if ( ((inputCommand->text()).length()) <= 0 )
{
if ( dxClusterConnected )
{
QTextStream os(tcpSocket);
os << "bye\n";
}
else
{
}
}
else
{
inputCommand->clear();
}
}
void DXClusterTWidget::slotClusterInputTextChanged()
{
qDebug() << "DXClusterTWidget::slotClusterInputTextChanged" << endl;
if ( ((inputCommand->text()).length()) <= 0 )
{
sendButton->setText(tr("Disconnect"));
clearButton->setText(tr("Clear"));
}
else if (dxClusterConnected)
{
sendButton->setText(tr("Send"));
clearButton->setText(tr("Clear"));
}
else
{}
}
void DXClusterTWidget::connectToDXCluster()
{
qDebug() << "DXClusterTWidget::connectToDXCluster" << endl;
if (dxClusterConnected)
{
qDebug() << "DXClusterTWidget::connectToDXCluster: - Already connected!!" << endl;
return; // If we are connected we don't want to start another connection
}
connect(tcpSocket, SIGNAL(connected()), SLOT(slotClusterSocketConnected()) );
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(slotClusterDataArrived() ));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotClusterDisplayError(QAbstractSocket::SocketError)));
connect(tcpSocket, SIGNAL(disconnected()), SLOT(slotClusterSocketConnectionClosed()) );
connect(inputCommand, SIGNAL(returnPressed()), this, SLOT(slotClusterSendToServer()) );
connect(clearButton, SIGNAL(clicked()), this, SLOT(slotClusterClearLineInput()) );
tcpSocket->connectToHost(server, port );
//dxClusterListWidget->setSortingEnabled (false);
//dxClusterSpotItem * item = new dxClusterSpotItem(dxClusterListWidget, tr("Trying to connect to the server\n"), awards->getDefaultColor());
}
void DXClusterTWidget::addSpotToList(const QString _de, const QString _fr, const QString _dx, const QString _co, const QString _da, const QString _ti)
{
//qDebug() << "DXClusterTWidget::addSpotToList" << _dx << endl;
QList<QStandardItem*> DX;
// "DX de " = 6
// Calls ~ 15
// Freq = 9
// DX ~ 15
// Date = 6
// Time = 5
//StandardItemModel *iStandardModel = new QStandardItemModel(this);
//QStandardItem* item1 = new QStandardItem(QIcon("images/shield-280x280.png"),"");
//QStandardItem* item2 = new QStandardItem(QIcon("images/shield-280x280.png"),"");
//iStandardModel->appendRow(item1);
QString dxC = _dx.simplified();
dxC = dxC.leftJustified(20, ' ');
QString deCall = _de.simplified();
deCall = deCall.leftJustified(20, ' ');
QString line = QString("%1\t on %2\t de %3\t%4\t%5 %6").arg(dxC, -15).arg(_fr, 9).arg(deCall, -15).arg(_co, -25).arg(_da, -6).arg(_ti, -5);
QString flagPath = QString();
qDebug() << "DXClusterTWidget::addSpotToList - line: " << line << endl;
QStandardItem *de = new QStandardItem(line);
// QStandardItem *ti = new QStandardItem(line2);
flagPath = QString("/Users/devel/Desktop/kluster/img/") + getFlagFromDX(_dx) + QString(".png");
de->setIcon(QIcon(flagPath));
//model->appendRow(DX);
DX.append(de);
//DX.append(ti);
//DX << de << ti;
//model->appendRow(flag);
//model->appendRow(DX);
model->insertRow(0,DX);
qDebug() << "DXClusterTWidget::addSpotToList - length: " << QString::number(DX.length()) << endl;
//model->insertRow(0, DX);
}
QString DXClusterTWidget::getFlagFromDX(const QString _dx)
{
qDebug() << "DXClusterTWidget::getFlagFromDX: " << _dx << " = " << world->getQRZEntityName(_dx) << endl;
int arrlid = world->getQRZARRLId(_dx);
switch (arrlid) { // Just to prepare or some tasks before reading DATA from UI
case 246://Sovereign Order of Malta
return "un";
break;
case 247://Spratly
return "un";
break;
case 260: // Monaco
return "mc";
break;
case 4: // Agalega
return "mu";
case 165: // Mauricio
return "mu";
break;
case 207: // Rodriguez
return "mu";
break;
case 49: // Equatorial Guinea
return "gq";
break;
case 195: // Annobon
return "gq";
case 176: // Fidji
return "fj";
break;
case 489: // Conway reef
return "fj";
break;
case 460: // Rotuma
return "fj";
break;
case 468: // Swaziland
return "sz";
case 474: // Tunisia
return "tn";
break;
case 293: // Vietnam
return "vn";
break;
case 107: //Guinea
return "gn";
break;
case 24: //Bouvet
return "bv";
break;
case 199: //"Peter 1 Is"
return "no";
break;
case 18: // Azerbaijan
return "az";
break;
case 75: // Georgia
return "ge";
break;
case 514: // Montenegro
return "me";
break;
case 315: // Sri lanka
return "lk";
break;
case 117: // ITU HQ
return "ch";
break;
case 289: // UN HQ
return "us";
break;
case 511: // Timor Leste
return "tl";
break;
case 336: // Israel
return "il";
break;
case 436: // Libya
return "ly";
break;
case 215: // Cyprus
return "cy";
break;
case 470: // Tanzania
return "tz";
break;
case 450: // Nigeria
return "ng";
break;
case 438: // Madagascar
return "mg";
break;
case 444: //Mauritania
return "mr";
break;
case 187: // Niger
return "ne";
break;
case 483: // Togo
return "tg";
break;
case 190: // Samoa
return "ws";
break;
case 286: // Uganda
return "ug";
break;
case 430: // Kenya
return "ke";
break;
case 456: // Senegal
return "sn";
break;
case 82: // Jamaica
return "jm";
break;
case 492: //Yemen
return "ye";
break;
case 432: //Lesotho
return "ls";
break;
case 440: // Malawi
return "mw";
break;
case 400: // Algeria
return "dz";
break;
case 62: // Barbados
return "bb";
break;
case 159: // Maldives
return "mv";
break;
case 129: // Guyana
return "gy";
break;
case 497: // Croatia
return "hr";
break;
case 424: // Ghana
return "gh";
break;
case 257: // Malta
return "mt";
break;
case 482: // Zambia
return "zm";
break;
case 348: // Kuwait
return "kw";
break;
case 458: // Sierra Leone
return "sl";
break;
case 299: // West Malaysia
return "my";
break;
case 46: // East Malaysia
return "my";
break;
case 369: // Nepal
return "np";
break;
case 414: // Dem Rep Congo
return "cd";
break;
case 404: // Burundi
return "bi";
break;
case 381: // Singapore
return "sg";
break;
case 454: // Rwanda
return "rw";
break;
case 90: // Trinidad & Tobago
return "tt";
break;
case 402: // Botswana
return "bw";
break;
case 160: // Tonga
return "to";
break;
case 370: // Oman
return "om";
break;
case 306: // Bhutan
return "bt";
break;
case 391: // Un Arab Emirates
return "ae";
break;
case 376: // Qatar
return "qa";
break;
case 304: //Bahrain
return "bh";
break;
case 372: // Pakistan
return "pk";
break;
case 506: // Scarboroug Reef
return "un";
break;
case 386: // Taiwan
return "tw";
break;
case 505: //Pratas Is
return "tw";
break;
case 318: // China
return "cn";
break;
case 157: // Nauru
return "nr";
break;
case 203: // Andorra
return "ad";
break;
case 422: // Gambia
return "gm";
break;
case 60: // Bahamas
return "bs";
break;
case 181: // Mozambique
return "mz";
break;
case 112: // Chile
return "cl";
break;
case 217: //San Felix
return "cl";
break;
case 47: // Easter Is
return "cl";
break;
case 125: // Juan Fernandez is
return "cl";
break;
case 13: // Antartica
return "un";
break;
case 70: // Cuba
return "cu";
break;
case 446: //Morocco
return "ma";
break;
case 104: //Bolivia
return "bo";
break;
case 272: //Portugal
return "pt";
break;
case 256: // Madeira
return "pt";
break;
case 149: // Azores
return "pt";
break;
case 144: // Uruguay
return "uy";
break;
case 211: // Sable Is
return "ca";
break;
case 252: // St Paul is
return "ca";
break;
case 401: // Angola
return "ao";
break;
case 409: //Cape Verde
return "cv";
break;
case 411: // Comoros
return "km";
break;
case 230: // Fed Rep Germany
return "de";
break;
case 375: //Philippines
return "ph";
break;
case 51: // Eritrea
return "er";
break;
case 510: // Palestine
return "ps";
break;
case 191: // North Cook
return "ck";
break;
case 234: // South Cook
return "ck";
break;
case 188: // Niue
return "nu";
break;
case 501: // Bosnia
return "ba";
break;
case 281: // Spain
return "es";
break;
case 21: //Balearic is
return "es";
break;
case 29: // Canary Is
return "canary";
break;
case 32: // Ceuta & Melilla
return "es";
break;
case 245: // Ireland
return "ie";
break;
case 14: // Armenia
return "am";
break;
case 434: // Liberia
return "lr";
break;
case 330: // Iran
return "ir";
break;
case 179: //Moldova
return "mv";
break;
case 52: // Estonia
return "ee";
break;
case 53: //Ethiopia
return "et";
break;
case 27: //Belarus
return "by";
break;
case 135: //Kyrgyzstan
return "kg";
break;
case 262: // Turkmenistan
return "tm";
break;
case 227: // France
return "fr";
break;
case 79: // Guadeloupe
return "fr";
break;
case 169: // Mayotte
return "yt";
break;
case 516: // St Barthelemy
return "fr";
break;
case 162: // New Caledonia
return "nc";
break;
case 512: // Chesterfield Is
return "nc";
break;
case 84: // Martinique
return "mq";
break;
case 175: // French Polynesia
return "pf";
break;
case 508: //Austral Is
return "pf";
break;
case 277: // St Pierre & Miquelon
return "pm";
break;
case 453: //Reunion Is
return "re";
break;
case 213: // St Marteen
return "fr";//TODO: Add the wikipedia flag
break;
case 99: // Glorioso is
return "fr";
break;
case 124: // Juan de nova, Europa
return "fr"; //TODO: Add the wikipedia flag
break;
case 276: // Tromelin
return "fr";//TODO: Add the wikipedia flag
break;
case 41: //Crozet
return "fr";
break;
case 131: //Kerguelen
return "fr"; //TODO: Add the wikipedia flag http://es.wikipedia.org/wiki/Tierras_Australes_y_Ant%C3%A1rticas_Francesas
break;
case 10: // Amsterdam & St Paul is
return "fr"; //TODO: Add the wikipedia flag
break;
case 298: // Wallis & Futuna is
return "wf";
break;
case 63: // French Guiana
return "gf"; //TODO: Add the wikipedia flag
break;
case 223: // England
return "england";
break;
case 114: //Isle of Man
return "gb"; //TODO: Add the wikipedia flag
break;
case 265: // Northern Ireland
return "northernireland";
break;
case 122: //Jersey
return "gb";break;
break;
case 279: // Scotland & Shetland is
return "scotland";
break;
case 106: // Guernsey
return "gb"; //TODO: Add the wikipedia flag
break;
case 294: // Wales
return "wales";
break;
case 185: // Solomon
return "sb";
break;
case 507: // Temotu Province
return "sb";
break;
case 239: // Hungary
return "hu";
break;
case 287: // Switzerland
return "ch";
break;
case 251: // Liechtenstein
return "li";
break;
case 120: // Ecuador
return "ec";
break;
case 71: // Galapagos Is
return "ec";
break;
case 78: // Haiti
return "ht";
break;
case 72: // Dominican Rep
return "do";
break;
case 116: // Colombia
return "co";
break;
case 216: // San Andres & Providencia
return "co";
break;
case 161: // Malpelo
return "co";
break;
case 137: // Rep Korea
return "kr";
break;
case 88: // Panama
return "pa";
break;
case 80: // Honduras
return "hn";
break;
case 387: // Thailand
return "th";
break;
case 295: // Vatican City
return "va";
break;
case 378: // Saudi Arabia
return "sa";
break;
case 248: //Italy
return "it";
break;
case 382: // Djibouti
return "dj";
break;
case 77: // Grenada
return "gd";
break;
case 109: // Guinea-Bissau
return "gw";
break;
case 97: // St Lucia
return "lc";
break;
case 95: // Dominica
return "dm";
break;
case 98: // St Vicent
return "vc";
break;
case 339: // Japan
return "jp";
break;
case 177: // Minami Torishima
return "jp";
break;
case 192: // Ogasawara
return "jp";
break;
case 363: //Mongolia
return "mn";
break;
case 259: // Svalbard
return "sj";
break;
case 118: // Jan Mayen
return "sj";
break;
case 342: // Jordan
return "jo";
break;
case 291: // United States
return "us";
break;
case 105: //Guantanamo Bay
return "us";
break;
case 166: // Mariana is
return "mp";
break;
case 20: // Baker & Howland is
return "us";
break;
case 103: // Guam
return "gu";
break;
case 123: // Johnston is
return "us";
break;
case 174: // Midway is
return "us";
break;
case 197: // Palmyra & Jarbis is
return "us";
break;
case 134: // Kingman Reef
return "us";
break;
case 110: // Hawaii
return "us"; //TODO: Add the wikipedia flag
break;
case 138: // Kure is
return "us";
break;
case 9: // American Samoa
return "as";
break;
case 515: // Swains is
return "as";
break;
case 297: // Wake is
return "us"; //TODO: Add the wikipedia flag
break;
case 6: //Alaska
return "us";
break;
case 182: // Navassa Is
return "us";
break;
case 285: // Us Virgin is
return "vi";
break;
case 202: // Puerto Rico
return "pr";
break;
case 43: // Desecheo Is
return "us";
break;