1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2013 Licq developers <licq-dev@googlegroups.com>
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #include "user.h"
21 
22 #include <licq/crypto.h>
23 #include <licq/inifile.h>
24 
25 using namespace LicqJabber;
26 
27 namespace
28 {
29 
30 const char KEY_PICTURE_SHA1[] = "JabberPictureSha1";
31 
32 } // namespace
33 
User(const Licq::UserId & id,bool temporary)34 User::User(const Licq::UserId& id, bool temporary)
35   : Licq::User(id, temporary)
36 {
37   Licq::IniFile& conf(userConf());
38 
39   conf.get(KEY_PICTURE_SHA1, myPictureSha1);
40 }
41 
~User()42 User::~User()
43 {
44   // Empty
45 }
46 
savePictureInfo()47 void User::savePictureInfo()
48 {
49   Licq::User::savePictureInfo();
50 
51   if (GetPicturePresent() && myPictureSha1.empty() && Licq::Sha1::supported())
52   {
53     std::string pictureData;
54     if (readPictureData(pictureData))
55       myPictureSha1 = Licq::Sha1::hashToHexString(pictureData);
56   }
57 
58   Licq::IniFile& conf(userConf());
59 
60   if (!myPictureSha1.empty())
61     conf.set(KEY_PICTURE_SHA1, myPictureSha1);
62   else
63     conf.unset(KEY_PICTURE_SHA1);
64 }
65