File indexing completed on 2024-04-28 16:01:33
0001 /****************************************************************************** 0002 * This file is part of the libqgit2 library 0003 * Copyright (c) 2011 Laszlo Papp <djszapi@archlinux.us> 0004 * Copyright (C) 2013 Leonardo Giordani 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 0021 #include "qgitsignature.h" 0022 #include "qgitexception.h" 0023 0024 namespace LibQGit2 0025 { 0026 0027 class Signature::Private { 0028 static void do_not_free(git_signature*) {} 0029 public: 0030 Private(const git_signature *signature, bool own) : 0031 signature(const_cast<git_signature*>(signature), own ? git_signature_free : do_not_free) 0032 { 0033 } 0034 0035 QSharedPointer<git_signature> signature; 0036 }; 0037 0038 Signature::Signature(const QString& name, const QString& email, QDateTime dateTime) 0039 { 0040 git_signature *sig = 0; 0041 qGitThrow(git_signature_new(&sig, name.toUtf8(), email.toUtf8(), dateTime.toTime_t(), dateTime.offsetFromUtc() / 60)); 0042 d_ptr = QSharedPointer<Private>(new Private(sig, true)); 0043 } 0044 0045 Signature::Signature(const QString& name, const QString& email) 0046 { 0047 git_signature *sig = 0; 0048 qGitThrow(git_signature_now(&sig, name.toUtf8(), email.toUtf8())); 0049 d_ptr = QSharedPointer<Private>(new Private(sig, true)); 0050 } 0051 0052 Signature::Signature(const git_signature *signature) : 0053 d_ptr(new Private(signature, false)) 0054 { 0055 } 0056 0057 QString Signature::name() const 0058 { 0059 QString ret; 0060 if (d_ptr->signature) { 0061 ret = QString::fromUtf8(d_ptr->signature->name); 0062 } 0063 return ret; 0064 } 0065 0066 QString Signature::email() const 0067 { 0068 QString ret; 0069 if (d_ptr->signature) { 0070 ret = QString::fromUtf8(d_ptr->signature->email); 0071 } 0072 return ret; 0073 } 0074 0075 QDateTime Signature::when() const 0076 { 0077 QDateTime dt; 0078 if (d_ptr->signature) { 0079 dt.setTime_t(d_ptr->signature->when.time); 0080 dt.setOffsetFromUtc(d_ptr->signature->when.offset * 60); 0081 } 0082 return dt; 0083 } 0084 0085 const git_signature *Signature::data() const 0086 { 0087 return d_ptr->signature.data(); 0088 } 0089 0090 } // namespace LibQGit2