TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

key.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. This file is part of libtdeabc.
  3. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <tdeapplication.h>
  18. #include <tdelocale.h>
  19. #include "key.h"
  20. using namespace TDEABC;
  21. Key::Key( const TQString &text, int type )
  22. : mTextData( text ), mIsBinary( false ), mType( type )
  23. {
  24. mId = TDEApplication::randomString(8);
  25. }
  26. Key::~Key()
  27. {
  28. }
  29. bool Key::operator==( const Key &k ) const
  30. {
  31. if ( mIsBinary != k.mIsBinary ) return false;
  32. if ( mIsBinary )
  33. if ( mBinaryData != k.mBinaryData ) return false;
  34. else
  35. if ( mTextData != k.mTextData ) return false;
  36. if ( mType != k.mType ) return false;
  37. if ( mCustomTypeString != k.mCustomTypeString ) return false;
  38. return true;
  39. }
  40. bool Key::operator!=( const Key &k ) const
  41. {
  42. return !( k == *this );
  43. }
  44. void Key::setId( const TQString &id )
  45. {
  46. mId = id;
  47. }
  48. TQString Key::id() const
  49. {
  50. return mId;
  51. }
  52. void Key::setBinaryData( const TQByteArray &binary )
  53. {
  54. mBinaryData = binary;
  55. mIsBinary = true;
  56. }
  57. TQByteArray Key::binaryData() const
  58. {
  59. return mBinaryData;
  60. }
  61. void Key::setTextData( const TQString &text )
  62. {
  63. mTextData = text;
  64. mIsBinary = false;
  65. }
  66. TQString Key::textData() const
  67. {
  68. return mTextData;
  69. }
  70. bool Key::isBinary() const
  71. {
  72. return mIsBinary;
  73. }
  74. void Key::setType( int type )
  75. {
  76. mType = type;
  77. }
  78. void Key::setCustomTypeString( const TQString &custom )
  79. {
  80. mCustomTypeString = custom;
  81. }
  82. int Key::type() const
  83. {
  84. return mType;
  85. }
  86. TQString Key::customTypeString() const
  87. {
  88. return mCustomTypeString;
  89. }
  90. Key::TypeList Key::typeList()
  91. {
  92. TypeList list;
  93. list << X509;
  94. list << PGP;
  95. list << Custom;
  96. return list;
  97. }
  98. TQString Key::typeLabel( int type )
  99. {
  100. switch ( type ) {
  101. case X509:
  102. return i18n( "X509" );
  103. break;
  104. case PGP:
  105. return i18n( "PGP" );
  106. break;
  107. case Custom:
  108. return i18n( "Custom" );
  109. break;
  110. default:
  111. return i18n( "Unknown type" );
  112. break;
  113. }
  114. }
  115. TQDataStream &TDEABC::operator<<( TQDataStream &s, const Key &key )
  116. {
  117. return s << key.mId << key.mIsBinary << key.mTextData << key.mBinaryData <<
  118. key.mCustomTypeString << key.mType;
  119. }
  120. TQDataStream &TDEABC::operator>>( TQDataStream &s, Key &key )
  121. {
  122. s >> key.mId >> key.mIsBinary >> key.mTextData >> key.mBinaryData >>
  123. key.mCustomTypeString >> key.mType;
  124. return s;
  125. }