diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2013-09-03 20:02:55 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2013-09-03 21:02:00 +0200 |
commit | 533bad2a1503973aaf8186691422c2eda91d02d4 (patch) | |
tree | f7e52f62416048859aa9bde8425e20aac0e7c669 /tdeabc/tdeabc2mutt | |
parent | 8144d5434bbd1c4448a37695aed6ad3d348043d8 (diff) | |
download | tdepim-533bad2a1503973aaf8186691422c2eda91d02d4.tar.gz tdepim-533bad2a1503973aaf8186691422c2eda91d02d4.zip |
Additional k => tde renaming and fixes
Diffstat (limited to 'tdeabc/tdeabc2mutt')
-rw-r--r-- | tdeabc/tdeabc2mutt/CMakeLists.txt | 29 | ||||
-rw-r--r-- | tdeabc/tdeabc2mutt/Makefile.am | 13 | ||||
-rw-r--r-- | tdeabc/tdeabc2mutt/README | 19 | ||||
-rw-r--r-- | tdeabc/tdeabc2mutt/main.cpp | 80 | ||||
-rw-r--r-- | tdeabc/tdeabc2mutt/tdeabc2mutt.cpp | 160 | ||||
-rw-r--r-- | tdeabc/tdeabc2mutt/tdeabc2mutt.h | 57 |
6 files changed, 358 insertions, 0 deletions
diff --git a/tdeabc/tdeabc2mutt/CMakeLists.txt b/tdeabc/tdeabc2mutt/CMakeLists.txt new file mode 100644 index 000000000..035c38940 --- /dev/null +++ b/tdeabc/tdeabc2mutt/CMakeLists.txt @@ -0,0 +1,29 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### tdeabc2mutt (executable) #################### + +tde_add_executable( tdeabc2mutt AUTOMOC + SOURCES tdeabc2mutt.cpp main.cpp + LINK tdeabc-shared + DESTINATION ${BIN_INSTALL_DIR} +) diff --git a/tdeabc/tdeabc2mutt/Makefile.am b/tdeabc/tdeabc2mutt/Makefile.am new file mode 100644 index 000000000..d921711b7 --- /dev/null +++ b/tdeabc/tdeabc2mutt/Makefile.am @@ -0,0 +1,13 @@ +INCLUDES = -I$(includedir)/tdeabc $(all_includes) + +METASOURCES = AUTO + +bin_PROGRAMS = tdeabc2mutt + +tdeabc2mutt_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor +tdeabc2mutt_LDADD = -ltdeabc $(LIB_TDECORE) +tdeabc2mutt_SOURCES = tdeabc2mutt.cpp main.cpp + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/tdeabc2mutt.pot + diff --git a/tdeabc/tdeabc2mutt/README b/tdeabc/tdeabc2mutt/README new file mode 100644 index 000000000..2da528a9a --- /dev/null +++ b/tdeabc/tdeabc2mutt/README @@ -0,0 +1,19 @@ +KAbc2Mutt +----------- + +tdeabc2mutt is a small programm to make the email addresses, stored in +kaddressbook, available in mutt. +You only have to add the following line to your .muttrc + + source "tdeabc2mutt |" + +You can also configure mutt to query tdeabc2mutt when typing a substring +of an email address (see the docu for query_command). +To do this, add the following line to your .muttrc + + set query_command = "tdeabc2mutt --query '%s' --format query" + +Have fun with it + +Ciao, +Tobias diff --git a/tdeabc/tdeabc2mutt/main.cpp b/tdeabc/tdeabc2mutt/main.cpp new file mode 100644 index 000000000..0515c37d9 --- /dev/null +++ b/tdeabc/tdeabc2mutt/main.cpp @@ -0,0 +1,80 @@ +/* + KAbc2Mutt + + Copyright (c) 2003 - 2004 Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <tdeapplication.h> +#include <tdecmdlineargs.h> +#include <tdelocale.h> + +#include <iostream> + +#include "tdeabc2mutt.h" + +static const char version[] = "0.2"; +static const char appName[] = "tdeabc2mutt"; +static const char programName[] = I18N_NOOP( "tdeabc2mutt" ); +static const char description[] = I18N_NOOP( "tdeabc - mutt converter" ); + +static TDECmdLineOptions k2moptions[] = +{ + { "query <substring>", I18N_NOOP( "Only show contacts where name or address matches <substring>" ), 0 }, + { "format <format>", I18N_NOOP( "Default format is 'alias'. 'query' returns email<tab>name<tab>, as needed by mutt's query_command" ), "alias" }, + { "alternate-key-format", I18N_NOOP( "Default key format is 'JohDoe', this option turns it into 'jdoe'" ), 0 }, + { "ignore-case", I18N_NOOP( "Make queries case insensitive" ), 0 }, + { "all-addresses", I18N_NOOP( "Return all mail addresses, not just the preferred one" ), 0}, + TDECmdLineLastOption +}; + + +int main( int argc, char **argv ) +{ + TDEApplication::disableAutoDcopRegistration(); + TDECmdLineArgs::init( argc, argv, appName, programName, description, version ); + TDECmdLineArgs::addCmdLineOptions( k2moptions ); + + TDEApplication app( false, false ); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + + KABC2Mutt *object = new KABC2Mutt( 0 ); + + // Handle --format option + object->setFormat( (args->getOption("format") == "query") ? KABC2Mutt::Query : KABC2Mutt::Aliases ); + + // Handle --alternate-key-format option + object->setAlternateKeyFormat( args->isSet( "alternate-key-format" ) ); + + // Handle --all-addresses option + object->setAllAddresses( args->isSet( "all-addresses" ) ); + + // Handle --query option + const TQString subString = TQString::fromLocal8Bit( args->getOption( "query" ) ); + if ( !subString.isEmpty() ) { + // Mutt wants a first line with some status message on it + // See http://mutt.org/doc/manual/manual-4.html#ss4.5 + std::cout << i18n( "Searching KDE addressbook" ).latin1() << std::endl; + } + object->setQuery( subString ); + + // Handle --ignore-case option + object->setIgnoreCase( !args->isSet( "ignore-case" ) ); + + object->run(); + + return app.exec(); +} diff --git a/tdeabc/tdeabc2mutt/tdeabc2mutt.cpp b/tdeabc/tdeabc2mutt/tdeabc2mutt.cpp new file mode 100644 index 000000000..d36582baf --- /dev/null +++ b/tdeabc/tdeabc2mutt/tdeabc2mutt.cpp @@ -0,0 +1,160 @@ +/* + KAbc2Mutt + + Copyright (c) 2003 - 2004 Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include <tdeabc/distributionlist.h> +#include <tdeapplication.h> +#include <tdelocale.h> + +#include <tqregexp.h> + +#include <iostream> + +#include "tdeabc2mutt.h" + +static std::ostream & operator<< ( std::ostream &os, const TQString &s ); + +KABC2Mutt::KABC2Mutt( TQObject *parent, const char *name ) + : TQObject( parent, name ), mFormat( Aliases ), + mIgnoreCase( false ), mAllAddresses( false ), + mAlternateKeyFormat( false ), + mAddressBook( 0 ) +{ +} + +void KABC2Mutt::run() +{ + mAddressBook = TDEABC::StdAddressBook::self( true ); + TDEABC::StdAddressBook::setAutomaticSave( false ); + + connect( mAddressBook, TQT_SIGNAL( addressBookChanged( AddressBook* ) ), + this, TQT_SLOT( loadingFinished() ) ); +} + +void KABC2Mutt::loadingFinished() +{ + // print addressees + TDEABC::AddressBook::ConstIterator iaddr; + for ( iaddr = mAddressBook->begin(); iaddr != mAddressBook->end(); ++iaddr ) { + const TQString name = (*iaddr).givenName() + ' ' + (*iaddr).familyName(); + if ( !mQuery.isEmpty() ) { + bool match = (name.find(mQuery, 0, mIgnoreCase) > -1) || + ((*iaddr).preferredEmail().find( mQuery, 0, mIgnoreCase ) > -1 ); + if ( !match ) + continue; + } + + const TQStringList &allAddresses = (*iaddr).emails(); + TQStringList::const_iterator from, to; + bool multiple = false; + + if ( mAllAddresses ) { + // use all entries + multiple = allAddresses.size() > 1; + from = allAddresses.begin(); + to = allAddresses.end(); + } else { + // use only the first entry, the one returned by preferredEmail() + from = to = allAddresses.begin(); // start with empty list + if ( to != allAddresses.end() ) + ++to; + } + + size_t index = 0; + if ( mFormat == Aliases ) { + static const TQChar space = TQChar( ' ' ); + static const TQChar underscore = TQChar( '_' ); + + TQString key; + if ( !mAlternateKeyFormat ) + key = (*iaddr).givenName().left( 3 ) + (*iaddr).familyName().left( 3 ); + else + if ( !(*iaddr).familyName().isEmpty() ) + key = (*iaddr).givenName().left( 1 ).lower() + + (*iaddr).familyName().lower().replace( space, underscore ); + else + key = (*iaddr).givenName().lower().replace( space, underscore ); + + while ( from != to ) { + std::cout << "alias " << key; + if ( index ) + std::cout << index; + std::cout << '\t' << name << " <" << (*from) << '>' << std::endl; + ++index; + ++from; + } + + if ( !(*iaddr).nickName().isEmpty() ) { + std::cout << "alias " + << (*iaddr).nickName().lower().replace( space, underscore ) + << '\t' << name << " <" + << (*iaddr).preferredEmail() << '>' << std::endl; + } + } else { + while ( from != to ) { + std::cout << (*from) << '\t' << name; + if ( multiple ) { + if ( index ) + std::cout << "\t#" << index; + else + std::cout << '\t' << i18n( "preferred" ); + ++index; + } + std::cout << std::endl; + ++from; + } + } + } + + // print all distribution lists + TDEABC::DistributionListManager manager( mAddressBook ); + manager.load(); + + TQStringList dists = manager.listNames(); + for ( TQStringList::Iterator iaddr = dists.begin(); iaddr != dists.end(); ++iaddr ) { + TDEABC::DistributionList *list = manager.list( *iaddr ); + if ( list ) { + if ( !mQuery.isEmpty() ) { + bool match = ((*iaddr).find(mQuery) > -1); + if ( !match ) + continue; + } + + TQStringList emails = list->emails(); + if ( emails.isEmpty() ) + continue; + + if ( mFormat == Aliases ) { + std::cout << "alias " << (*iaddr).replace( TQRegExp( " " ), "_" ) + << '\t' << emails.join( "," ) << std::endl; + } else { + std::cout << emails.join( "," ) << '\t' << (*iaddr) << '\t' << std::endl; + } + } + } + + kapp->quit(); +} + +static std::ostream & operator<< ( std::ostream &os, const TQString &s ) +{ + os << s.local8Bit().data(); + return os; +} + +#include "tdeabc2mutt.moc" diff --git a/tdeabc/tdeabc2mutt/tdeabc2mutt.h b/tdeabc/tdeabc2mutt/tdeabc2mutt.h new file mode 100644 index 000000000..a0e58a598 --- /dev/null +++ b/tdeabc/tdeabc2mutt/tdeabc2mutt.h @@ -0,0 +1,57 @@ +/* + KAbc2Mutt + + Copyright (c) 2003 - 2004 Tobias Koenig <tokoe@kde.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef TDEABC2MUTT_H +#define TDEABC2MUTT_H + +#include <tdeabc/stdaddressbook.h> + +class KABC2Mutt : public TQObject +{ + Q_OBJECT + + + public: + + enum Format { Aliases, Query }; + + KABC2Mutt( TQObject *parent, const char *name = 0 ); + + void setQuery( const TQString &query ) { mQuery = query; } + void setFormat( Format format ) { mFormat = format; } + void setIgnoreCase( bool ignoreCase ) { mIgnoreCase = ignoreCase; } + void setAllAddresses( bool allAddresses ) { mAllAddresses = allAddresses; } + void setAlternateKeyFormat( bool alternateKeyFormat ) { mAlternateKeyFormat = alternateKeyFormat; } + + void run(); + + private slots: + void loadingFinished(); + + private: + TQString mQuery; + Format mFormat; + bool mIgnoreCase; + bool mAllAddresses; + bool mAlternateKeyFormat; + + TDEABC::AddressBook *mAddressBook; +}; + +#endif |