Welcome to mirror list, hosted at ThFree Co, Russian Federation.

optparser.py « common « src - dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e8ecbd9d2c60203b5404192aac2af1217dd72c44 (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
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
# -*- coding:utf-8 -*-
## src/common/optparser.py
##
## Copyright (C) 2003-2005 Vincent Hanquez <tab AT snarc.org>
## Copyright (C) 2003-2014 Yann Leboulanger <asterix AT lagaule.org>
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com>
##                         Nikos Kouremenos <kourem AT gmail.com>
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
## Copyright (C) 2007 James Newton <redshodan AT gmail.com>
##                    Brendan Taylor <whateley AT gmail.com>
##                    Tomasz Melcer <liori AT exroot.org>
##                    Stephan Erb <steve-e AT h3c.de>
##
## This file is part of Gajim.
##
## Gajim 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; version 3 only.
##
## Gajim 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 Gajim. If not, see <http://www.gnu.org/licenses/>.
##

import os
import sys
import locale
import re
from time import time
from common import gajim
from common import helpers
from common import caps_cache

import sqlite3 as sqlite
import logger

import logging
log = logging.getLogger('gajim.c.optparser')

class OptionsParser:
    def __init__(self, filename):
        self.__filename = filename
        self.old_values = {}    # values that are saved in the file and maybe
                                                        # no longer valid

    def read(self):
        try:
            fd = open(self.__filename)
        except Exception:
            if os.path.exists(self.__filename):
                #we talk about a file
                print _('Error: cannot open %s for reading') % self.__filename
            return False

        new_version = gajim.config.get('version')
        new_version = new_version.split('-', 1)[0]
        seen = set()
        regex = re.compile(r"(?P<optname>[^.=]+)(?:(?:\.(?P<key>.+))?\.(?P<subname>[^.=]+))?\s=\s(?P<value>.*)")

        for line in fd:
            try:
                line = line.decode('utf-8')
            except UnicodeDecodeError:
                line = line.decode(locale.getpreferredencoding())
            match = regex.match(line)
            if match is None:
                log.warn('Invalid configuration line, ignoring it: %s', line)
                continue
            optname, key, subname, value = match.groups()
            if key is None:
                self.old_values[optname] = value
                gajim.config.set(optname, value)
            else:
                if (optname, key) not in seen:
                    gajim.config.add_per(optname, key)
                    seen.add((optname, key))
                gajim.config.set_per(optname, key, subname, value)

        old_version = gajim.config.get('version')
        old_version = old_version.split('-', 1)[0]

        self.update_config(old_version, new_version)
        self.old_values = {} # clean mem

        fd.close()
        return True

    def write_line(self, fd, opt, parents, value):
        if value is None:
            return
        # convert to utf8 before writing to file if needed
        if isinstance(value, unicode):
            value = value.encode('utf-8')
        else:
            value = str(value)
        if isinstance(opt, unicode):
            opt = opt.encode('utf-8')
        s = ''
        if parents:
            if len(parents) == 1:
                return
            for p in parents:
                if isinstance(p, unicode):
                    p = p.encode('utf-8')
                s += p + '.'
        s += opt
        fd.write(s + ' = ' + value + '\n')

    def write(self):
        (base_dir, filename) = os.path.split(self.__filename)
        self.__tempfile = os.path.join(base_dir, '.' + filename)
        try:
            f = open(self.__tempfile, 'w')
        except IOError, e:
            return str(e)
        try:
            gajim.config.foreach(self.write_line, f)
        except IOError, e:
            return str(e)
        f.flush()
        os.fsync(f.fileno())
        f.close()
        if os.path.exists(self.__filename):
            if os.name == 'nt':
                # win32 needs this
                try:
                    os.remove(self.__filename)
                except Exception:
                    pass
        try:
            os.rename(self.__tempfile, self.__filename)
        except IOError, e:
            return str(e)
        os.chmod(self.__filename, 0600)

    def update_config(self, old_version, new_version):
        old_version_list = old_version.split('.') # convert '0.x.y' to (0, x, y)
        old = []
        while len(old_version_list):
            old.append(int(old_version_list.pop(0)))
        new_version_list = new_version.split('.')
        new = []
        while len(new_version_list):
            new.append(int(new_version_list.pop(0)))

        if old < [0, 9] and new >= [0, 9]:
            self.update_config_x_to_09()
        if old < [0, 10] and new >= [0, 10]:
            self.update_config_09_to_010()
        if old < [0, 10, 1, 1] and new >= [0, 10, 1, 1]:
            self.update_config_to_01011()
        if old < [0, 10, 1, 2] and new >= [0, 10, 1, 2]:
            self.update_config_to_01012()
        if old < [0, 10, 1, 3] and new >= [0, 10, 1, 3]:
            self.update_config_to_01013()
        if old < [0, 10, 1, 4] and new >= [0, 10, 1, 4]:
            self.update_config_to_01014()
        if old < [0, 10, 1, 5] and new >= [0, 10, 1, 5]:
            self.update_config_to_01015()
        if old < [0, 10, 1, 6] and new >= [0, 10, 1, 6]:
            self.update_config_to_01016()
        if old < [0, 10, 1, 7] and new >= [0, 10, 1, 7]:
            self.update_config_to_01017()
        if old < [0, 10, 1, 8] and new >= [0, 10, 1, 8]:
            self.update_config_to_01018()
        if old < [0, 11, 0, 1] and new >= [0, 11, 0, 1]:
            self.update_config_to_01101()
        if old < [0, 11, 0, 2] and new >= [0, 11, 0, 2]:
            self.update_config_to_01102()
        if old < [0, 11, 1, 1] and new >= [0, 11, 1, 1]:
            self.update_config_to_01111()
        if old < [0, 11, 1, 2] and new >= [0, 11, 1, 2]:
            self.update_config_to_01112()
        if old < [0, 11, 1, 3] and new >= [0, 11, 1, 3]:
            self.update_config_to_01113()
        if old < [0, 11, 1, 4] and new >= [0, 11, 1, 4]:
            self.update_config_to_01114()
        if old < [0, 11, 1, 5] and new >= [0, 11, 1, 5]:
            self.update_config_to_01115()
        if old < [0, 11, 2, 1] and new >= [0, 11, 2, 1]:
            self.update_config_to_01121()
        if old < [0, 11, 4, 1] and new >= [0, 11, 4, 1]:
            self.update_config_to_01141()
        if old < [0, 11, 4, 2] and new >= [0, 11, 4, 2]:
            self.update_config_to_01142()
        if old < [0, 11, 4, 3] and new >= [0, 11, 4, 3]:
            self.update_config_to_01143()
        if old < [0, 11, 4, 4] and new >= [0, 11, 4, 4]:
            self.update_config_to_01144()
        if old < [0, 12, 0, 1] and new >= [0, 12, 0, 1]:
            self.update_config_to_01201()
        if old < [0, 12, 1, 1] and new >= [0, 12, 1, 1]:
            self.update_config_to_01211()
        if old < [0, 12, 1, 2] and new >= [0, 12, 1, 2]:
            self.update_config_to_01212()
        if old < [0, 12, 1, 3] and new >= [0, 12, 1, 3]:
            self.update_config_to_01213()
        if old < [0, 12, 1, 4] and new >= [0, 12, 1, 4]:
            self.update_config_to_01214()
        if old < [0, 12, 1, 5] and new >= [0, 12, 1, 5]:
            self.update_config_to_01215()
        if old < [0, 12, 3, 1] and new >= [0, 12, 3, 1]:
            self.update_config_to_01231()
        if old < [0, 12, 5, 1] and new >= [0, 12, 5, 1]:
            self.update_config_from_0125()
            self.update_config_to_01251()
        if old < [0, 12, 5, 2] and new >= [0, 12, 5, 2]:
            self.update_config_to_01252()
        if old < [0, 12, 5, 3] and new >= [0, 12, 5, 3]:
            self.update_config_to_01253()
        if old < [0, 12, 5, 4] and new >= [0, 12, 5, 4]:
            self.update_config_to_01254()
        if old < [0, 12, 5, 5] and new >= [0, 12, 5, 5]:
            self.update_config_to_01255()
        if old < [0, 12, 5, 6] and new >= [0, 12, 5, 6]:
            self.update_config_to_01256()
        if old < [0, 12, 5, 7] and new >= [0, 12, 5, 7]:
            self.update_config_to_01257()
        if old < [0, 12, 5, 8] and new >= [0, 12, 5, 8]:
            self.update_config_to_01258()
        if old < [0, 13, 10, 0] and new >= [0, 13, 10, 0]:
            self.update_config_to_013100()
        if old < [0, 13, 10, 1] and new >= [0, 13, 10, 1]:
            self.update_config_to_013101()
        if old < [0, 13, 90, 1] and new >= [0, 13, 90, 1]:
            self.update_config_to_013901()
        if old < [0, 14, 0, 1] and new >= [0, 14, 0, 1]:
            self.update_config_to_01401()
        if old < [0, 14, 90, 0] and new >= [0, 14, 90, 0]:
            self.update_config_to_014900()
        if old < [0, 16, 0, 1] and new >= [0, 16, 0, 1]:
            self.update_config_to_01601()

        gajim.logger.init_vars()
        gajim.logger.attach_cache_database()
        gajim.config.set('version', new_version)

        caps_cache.capscache.initialize_from_db()

    def assert_unread_msgs_table_exists(self):
        """
        Create table unread_messages if there is no such table
        """
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    CREATE TABLE unread_messages (
                            message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
                            jid_id INTEGER
                    );
                    '''
            )
            con.commit()
            gajim.logger.init_vars()
        except sqlite.OperationalError:
            pass
        con.close()

    def update_ft_proxies(self, to_remove=[], to_add=[]):
        for account in gajim.config.get_per('accounts'):
            proxies_str = gajim.config.get_per('accounts', account,
                    'file_transfer_proxies')
            proxies = [p.strip() for p in proxies_str.split(',')]
            for wrong_proxy in to_remove:
                if wrong_proxy in proxies:
                    proxies.remove(wrong_proxy)
            for new_proxy in to_add:
                if new_proxy not in proxies:
                    proxies.append(new_proxy)
            proxies_str = ', '.join(proxies)
            gajim.config.set_per('accounts', account, 'file_transfer_proxies',
                    proxies_str)

    def update_config_x_to_09(self):
        # Var name that changed:
        # avatar_width /height -> chat_avatar_width / height
        if 'avatar_width' in self.old_values:
            gajim.config.set('chat_avatar_width', self.old_values['avatar_width'])
        if 'avatar_height' in self.old_values:
            gajim.config.set('chat_avatar_height', self.old_values['avatar_height'])
        if 'use_dbus' in self.old_values:
            gajim.config.set('remote_control', self.old_values['use_dbus'])
        # always_compact_view -> always_compact_view_chat / _gc
        if 'always_compact_view' in self.old_values:
            gajim.config.set('always_compact_view_chat',
                    self.old_values['always_compact_view'])
            gajim.config.set('always_compact_view_gc',
                    self.old_values['always_compact_view'])
        # new theme: grocery, plain
        d = ['accounttextcolor', 'accountbgcolor', 'accountfont',
                'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont',
                'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont',
                'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont',
                'bannerfontattrs']
        for theme_name in (_('grocery'), _('default')):
            if theme_name not in gajim.config.get_per('themes'):
                gajim.config.add_per('themes', theme_name)
                theme = gajim.config.themes_default[theme_name]
                for o in d:
                    gajim.config.set_per('themes', theme_name, o, theme[d.index(o)])
        # Remove cyan theme if it's not the current theme
        if 'cyan' in gajim.config.get_per('themes'):
            gajim.config.del_per('themes', 'cyan')
        if _('cyan') in gajim.config.get_per('themes'):
            gajim.config.del_per('themes', _('cyan'))
        # If we removed our roster_theme, choose the default green one or another
        # one if doesn't exists in config
        if gajim.config.get('roster_theme') not in gajim.config.get_per('themes'):
            theme = _('green')
            if theme not in gajim.config.get_per('themes'):
                theme = gajim.config.get_per('themes')[0]
            gajim.config.set('roster_theme', theme)
        # new proxies in accounts.name.file_transfer_proxies
        self.update_ft_proxies(to_add=['proxy.netlab.cz'])

        gajim.config.set('version', '0.9')

    def update_config_09_to_010(self):
        if 'usetabbedchat' in self.old_values and not \
        self.old_values['usetabbedchat']:
            gajim.config.set('one_message_window', 'never')
        if 'autodetect_browser_mailer' in self.old_values and \
        self.old_values['autodetect_browser_mailer'] is True:
            gajim.config.set('autodetect_browser_mailer', False)
        if 'useemoticons' in self.old_values and \
        not self.old_values['useemoticons']:
            gajim.config.set('emoticons_theme', '')
        if 'always_compact_view_chat' in self.old_values and \
        self.old_values['always_compact_view_chat'] != 'False':
            gajim.config.set('always_hide_chat_buttons', True)
        if 'always_compact_view_gc' in self.old_values and \
        self.old_values['always_compact_view_gc'] != 'False':
            gajim.config.set('always_hide_groupchat_buttons', True)

        self.update_ft_proxies(to_remove=['proxy65.jabber.autocom.pl',
                'proxy65.jabber.ccc.de'], to_add=['transfer.jabber.freenet.de'])
        # create unread_messages table if needed
        self.assert_unread_msgs_table_exists()

        gajim.config.set('version', '0.10')

    def update_config_to_01011(self):
        if 'print_status_in_muc' in self.old_values and \
                self.old_values['print_status_in_muc'] in (True, False):
            gajim.config.set('print_status_in_muc', 'in_and_out')
        gajim.config.set('version', '0.10.1.1')

    def update_config_to_01012(self):
        # See [6456]
        if 'emoticons_theme' in self.old_values and \
                self.old_values['emoticons_theme'] == 'Disabled':
            gajim.config.set('emoticons_theme', '')
        gajim.config.set('version', '0.10.1.2')

    def update_config_to_01013(self):
        """
        Create table transports_cache if there is no such table
        """
        # FIXME see #2812
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    CREATE TABLE transports_cache (
                            transport TEXT UNIQUE,
                            type INTEGER
                    );
                    '''
            )
            con.commit()
        except sqlite.OperationalError:
            pass
        con.close()
        gajim.config.set('version', '0.10.1.3')

    def update_config_to_01014(self):
        """
        Apply indeces to the logs database
        """
        print _('migrating logs database to indices')
        # FIXME see #2812
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        # apply indeces
        try:
            cur.executescript(
                    '''
                    CREATE INDEX idx_logs_jid_id_kind ON logs (jid_id, kind);
                    CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id);
                    '''
            )

            con.commit()
        except Exception:
            pass
        con.close()
        gajim.config.set('version', '0.10.1.4')

    def update_config_to_01015(self):
        """
        Clean show values in logs database
        """
        #FIXME see #2812
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        status = dict((i[5:].lower(), logger.constants.__dict__[i]) for i in \
                logger.constants.__dict__.keys() if i.startswith('SHOW_'))
        for show in status:
            cur.execute('update logs set show = ? where show = ?;', (status[show],
                    show))
        cur.execute('update logs set show = NULL where show not in (0, 1, 2, 3, 4, 5);')
        con.commit()
        cur.close() # remove this in 2007 [pysqlite old versions need this]
        con.close()
        gajim.config.set('version', '0.10.1.5')

    def update_config_to_01016(self):
        """
        #2494 : Now we play gc_received_message sound even if
        notify_on_all_muc_messages is false. Keep precedent behaviour
        """
        if 'notify_on_all_muc_messages' in self.old_values and \
        self.old_values['notify_on_all_muc_messages'] == 'False' and \
        gajim.config.get_per('soundevents', 'muc_message_received', 'enabled'):
            gajim.config.set_per('soundevents',\
                    'muc_message_received', 'enabled', False)
        gajim.config.set('version', '0.10.1.6')

    def update_config_to_01017(self):
        """
        trayicon_notification_on_new_messages -> trayicon_notification_on_events
        """
        if 'trayicon_notification_on_new_messages' in self.old_values:
            gajim.config.set('trayicon_notification_on_events',
                    self.old_values['trayicon_notification_on_new_messages'])
        gajim.config.set('version', '0.10.1.7')

    def update_config_to_01018(self):
        """
        chat_state_notifications -> outgoing_chat_state_notifications
        """
        if 'chat_state_notifications' in self.old_values:
            gajim.config.set('outgoing_chat_state_notifications',
                    self.old_values['chat_state_notifications'])
        gajim.config.set('version', '0.10.1.8')

    def update_config_to_01101(self):
        """
        Fill time_stamp from before_time and after_time
        """
        if 'before_time' in self.old_values:
            gajim.config.set('time_stamp', '%s%%X%s ' % (
                    self.old_values['before_time'], self.old_values['after_time']))
        gajim.config.set('version', '0.11.0.1')

    def update_config_to_01102(self):
        """
        Fill time_stamp from before_time and after_time
        """
        if 'ft_override_host_to_send' in self.old_values:
            gajim.config.set('ft_add_hosts_to_send',
                    self.old_values['ft_override_host_to_send'])
        gajim.config.set('version', '0.11.0.2')

    def update_config_to_01111(self):
        """
        Always_hide_chatbuttons -> compact_view
        """
        if 'always_hide_groupchat_buttons' in self.old_values and \
        'always_hide_chat_buttons' in self.old_values:
            gajim.config.set('compact_view', self.old_values['always_hide_groupchat_buttons'] and \
            self.old_values['always_hide_chat_buttons'])
        gajim.config.set('version', '0.11.1.1')

    def update_config_to_01112(self):
        """
        GTK+ theme is renamed to default
        """
        if 'roster_theme' in self.old_values and \
        self.old_values['roster_theme'] == 'gtk+':
            gajim.config.set('roster_theme', _('default'))
        gajim.config.set('version', '0.11.1.2')

    def update_config_to_01113(self):
        # copy&pasted from update_config_to_01013, possibly 'FIXME see #2812' applies too
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    CREATE TABLE caps_cache (
                            node TEXT,
                            ver TEXT,
                            ext TEXT,
                            data BLOB
                    );
                    '''
            )
            con.commit()
        except sqlite.OperationalError:
            pass
        con.close()
        gajim.config.set('version', '0.11.1.3')

    def update_config_to_01114(self):
        # add default theme if it doesn't exist
        d = ['accounttextcolor', 'accountbgcolor', 'accountfont',
                'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont',
                'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont',
                'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont',
                'bannerfontattrs']
        theme_name = _('default')
        if theme_name not in gajim.config.get_per('themes'):
            gajim.config.add_per('themes', theme_name)
            if gajim.config.get_per('themes', 'gtk+'):
                # copy from old gtk+ theme
                for o in d:
                    val = gajim.config.get_per('themes', 'gtk+', o)
                    gajim.config.set_per('themes', theme_name, o, val)
                gajim.config.del_per('themes', 'gtk+')
            else:
                # copy from default theme
                theme = gajim.config.themes_default[theme_name]
                for o in d:
                    gajim.config.set_per('themes', theme_name, o, theme[d.index(o)])
        gajim.config.set('version', '0.11.1.4')

    def update_config_to_01115(self):
        # copy&pasted from update_config_to_01013, possibly 'FIXME see #2812' applies too
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    DELETE FROM caps_cache;
                    '''
            )
            con.commit()
        except sqlite.OperationalError:
            pass
        con.close()
        gajim.config.set('version', '0.11.1.5')

    def update_config_to_01121(self):
        # remove old unencrypted secrets file
        from common.configpaths import gajimpaths

        new_file = gajimpaths['SECRETS_FILE']

        old_file = os.path.dirname(new_file) + '/secrets'

        if os.path.exists(old_file):
            os.remove(old_file)

        gajim.config.set('version', '0.11.2.1')

    def update_config_to_01141(self):
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    CREATE TABLE IF NOT EXISTS caps_cache (
                            node TEXT,
                            ver TEXT,
                            ext TEXT,
                            data BLOB
                    );
                    '''
            )
            con.commit()
        except sqlite.OperationalError:
            pass
        con.close()
        gajim.config.set('version', '0.11.4.1')

    def update_config_to_01142(self):
        """
        next_message_received sound event is splittedin 2 events
        """
        gajim.config.add_per('soundevents', 'next_message_received_focused')
        gajim.config.add_per('soundevents', 'next_message_received_unfocused')
        if gajim.config.get_per('soundevents', 'next_message_received'):
            enabled = gajim.config.get_per('soundevents', 'next_message_received',
                    'enabled')
            path = gajim.config.get_per('soundevents', 'next_message_received',
                    'path')
            gajim.config.del_per('soundevents', 'next_message_received')
            gajim.config.set_per('soundevents', 'next_message_received_focused',
                    'enabled', enabled)
            gajim.config.set_per('soundevents', 'next_message_received_focused',
                    'path', path)
        gajim.config.set('version', '0.11.1.2')

    def update_config_to_01143(self):
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    CREATE TABLE IF NOT EXISTS rooms_last_message_time(
                            jid_id INTEGER PRIMARY KEY UNIQUE,
                            time INTEGER
                    );
                    '''
            )
            con.commit()
        except sqlite.OperationalError:
            pass
        con.close()
        gajim.config.set('version', '0.11.4.3')

    def update_config_to_01144(self):
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript('DROP TABLE caps_cache;')
            con.commit()
        except sqlite.OperationalError:
            pass
        try:
            cur.executescript(
                    '''
                    CREATE TABLE caps_cache (
                            hash_method TEXT,
                            hash TEXT,
                            data BLOB
                    );
                    '''
            )
            con.commit()
        except sqlite.OperationalError, e:
            pass
        con.close()
        gajim.config.set('version', '0.11.4.4')

    def update_config_to_01201(self):
        if 'uri_schemes' in self.old_values:
            new_values = self.old_values['uri_schemes'].replace(' mailto', '').\
                    replace(' xmpp', '')
            gajim.config.set('uri_schemes', new_values)
        gajim.config.set('version', '0.12.0.1')

    def update_config_to_01211(self):
        if 'trayicon' in self.old_values:
            if self.old_values['trayicon'] == 'False':
                gajim.config.set('trayicon', 'never')
            else:
                gajim.config.set('trayicon', 'always')
        gajim.config.set('version', '0.12.1.1')

    def update_config_to_01212(self):
        for opt in ('ignore_unknown_contacts', 'send_os_info',
        'log_encrypted_sessions'):
            if opt in self.old_values:
                val = self.old_values[opt]
                for account in gajim.config.get_per('accounts'):
                    gajim.config.set_per('accounts', account, opt, val)
        gajim.config.set('version', '0.12.1.2')

    def update_config_to_01213(self):
        msgs = gajim.config.statusmsg_default
        for msg_name in gajim.config.get_per('statusmsg'):
            if msg_name in msgs:
                gajim.config.set_per('statusmsg', msg_name, 'activity',
                        msgs[msg_name][1])
                gajim.config.set_per('statusmsg', msg_name, 'subactivity',
                        msgs[msg_name][2])
                gajim.config.set_per('statusmsg', msg_name, 'activity_text',
                        msgs[msg_name][3])
                gajim.config.set_per('statusmsg', msg_name, 'mood',
                        msgs[msg_name][4])
                gajim.config.set_per('statusmsg', msg_name, 'mood_text',
                        msgs[msg_name][5])
        gajim.config.set('version', '0.12.1.3')

    def update_config_to_01214(self):
        for status in ['online', 'chat', 'away', 'xa', 'dnd', 'invisible',
        'offline']:
            if 'last_status_msg_' + status in self.old_values:
                gajim.config.add_per('statusmsg', '_last_' + status)
                gajim.config.set_per('statusmsg', '_last_' + status, 'message',
                        self.old_values['last_status_msg_' + status])
        gajim.config.set('version', '0.12.1.4')

    def update_config_to_01215(self):
        """
        Remove hardcoded ../data/sounds from config
        """
        dirs = ['../data', gajim.gajimpaths.data_root, gajim.DATA_DIR]
        if os.name != 'nt':
            dirs.append(os.path.expanduser(u'~/.gajim'))
        for evt in gajim.config.get_per('soundevents'):
            path = gajim.config.get_per('soundevents', evt, 'path')
            # absolute and relative passes are necessary
            path = helpers.strip_soundfile_path(path, dirs, abs=False)
            path = helpers.strip_soundfile_path(path, dirs, abs=True)
            gajim.config.set_per('soundevents', evt, 'path', path)
        gajim.config.set('version', '0.12.1.5')

    def update_config_to_01231(self):
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    CREATE TABLE IF NOT EXISTS roster_entry(
                            account_jid_id INTEGER,
                            jid_id INTEGER,
                            name TEXT,
                            subscription INTEGER,
                            ask BOOLEAN,
                            PRIMARY KEY (account_jid_id, jid_id)
                    );

                    CREATE TABLE IF NOT EXISTS roster_group(
                            account_jid_id INTEGER,
                            jid_id INTEGER,
                            group_name TEXT,
                            PRIMARY KEY (account_jid_id, jid_id, group_name)
                    );
                    '''
            )
            con.commit()
        except sqlite.OperationalError:
            pass
        con.close()
        gajim.config.set('version', '0.12.3.1')

    def update_config_from_0125(self):
        # All those functions need to be called for 0.12.5 to 0.13 transition
        self.update_config_to_01211()
        self.update_config_to_01213()
        self.update_config_to_01214()
        self.update_config_to_01215()
        self.update_config_to_01231()

    def update_config_to_01251(self):
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    ALTER TABLE unread_messages
                    ADD shown BOOLEAN default 0;
                    '''
            )
            con.commit()
        except sqlite.OperationalError:
            pass
        con.close()
        gajim.config.set('version', '0.12.5.1')

    def update_config_to_01252(self):
        if 'alwaysauth' in self.old_values:
            val = self.old_values['alwaysauth']
            for account in gajim.config.get_per('accounts'):
                gajim.config.set_per('accounts', account, 'autoauth', val)
        gajim.config.set('version', '0.12.5.2')

    def update_config_to_01253(self):
        if 'enable_zeroconf' in self.old_values:
            val = self.old_values['enable_zeroconf']
            for account in gajim.config.get_per('accounts'):
                if gajim.config.get_per('accounts', account, 'is_zeroconf'):
                    gajim.config.set_per('accounts', account, 'active', val)
                else:
                    gajim.config.set_per('accounts', account, 'active', True)
        gajim.config.set('version', '0.12.5.3')

    def update_config_to_01254(self):
        vals = {'inmsgcolor': ['#a34526', '#a40000'],
                'outmsgcolor': ['#164e6f', '#3465a4'],
                'restored_messages_color': ['grey', '#555753'],
                'statusmsgcolor': ['#1eaa1e', '#73d216'],
                'urlmsgcolor': ['#0000ff', '#204a87'],
                'gc_nicknames_colors': ['#a34526:#c000ff:#0012ff:#388a99:#045723:#7c7c7c:#ff8a00:#94452d:#244b5a:#32645a', '#4e9a06:#f57900:#ce5c00:#3465a4:#204a87:#75507b:#5c3566:#c17d11:#8f5902:#ef2929:#cc0000:#a40000']}
        for c in vals:
            if c not in self.old_values:
                continue
            val = self.old_values[c]
            if val == vals[c][0]:
                # We didn't change default value, so update it with new default
                gajim.config.set(c, vals[c][1])
        gajim.config.set('version', '0.12.5.4')

    def update_config_to_01255(self):
        vals = {'statusmsgcolor': ['#73d216', '#4e9a06'],
                'outmsgtxtcolor': ['#a2a2a2', '#555753']}
        for c in vals:
            if c not in self.old_values:
                continue
            val = self.old_values[c]
            if val == vals[c][0]:
                # We didn't change default value, so update it with new default
                gajim.config.set(c, vals[c][1])
        gajim.config.set('version', '0.12.5.5')

    def update_config_to_01256(self):
        vals = {'gc_nicknames_colors': ['#4e9a06:#f57900:#ce5c00:#3465a4:#204a87:#75507b:#5c3566:#c17d11:#8f5902:#ef2929:#cc0000:#a40000', '#f57900:#ce5c00:#204a87:#75507b:#5c3566:#c17d11:#8f5902:#ef2929:#cc0000:#a40000']}
        for c in vals:
            if c not in self.old_values:
                continue
            val = self.old_values[c]
            if val == vals[c][0]:
                # We didn't change default value, so update it with new default
                gajim.config.set(c, vals[c][1])
        gajim.config.set('version', '0.12.5.6')

    def update_config_to_01257(self):
        if 'iconset' in self.old_values:
            if self.old_values['iconset'] in ('nuvola', 'crystal', 'gossip',
            'simplebulb', 'stellar'):
                gajim.config.set('iconset', gajim.config.DEFAULT_ICONSET)
        gajim.config.set('version', '0.12.5.7')

    def update_config_to_01258(self):
        self.update_ft_proxies(to_remove=['proxy65.talkonaut.com',
                'proxy.jabber.org', 'proxy.netlab.cz', 'transfer.jabber.freenet.de',
                'proxy.jabber.cd.chalmers.se'], to_add=['proxy.eu.jabber.org',
                'proxy.jabber.ru', 'proxy.jabbim.cz'])
        gajim.config.set('version', '0.12.5.8')

    def update_config_to_013100(self):
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    ALTER TABLE caps_cache
                    ADD last_seen INTEGER default %d;
                    ''' % int(time())
            )
            con.commit()
        except sqlite.OperationalError:
            pass
        con.close()
        gajim.config.set('version', '0.13.10.0')

    def update_config_to_013101(self):
        back = os.getcwd()
        os.chdir(logger.LOG_DB_FOLDER)
        con = sqlite.connect(logger.LOG_DB_FILE)
        os.chdir(back)
        cur = con.cursor()
        try:
            cur.executescript(
                    '''
                    DROP INDEX IF EXISTS idx_logs_jid_id_kind;

                    CREATE INDEX IF NOT EXISTS
                    idx_logs_jid_id_time ON logs (jid_id, time DESC);
                    '''
            )
            con.commit()
        except sqlite.OperationalError:
            pass
        con.close()
        gajim.config.set('version', '0.13.10.1')

    def update_config_to_013901(self):
        schemes = 'aaa:// aaas:// acap:// cap:// cid: crid:// data: dav: dict:// dns: fax: file:/ ftp:// geo: go: gopher:// h323: http:// https:// iax: icap:// im: imap:// info: ipp:// iris: iris.beep: iris.xpc: iris.xpcs: iris.lwz: ldap:// mid: modem: msrp:// msrps:// mtqp:// mupdate:// news: nfs:// nntp:// opaquelocktoken: pop:// pres: prospero:// rtsp:// service: shttp:// sip: sips: sms: snmp:// soap.beep:// soap.beeps:// tag: tel: telnet:// tftp:// thismessage:/ tip:// tv: urn:// vemmi:// xmlrpc.beep:// xmlrpc.beeps:// z39.50r:// z39.50s:// about: apt: cvs:// daap:// ed2k:// feed: fish:// git:// iax2: irc:// ircs:// ldaps:// magnet: mms:// rsync:// ssh:// svn:// sftp:// smb:// webcal://'
        gajim.config.set('uri_schemes', schemes)
        gajim.config.set('version', '0.13.90.1')

    def update_config_to_01401(self):
        if 'autodetect_browser_mailer' not in self.old_values or 'openwith' \
        not in self.old_values or \
        (self.old_values['autodetect_browser_mailer'] == False and \
        self.old_values['openwith'] != 'custom'):
            gajim.config.set('autodetect_browser_mailer', True)
            gajim.config.set('openwith', gajim.config.DEFAULT_OPENWITH)
        gajim.config.set('version', '0.14.0.1')

    def update_config_to_014900(self):
        if 'use_stun_server' in self.old_values and self.old_values[
        'use_stun_server'] and not self.old_values['stun_server']:
            gajim.config.set('use_stun_server', False)
        if os.name == 'nt':
            gajim.config.set('autodetect_browser_mailer', True)

    def update_config_to_01601(self):
        if 'last_mam_id' in self.old_values:
            last_mam_id = self.old_values['last_mam_id']
            for account in gajim.config.get_per('accounts'):
                gajim.config.set_per('accounts', account, 'last_mam_id',
                    last_mam_id)
        gajim.config.set('version', '0.16.0.1')