~ubuntu-branches/ubuntu/vivid/kdepim/vivid

« back to all changes in this revision

Viewing changes to importwizard/claws-mail/clawsmailsettings.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Rohan Garg, Scott Kitterman
  • Date: 2012-11-21 13:12:36 UTC
  • mfrom: (0.2.33)
  • Revision ID: package-import@ubuntu.com-20121121131236-32ijw9a2txrar80k
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Rohan Garg ]
* Add nepomuk-core-dev to build-deps

[ Scott Kitterman ]
* Add new package, libpimcommon4
  - Add libpimcommon4.install
  - Add to debian/control, including kdepim-dbg and kdepim-dev depends
  - Add to kdepim-dev.install
* Remove usr/bin/backupmail and related files from kmail.install as they are
  not provided by upstream anymore
* Add usr/bin/pimsettingexporter and related files to kmail.install
* Add libnepomukwidgets-dev to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2012 Montel Laurent <montel@kde.org>
 
3
  
 
4
  This program is free software; you can redistribute it and/or modify it
 
5
  under the terms of the GNU General Public License, version 2, as
 
6
  published by the Free Software Foundation.
 
7
  
 
8
  This program is distributed in the hope that it will be useful, but
 
9
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
  General Public License for more details.
 
12
  
 
13
  You should have received a copy of the GNU General Public License along
 
14
  with this program; if not, write to the Free Software Foundation, Inc.,
 
15
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
16
*/
 
17
 
 
18
#include "clawsmailsettings.h"
 
19
#include "importwizardutil.h"
 
20
 
 
21
#include <mailtransport/transportmanager.h>
 
22
#include "mailcommon/mailutil.h"
 
23
 
 
24
#include <kpimidentities/identity.h>
 
25
#include <kpimidentities/signature.h>
 
26
 
 
27
 
 
28
#include <KConfig>
 
29
#include <KConfigGroup>
 
30
#include <QFile>
 
31
 
 
32
ClawsMailSettings::ClawsMailSettings(ImportWizard *parent)
 
33
  :SylpheedSettings( parent )
 
34
{
 
35
}
 
36
 
 
37
ClawsMailSettings::~ClawsMailSettings()
 
38
{
 
39
 
 
40
}
 
41
 
 
42
void ClawsMailSettings::importSettings(const QString& filename, const QString& path)
 
43
{
 
44
  bool checkMailOnStartup = true;
 
45
  int intervalCheckMail = -1;
 
46
  const QString sylpheedrc = path + QLatin1String("/clawsrc");
 
47
  if(QFile( sylpheedrc ).exists()) {
 
48
    KConfig configCommon( sylpheedrc );
 
49
    if(configCommon.hasGroup("Common")) {
 
50
      KConfigGroup common = configCommon.group("Common");
 
51
      checkMailOnStartup = ( common.readEntry("check_on_startup",1) == 1 );
 
52
         if(common.readEntry(QLatin1String("autochk_newmail"),1) == 1 ) {
 
53
          intervalCheckMail = common.readEntry(QLatin1String("autochk_interval"),-1);
 
54
      }
 
55
      readGlobalSettings(common);
 
56
    }
 
57
  }
 
58
  KConfig config( filename );
 
59
  const QStringList accountList = config.groupList().filter( QRegExp( "Account: \\d+" ) );
 
60
  const QStringList::const_iterator end( accountList.constEnd() );
 
61
  for ( QStringList::const_iterator it = accountList.constBegin(); it!=end; ++it )
 
62
  {
 
63
    KConfigGroup group = config.group( *it );
 
64
    readAccount( group, checkMailOnStartup, intervalCheckMail );
 
65
    readIdentity( group );
 
66
  }
 
67
  const QString customheaderrc = path + QLatin1String("/customheaderrc");
 
68
  QFile customHeaderFile(customheaderrc);
 
69
  if(customHeaderFile.exists()) {
 
70
    if ( !customHeaderFile.open( QIODevice::ReadOnly ) ) {
 
71
      kDebug()<<" We can't open file"<<customheaderrc;
 
72
    } else {
 
73
      readCustomHeader(&customHeaderFile);
 
74
    }
 
75
  }
 
76
}
 
77
 
 
78
void ClawsMailSettings::readSettingsColor(const KConfigGroup& group)
 
