1 //////////////////////////////////////////////////////////////////////
2 //
3 // BeeBEEP Copyright (C) 2010-2021 Marco Mastroddi
4 //
5 // BeeBEEP is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published
7 // by the Free Software Foundation, either version 3 of the License,
8 // or (at your option) any later version.
9 //
10 // BeeBEEP 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 BeeBEEP. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Author: Marco Mastroddi <marco.mastroddi(AT)gmail.com>
19 //
20 // $Id: NumberTextMarker.cpp 101 2011-09-19 11:59:48Z mastroddi $
21 //
22 //////////////////////////////////////////////////////////////////////
23 
24 #include <QtPlugin>
25 #include <QtDebug>
26 #include <QtCore/qmath.h>
27 #include "NumberTextMarker.h"
28 #include "Version.h"
29 
30 
name() const31 QString NumberTextMarker::name() const
32 {
33   return tr( "Number Text Marker" );
34 }
35 
version() const36 QString NumberTextMarker::version() const
37 {
38   return "0.9.7";
39 }
40 
author() const41 QString NumberTextMarker::author() const
42 {
43   return "Marco Mastroddi";
44 }
45 
help() const46 QString NumberTextMarker::help() const
47 {
48   return tr( "If you want to encode your message with numbers write a #text to encode# ." );
49 }
50 
icon() const51 QIcon NumberTextMarker::icon() const
52 {
53   return QIcon( iconFileName() );
54 }
55 
iconFileName() const56 QString NumberTextMarker::iconFileName() const
57 {
58   return QLatin1String( ":/plugins/number.png" );
59 }
60 
priority() const61 int NumberTextMarker::priority() const
62 {
63   return 1000;
64 }
65 
coreVersion() const66 QString NumberTextMarker::coreVersion() const
67 {
68   return QString( BEEBEEP_VERSION );
69 }
70 
parseBeforeSending() const71 bool NumberTextMarker::parseBeforeSending() const
72 {
73   return true;
74 }
75 
76 namespace
77 {
78 
GetCharToNumber(const QChar & c_to_parse)79   QChar GetCharToNumber( const QChar& c_to_parse )
80   {
81     char c = c_to_parse.toLower().toLatin1();
82     switch( c )
83     {
84     case 'a':
85       return '4';
86     case 'z':
87       return '2';
88     case 'o':
89       return '0';
90     case 'e':
91       return '3';
92     case 'i':
93       return '1';
94     case 's':
95       return '5';
96     case 't':
97       return '7';
98     default:
99       return c_to_parse;
100     }
101   }
102 
103 } // end of namespace
104 
105 
openCommand() const106 QString NumberTextMarker::openCommand() const
107 {
108   return QLatin1String( " #" );
109 }
110 
closeCommand() const111 QString NumberTextMarker::closeCommand() const
112 {
113   return QLatin1String( "# " );
114 }
115 
openString() const116 QString NumberTextMarker::openString() const
117 {
118   return QLatin1String( " " );
119 }
120 
closeString() const121 QString NumberTextMarker::closeString() const
122 {
123   return QLatin1String( " " );
124 }
125 
initParser(const QString &)126 void NumberTextMarker::initParser( const QString& )
127 {
128   // do nothing
129 }
130 
parseString(const QString & str)131 QString NumberTextMarker::parseString( const QString& str )
132 {
133   if( str.size() == 1 )
134     return GetCharToNumber( str.at( 0 ) );
135   else
136     return str;
137 }
138 
NumberTextMarker()139 NumberTextMarker::NumberTextMarker()
140   : QObject()
141 {
142   setEnabled( true );
143   qDebug() << "NumberTextMarker plugin loaded";
144 }
145 
146 #if QT_VERSION >= 0x050000
147 Q_PLUGIN_METADATA(IID "beebeep.plugin.TextMarkerInterface/2.0")
148 #else
149 Q_EXPORT_PLUGIN2( numbertextmarker, NumberTextMarker )
150 #endif
151