File indexing completed on 2024-04-21 15:08:18

0001 //
0002 // C++ Implementation: caliaslist
0003 //
0004 // Description: 
0005 //
0006 /*
0007 Copyright 2002-2011 Tomas Mecir <kmuddy@kmuddy.com>
0008 
0009 This program is free software; you can redistribute it and/or
0010 modify it under the terms of the GNU General Public License as
0011 published by the Free Software Foundation; either version 2 of 
0012 the License, or (at your option) any later version.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #include "caliaslist.h"
0024 
0025 #include "calias.h"
0026 #include "caliaseditor.h"
0027 #include "cpattern.h"
0028 
0029 #include <QStringList>
0030 
0031 struct cAliasList::Private {
0032   QString stringToMatch;
0033   bool sendOriginal, matched;
0034   QStringList commandsToExec;
0035 };
0036 
0037 cAliasList::cAliasList () :
0038     cList ("aliases")
0039 {
0040   // create properties
0041   addStringProperty ("pattern", "Matching pattern");
0042   addIntProperty ("newtext-count", "Replacement line count", 0);
0043   // then we have a "newtext-"+i string for each
0044   addIntProperty ("matching", "Comparison type", int(cPattern::begin));
0045   addBoolProperty ("cs", "Case sensitive", true);
0046   addBoolProperty ("prefix-suffix", "Include prefix/suffix", true);
0047   addBoolProperty ("orig", "Send original", false);
0048   addBoolProperty ("whole-words", "Whole words", true);
0049   addBoolProperty ("global", "Global matching", false);
0050   addStringProperty ("condition", "Matching condition");
0051 
0052   // script
0053   addStringProperty ("script", "Script to execute");
0054 
0055   d = new Private;
0056 }
0057 
0058 cAliasList::~cAliasList ()
0059 {
0060   delete d;
0061 }
0062 
0063 cListObject *cAliasList::newObject ()
0064 {
0065   return new cAlias (this);
0066 }
0067 
0068 cListEditor *cAliasList::editor (QWidget *parent)
0069 {
0070   return new cAliasEditor (parent);
0071 }
0072 
0073 bool cAliasList::matchString (const QString &string)
0074 {
0075   d->sendOriginal = false;
0076   d->matched = false;
0077   d->stringToMatch = string;
0078   d->commandsToExec.clear ();
0079 
0080   // traverse the structure
0081   traverse (ALIAS_MATCH);
0082 
0083   if (d->sendOriginal)
0084     d->commandsToExec.prepend (string);
0085 
0086   return d->matched;
0087 }
0088 
0089 QStringList cAliasList::commandsToExec ()
0090 {
0091   return d->commandsToExec;
0092 }
0093 
0094 QString cAliasList::stringToMatch ()
0095 {
0096   return d->stringToMatch;
0097 }
0098   
0099 void cAliasList::wantOriginalCommand ()
0100 {
0101   d->sendOriginal = true;
0102 }
0103 
0104 void cAliasList::setMatched ()
0105 {
0106   d->matched = true;
0107 }
0108 
0109 void cAliasList::addCommand (const QString &command)
0110 {
0111   d->commandsToExec << command;
0112 }
0113