79
{
 
80
  const bool enableColor = group.readEntry("enable_color", false);
 
81
  if(enableColor) {
 
82
    const QString colorLevel1 = group.readEntry("quote_level1_color");
 
83
    if(!colorLevel1.isEmpty()) {
 
84
        const QColor col = QColor(colorLevel1);
 
85
        if(col.isValid()) {
 
86
          addKmailConfig(QLatin1String("Reader"), QLatin1String("QuotedText1"), writeColor(col));
 
87
        }
 
88
      //[Reader]  QuotedText1
 
89
    }
 
90
    const QString colorLevel2 = group.readEntry("quote_level2_color");
 
91
    if(!colorLevel2.isEmpty()) {
 
92
        const QColor col = QColor(colorLevel2);
 
93
        if(col.isValid()) {
 
94
          addKmailConfig(QLatin1String("Reader"), QLatin1String("QuotedText2"), writeColor(col));
 
95
        }
 
96
      //[Reader]  QuotedText2
 
97
    }
 
98
    const QString colorLevel3 = group.readEntry("quote_level3_color");
 
99
    if(!colorLevel3.isEmpty()) {
 
100
        const QColor col = QColor(colorLevel3);
 
101
        if(col.isValid()) {
 
102
          addKmailConfig(QLatin1String("Reader"), QLatin1String("QuotedText3"), writeColor(col));
 
103
        }
 
104
      //[Reader]  QuotedText3
 
105
    }
 
106
    const QString misspellColor = group.readEntry(QLatin1String("misspelled_color"));
 
107
    if(!misspellColor.isEmpty()) {
 
108
        const QColor col = QColor(misspellColor);
 
109
        if(col.isValid()) {
 
110
          addKmailConfig(QLatin1String("Reader"), QLatin1String("MisspelledColor"), writeColor(col));
 
111
        }
 
112
    }
 
113
    const QString uriColor = group.readEntry(QLatin1String("uri_color"));
 
114
    if(!uriColor.isEmpty()) {
 
115
      const QColor col(uriColor);
 
116
      if(col.isValid()) {
 
117
        addKmailConfig(QLatin1String("Reader"), QLatin1String("LinkColor"), writeColor(col));
 
118
       }
 
119
    }
 
120
    const QString newColor = group.readEntry(QLatin1String("color_new"));
 
121
    if(!newColor.isEmpty()) {
 
122
      const QColor col(newColor);
 
123
      if(col.isValid()) {
 
124
        addKmailConfig(QLatin1String("MessageListView::Colors"), QLatin1String("UnreadMessageColor"), writeColor(col));
 
125
       }
 
126
    }
 
127
  }
 
128
}
 
129
 
 
130
QString ClawsMailSettings::writeColor(const QColor& col)
 
131
{
 
132
    QStringList list;
 
133
    list.insert(0, QString::number(col.red()));
 
134
    list.insert(1, QString::number(col.green()));
 
135
    list.insert(2, QString::number(col.blue()));
 
136
    if (col.alpha() != 255)
 
137
        list.insert(3, QString::number(col.alpha()));
 
138
    return list.join(QLatin1String(","));
 
139
}
 
140
 
 
141
void ClawsMailSettings::readTemplateFormat(const KConfigGroup& group)
 
142
{
 
143
  SylpheedSettings::readTemplateFormat(group);
 
144
  const QString composerNewMessage = group.readEntry(QLatin1String("compose_body_format"));
 
145
  if(!composerNewMessage.isEmpty()) {
 
146
    addKmailConfig(QLatin1String("TemplateParser"), QLatin1String("TemplateNewMessage"), convertToKmailTemplate(composerNewMessage));
 
147
  }
 
148
}
 
149
 
 
150
void ClawsMailSettings::readGlobalSettings(const KConfigGroup& group)
 
151
{
 
152
    SylpheedSettings::readGlobalSettings(group);
 
153
    if(!group.readEntry(QLatin1String("check_while_typing"),0) == 1) {
 
154
      addKmailConfig(QLatin1String("Spelling"), QLatin1String("backgroundCheckerEnabled"), true);
 
155
    }
 
156
    const int markAsRead = group.readEntry(QLatin1String("mark_as_read_delay"),-1);
 
157
    if(markAsRead!=-1) {
 
158
      addKmailConfig(QLatin1String("Behaviour"), QLatin1String("DelayedMarkTime"), markAsRead);
 
159
      addKmailConfig(QLatin1String("Behaviour"), QLatin1String("DelayedMarkAsRead"), true);
 
160
    }
 
161
 
 
162
    const int warnLargeFileInserting = group.readEntry(QLatin1String("warn_large_insert"),0);
 
163
    if(warnLargeFileInserting == 0) {
 
164
      addKmailConfig(QLatin1String("Composer"), QLatin1String("MaximumAttachmentSize"), -1);
 
165
    } else {
 
166
      const int warnLargeFileSize = group.readEntry(QLatin1String("warn_large_insert_size"),-1);
 
167
      if(warnLargeFileSize > 0) {
 
168
        addKmailConfig(QLatin1String("Composer"), QLatin1String("MaximumAttachmentSize"), warnLargeFileSize*1024);
 
169
      }
 
170
    }
 
171
}
 
172
 
 
173
void ClawsMailSettings::readTagColor(const KConfigGroup &group)
 
174
{
 
175
  const QString customColorPattern(QLatin1String("custom_color%1"));
 
176
  const QString customColorLabelPattern(QLatin1String("custom_colorlabel%1"));
 
177
  QList<tagStruct> listTag;
 
178
  for(int i = 1; i<=15; ++i) {
 
179
    if(group.hasKey(customColorPattern.arg(i))
 
180
      && group.hasKey(customColorLabelPattern.arg(i))) {
 
181
      tagStruct tag;
 
182
      const QString colorStr = group.readEntry(customColorPattern.arg(i));
 
183
      const QString labelStr = group.readEntry(customColorLabelPattern.arg(i));
 
184
      if(!colorStr.isEmpty()&& !labelStr.isEmpty()) {
 
185
        tag.color = QColor(colorStr).name();
 
186
        tag.name = labelStr;
 
187
        listTag<<tag;
 
188
      }
 
189
    }
 
190
  }
 
191
  if(!listTag.isEmpty()) {
 
192
    ImportWizardUtil::addNepomukTag(listTag);
 
193
  }
 
194
}