• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KAlarm Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kalarmcal
version.cpp
1 /*
2  * version.cpp - program version functions
3  * This file is part of kalarmcal library, which provides access to KAlarm
4  * calendar data.
5  * Copyright © 2002-2007,2011,2013 by David Jarvie <djarvie@kde.org>
6  *
7  * This library is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Library General Public License as published
9  * by the Free Software Foundation; either version 2 of the License, or (at
10  * your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  * License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to the
19  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  */
22 
23 #include "version.h"
24 
25 namespace KAlarmCal
26 {
27 
28 int Version(int major, int minor, int rev)
29 {
30  return major*10000 + minor*100 + rev;
31 }
32 
33 /******************************************************************************
34 * Convert the supplied KAlarm version string to a version number.
35 * Reply = version number (double digit for each of major, minor & issue number,
36 * e.g. 010203 for 1.2.3
37 * = 0 if invalid version string.
38 */
39 int getVersionNumber(const QString& version, QString* subVersion)
40 {
41  // N.B. Remember to change Version(int major, int minor, int rev)
42  // if the representation returned by this method changes.
43  if (subVersion)
44  subVersion->clear();
45  int count = version.count(QLatin1Char('.')) + 1;
46  if (count < 2)
47  return 0;
48  bool ok;
49  unsigned vernum = version.section(QLatin1Char('.'), 0, 0).toUInt(&ok) * 10000; // major version
50  if (!ok)
51  return 0;
52  unsigned v = version.section(QLatin1Char('.'), 1, 1).toUInt(&ok); // minor version
53  if (!ok)
54  return 0;
55  vernum += (v < 99 ? v : 99) * 100;
56  if (count >= 3)
57  {
58  // Issue number: allow other characters to follow the last digit
59  const QString issue = version.section(QLatin1Char('.'), 2);
60  int n = issue.length();
61  if (!n || !issue[0].isDigit())
62  return 0;
63  int i;
64  for (i = 0; i < n && issue[i].isDigit(); ++i) ;
65  if (subVersion)
66  *subVersion = issue.mid(i);
67  v = issue.left(i).toUInt(); // issue number
68  vernum += (v < 99 ? v : 99);
69  }
70  return vernum;
71 }
72 
73 QString getVersionString(int version)
74 {
75  return QString::fromLatin1("%1.%2.%3").arg(version/10000).arg((version%10000)/100).arg(version%100);
76 }
77 
78 } // namespace KAlarmCal
79 
80 // vim: et sw=4:
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KAlarm Library

Skip menu "KAlarm Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal