diff options
Diffstat (limited to 'tderesources/tvanytime')
20 files changed, 1921 insertions, 0 deletions
diff --git a/tderesources/tvanytime/AUTHORS b/tderesources/tvanytime/AUTHORS new file mode 100644 index 000000000..05ef12ec0 --- /dev/null +++ b/tderesources/tvanytime/AUTHORS @@ -0,0 +1 @@ +Will Stephenson <wstephenson@kde.org> diff --git a/tderesources/tvanytime/COPYING b/tderesources/tvanytime/COPYING new file mode 100644 index 000000000..c13faf0dd --- /dev/null +++ b/tderesources/tvanytime/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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 + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/tderesources/tvanytime/ChangeLog b/tderesources/tvanytime/ChangeLog new file mode 100644 index 000000000..fc31a7a24 --- /dev/null +++ b/tderesources/tvanytime/ChangeLog @@ -0,0 +1,6 @@ +20050729 +Initial import. +Supports parsing and displaying BBC Backstage schedule tarballs. +Displays each channel as a subresource but requires a reload to show the +subresources in the resource list. +Takes a long time if every channel is enabled. diff --git a/tderesources/tvanytime/DESIGN b/tderesources/tvanytime/DESIGN new file mode 100644 index 000000000..874fa7cd3 --- /dev/null +++ b/tderesources/tvanytime/DESIGN @@ -0,0 +1,22 @@ +Aim: +Use Kontact as an EPG showing BBC TV and radio programs. Calendar KResource for BBC TV and radio schedules made available by the backstage.bbc.co.uk open tech portal. KResource can be used in other programs - twintv? + +DESIGN: Fetch TVAnywhere tarballs via http. Parse contents using KArchive classes and QDom API. Present channel listing from tarball in resource config so that user can control which channels are shown in resource. Use subresources to show channels. Use categories for genre descriptors? + +Set alarms for programmes? +Bookmark programmes? + +PROBLEMS: Tarball is huge. Ask about subdividing it? + +AIM: make generic TVAnywhere capable? + +Algorithm: +Read ServiceInformation. +Generate a subresource for each service +read list of enabled subresources +if null, assume bbc1, 2, 3, 4, radios 1 - 4? +for enabled subresources, generate incidences for each program +generate in-memory program information table keyed on CRID. +generate an incidence for each <ScheduleEvent> in the program location table, using the values from the PIT. + + diff --git a/tderesources/tvanytime/Makefile.am b/tderesources/tvanytime/Makefile.am new file mode 100644 index 000000000..e7c8c40d3 --- /dev/null +++ b/tderesources/tvanytime/Makefile.am @@ -0,0 +1,27 @@ +INCLUDES = -I$(top_srcdir) $(all_includes) + +lib_LTLIBRARIES = libkcal_tvanytime.la + +libkcal_tvanytime_la_SOURCES = kcal_resourcetvanytime.cpp \ + kcal_resourcetvanytimeconfig.cpp kcal_tvanytimeprefsbase.kcfgc kcal_tvanytimeprefs.cpp service.cpp + +libkcal_tvanytime_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) \ + -version-info 1:0:0 -no-undefined +libkcal_tvanytime_la_LIBADD = $(top_builddir)/libkcal/libkcal.la \ + $(top_builddir)/libtdepim/libtdepim.la + +kde_module_LTLIBRARIES = kcal_tvanytime.la + +kcal_tvanytime_la_SOURCES = kcal_resourcetvanytime_plugin.cpp +kcal_tvanytime_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kcal_tvanytime_la_LIBADD = libkcal_tvanytime.la + +kcal_servicedir = $(kde_servicesdir)/tderesources/kcal +kcal_service_DATA = kcal_tvanytime.desktop + +METASOURCES = AUTO + +messages: rc.cpp + $(EXTRACTRC) `find . -name "*.ui" -o -name "*.kcfg"` >> rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/kres_tvanytime.pot +noinst_HEADERS = service.h diff --git a/tderesources/tvanytime/README b/tderesources/tvanytime/README new file mode 100644 index 000000000..17ad628c7 --- /dev/null +++ b/tderesources/tvanytime/README @@ -0,0 +1,9 @@ +This is a KDE KResource for loading TV and radio schedule data in the TV-Anytime format into KDE applications as a calendar. + +Currently it only works with BBC schedule data as provided at http://backstage.bbc.co.uk/feeds/tvradio/ + +To use, enter the full URL of the schedule tarball you want to view from the URL above. + +(C) 2005 Will Stephenson <wstephenson@kde.org> + +supported by backstage.bbc.co.uk diff --git a/tderesources/tvanytime/TODO b/tderesources/tvanytime/TODO new file mode 100644 index 000000000..bc2d8a1f2 --- /dev/null +++ b/tderesources/tvanytime/TODO @@ -0,0 +1,9 @@ +EASY +Parse more fields (email addresses, webpages) and store as attachments. +Allow the schedule timezone to be specified in the resource config. +HARDER +Fix subresource (channel) display at first load. +Better caching to improve load times - stat the URL before fetching it. +REQUIRES PROVIDER HELP +Arrange a constant URL for the most recent data. + diff --git a/tderesources/tvanytime/kcal_resourcetvanytime.cpp b/tderesources/tvanytime/kcal_resourcetvanytime.cpp new file mode 100644 index 000000000..9de4b0d1d --- /dev/null +++ b/tderesources/tvanytime/kcal_resourcetvanytime.cpp @@ -0,0 +1,489 @@ +/* + This file is part of tdepim. + + Copyright (c) 2005 Will Stephenson <wstephenson@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kcal_resourcetvanytime.h" + +#include "kcal_tvanytimeprefsbase.h" +#include "kcal_resourcetvanytimeconfig.h" + +#include <libkcal/icalformat.h> +#include <libkcal/calendarlocal.h> +#include <libkcal/confirmsavedialog.h> + +#include <libtdepim/kpimprefs.h> + +#include <tqapplication.h> +#include <tqdom.h> +#include <tqdatetime.h> +#include <tqptrlist.h> +#include <tqregexp.h> +#include <tqstringlist.h> +#include <tqtimer.h> + +#include <kabc/locknull.h> +#include <karchive.h> +#include <kdebug.h> +#include <klocale.h> +#include <tderesources/configwidget.h> +#include <kstandarddirs.h> +#include <kstringhandler.h> +#include <ktempfile.h> +#include <ktar.h> +#include <kurl.h> + +using namespace KCal; + +ResourceTVAnytime::ResourceTVAnytime() + : ResourceCached( 0 ), mLock( true ) +{ + init(); + + mPrefs->addGroupPrefix( identifier() ); +} + +ResourceTVAnytime::ResourceTVAnytime( const TDEConfig *config ) + : ResourceCached( config ), mLock( true ) +{ + init(); + + mPrefs->addGroupPrefix( identifier() ); + + if ( config ) readConfig( config ); +} + +ResourceTVAnytime::~ResourceTVAnytime() +{ + disableChangeNotification(); + + delete mPrefs; + mPrefs = 0; +} + +void ResourceTVAnytime::init() +{ + mDownloadJob = 0; + mProgress = 0; + mDestination = 0; + + mIsShowingError = false; + + mPrefs = new TVAnytimePrefsBase(); + + setType( "tvanytime" ); + + enableChangeNotification(); + + //setReadOnly( true ); + + connect( &mResourceChangedTimer, TQT_SIGNAL( timeout() ), + this, TQT_SLOT( slotEmitResourceChanged() ) ); +} + +TVAnytimePrefsBase *ResourceTVAnytime::prefs() +{ + return mPrefs; +} + +void ResourceTVAnytime::readConfig( const TDEConfig *config ) +{ + kdDebug() << "KCal::ResourceTVAnytime::readConfig()" << endl; + + mPrefs->readConfig(); + + ResourceCached::readConfig( config ); + + TQStringList defaultActive; + defaultActive << "BBCOne" << "BBCTwo" << "BBCThree" << "BBCROne" << "BBCRTwo" << "BBCRThree" << "BBCRFour"; + mActiveServices = config->readListEntry( "ActiveServices", defaultActive ); + +} + +void ResourceTVAnytime::writeConfig( TDEConfig *config ) +{ + kdDebug() << "KCal::ResourceTVAnytime::writeConfig()" << endl; + + ResourceCalendar::writeConfig( config ); + + mPrefs->writeConfig(); + + ResourceCached::writeConfig( config ); + TQStringList activeServices; + ServiceMap::ConstIterator it; + for ( it = mServiceMap.begin(); it != mServiceMap.end(); ++it ) + if ( it.data().active() ) + activeServices.append( it.key() ); + config->writeEntry( "ActiveServices", activeServices ); +} + +bool ResourceTVAnytime::doOpen() +{ + return true; +} + +void ResourceTVAnytime::doClose() +{ + ResourceCached::doClose(); +} + +bool ResourceTVAnytime::doLoad() +{ + kdDebug() << "ResourceTVAnytime::load()" << endl; + + if ( mIsShowingError ) { + kdDebug() << "Still showing error" << endl; + return true; + } + + if ( mDownloadJob ) { + kdWarning() << "Download still in progress" << endl; + return false; + } + + mUidMap.clear(); + mCalendar.close(); + + disableChangeNotification(); + // FIXME - reenable cache + loadCache(); // TODO: default loadCache() won't set up the subresources... + enableChangeNotification(); + + emit resourceChanged( this ); + + clearChanges(); + + mDestination = new KTempFile; + KURL url( prefs()->url() ); + + KURL destination = KURL( mDestination->name() ); + + kdDebug(5850) << " SOURCE: " << url.url() << endl; + kdDebug(5850) << " DESTINATION: " << destination.url() << endl; + + // TODO: find out if the file to download is fresh. if not, just work with the cache. + mDownloadJob = TDEIO::file_copy( url, destination, -1, true ); + connect( mDownloadJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( slotJobResult( TDEIO::Job * ) ) ); + + mProgress = KPIM::ProgressManager::instance()->createProgressItem( + KPIM::ProgressManager::getUniqueID(), i18n("Downloading program schedule") ); + + connect( mProgress, + TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), + TQT_SLOT( cancelLoad() ) ); + + return true; +} + +void ResourceTVAnytime::slotJobResult( TDEIO::Job *job ) +{ + kdDebug() << "ResourceTVAnytime::slotJobResult(): " << endl; + + if ( job->error() ) { + mIsShowingError = true; + loadError( job->errorString() ); + mIsShowingError = false; + delete mDestination; + mDestination = 0; + } else { + disableChangeNotification(); + + clearCache(); + + // FIXME: This does not take into account the time zone! + + readSchedule(); + + // FIXME - reenable cache + saveCache(); + enableChangeNotification(); + + clearChanges(); + + emit resourceChanged( this ); + emit resourceLoaded( this ); + } + + mDownloadJob = 0; + if ( mProgress ) mProgress->setComplete(); + mProgress = 0; + delete mDestination; + mDestination = 0; +} + +TQDomDocument ResourceTVAnytime::archiveFileXml( const TQString & name ) +{ + TQDomDocument result; + const KArchiveDirectory *dir = mScheduleArchive->directory(); + const KArchiveEntry * entry = dir->entry( name ); + if ( entry && entry->isFile() ) + { + const KArchiveFile * file = static_cast<const KArchiveFile *>( entry ); + result.setContent( file->data() ); + } + return result; +} + +bool ResourceTVAnytime::readSchedule() +{ + TQString uncompress = "application/x-gzip"; + mScheduleArchive = new KTar( mDestination->name(), uncompress ); + mScheduleArchive->open( IO_ReadOnly ); + + TQDomDocument serviceInfo = archiveFileXml( "ServiceInformation.xml" ); + if ( !serviceInfo.isNull() ) + readServiceInformation( serviceInfo ); + + + ServiceMap::Iterator it; + // for each date in the tarball/or user preference: +#if 1 + for ( it = mServiceMap.begin(); it != mServiceMap.end(); ++it ) + { + if ( (it.data().active() ) ) + readService( it.key() ); + } +#else + TQString serviceId = "BBCOne"; + Service s = mServiceMap[ serviceId ]; + if ( s.active() ) + readService( serviceId ); +#endif + + mScheduleArchive->close(); + return true; +} + +bool ResourceTVAnytime::readServiceInformation( const TQDomDocument & serviceInfo ) +{ + kdDebug() << k_funcinfo << endl; + TQDomElement docElem = serviceInfo.documentElement(); + + TQDomNode n = docElem.firstChild(); + while( !n.isNull() ) { + TQDomElement e = n.toElement(); // try to convert the node to an element. + if( !e.isNull() && e.tagName() == "ProgramDescription" ) { + TQDomNode n2 = e.firstChild(); + TQDomElement e2 = n2.toElement(); + if( !e2.isNull() && e2.tagName() == "ServiceInformationTable" ) { + TQDomNode n3 = e2.firstChild(); + while ( !n3.isNull() ) { + Service s; + TQDomElement e3 = n3.toElement(); + if (s.loadXML( e3 ) ) { + s.setActive( mActiveServices.contains( s.id() ) ); + bool newService = !mServiceMap.contains( s.id() ); + if ( newService ) + { + mServiceMap.insert( s.id(), s ); + emit signalSubresourceAdded( this, "Calendar", s.id(), s.name() ); + } + } + else + kdDebug() << " couldn't find ServiceInformation: " << e3.tagName() << endl; + n3 = n3.nextSibling(); + } + } + else + kdDebug() << " couldn't find ServiceInformationTable: " << e2.tagName() << endl; + } + else + kdDebug() << " couldn't find ProgramDescription: " << e.tagName() << endl; + n = n.nextSibling(); + } + return true; +} + +bool ResourceTVAnytime::readService( const TQString & serviceId ) +{ + kdDebug() << k_funcinfo << endl; + // open programme information table + Service service = mServiceMap[ serviceId ]; + + TQStringList entries = mScheduleArchive->directory()->entries(); + TQRegExp re( "^(\\d{8})" + serviceId ); + TQStringList dates; + TQString todaysDate = TQDate::currentDate().toString( "yyyyMMdd" ); + for( TQStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) + { + if ( re.search( *it ) != -1 ) // this entry belongs to the requested service + { + TQString entry = re.cap( 1 ); + // handle this date according to user preferences + TQDate entryDate( entry.left( 4 ).toInt(), entry.mid( 4, 2 ).toInt(), entry.right( 2 ).toInt() ); + if ( entryDate < TQDate::currentDate() || ( entryDate > TQDate::currentDate().addDays( prefs()->days() - 1 ) ) ) + continue; + + if ( !dates.contains( re.cap( 1 ) ) ) + dates.append( re.cap( 1 ) ); + } + } + + kdDebug() << "reading schedule for " << serviceId << " on " << dates << endl; + + for( TQStringList::Iterator it = dates.begin(); it != dates.end(); ++it ) + { + ProgramInformationMap progInfoMap = service.programmeInformation(); + TQString programInfoFileName = TQString( *it + serviceId + "_pi.xml" ); + TQDomDocument programInfo = archiveFileXml( programInfoFileName ); + if ( !programInfo.isNull() ) { + TQDomElement docElem = programInfo.documentElement(); + TQDomNode n = docElem.firstChild(); + while( !n.isNull() ) { + TQDomElement e = n.toElement(); // try to convert the node to an element. + if( !e.isNull() && e.tagName() == "ProgramDescription" ) { + TQDomNode n2 = e.firstChild(); + TQDomElement e2 = n2.toElement(); + if( !e2.isNull() && e2.tagName() == "ProgramInformationTable" ) { + TQDomNode n3 = e2.firstChild(); + while ( !n3.isNull() ) { + TQDomElement e3 = n3.toElement(); + ProgramInformation pi; + if ( pi.loadXML( e3 ) ) { + //kdDebug() << "Found programme: " << pi.id() << "," << pi.title() << "," << pi.synopsis() << endl; + progInfoMap.insert( pi.id(), pi ); + } + n3 = n3.nextSibling(); + } + } + } + n = n.nextSibling(); + } + service.setProgramInformation( progInfoMap ); + } + else + kdDebug() << "Service file: " << programInfoFileName << " not found in archive" << endl; + // open programme location table, iterate and create incidences + + TQString programLocationFileName = TQString( *it + serviceId + "_pl.xml" ); + TQDomDocument programLocation = archiveFileXml( programLocationFileName ); + if ( !programLocation.isNull() ) { + TQDomElement docElem = programLocation.documentElement(); + TQDomNode n = docElem.firstChild(); + while( !n.isNull() ) { + TQDomElement e = n.toElement(); // try to convert the node to an element. + if( !e.isNull() && e.tagName() == "ProgramDescription" ) { + TQDomNode n2 = e.firstChild(); + TQDomElement e2 = n2.toElement(); + if( !e2.isNull() && e2.tagName() == "ProgramLocationTable" ) { + TQDomNode n3 = e2.firstChild(); + TQDomElement e3 = n3.toElement(); + if( !e3.isNull() && e3.tagName() == "Schedule" ) { + TQString foundServiceId = e3.attribute( "serviceIDRef" ); + if ( serviceId == foundServiceId ) { + TQDomNode n4 = e3.firstChild(); + while ( !n4.isNull() ) { + TQDomElement e4 = n4.toElement(); + ScheduleEvent se; + if ( se.loadXML( e4 ) ) { + ProgramInformation pi = progInfoMap[ se.crid() ]; + //kdDebug() << "programme incidence: " << se.crid() << "," << se.startTime() << "," << se.duration() << "," << pi.title() << "," << pi.synopsis() << endl; + KCal::Event *event = new KCal::Event(); + event->setFloats( false ); + event->setSummary( pi.title() ); + event->setDescription( pi.synopsis() ); + event->setDtStart( KPimPrefs::localTimeToUtc( se.startTime(), "Europe/London" ) ); + event->setDuration( se.duration() ); + event->setLocation( service.name() ); + event->setCategories( pi.genres() ); + event->setUid( se.programUrl() ); + event->setCustomProperty( "TVANYWHERE", "SERVICEID", serviceId ); + // store the reverse mapping from event to service, for subresources + mUidMap.insert( event->uid(), serviceId ); + event->setReadOnly( true ); + + addIncidence( event ); + } + n4 = n4.nextSibling(); + } + } + else + kdDebug() << " file contains schedule for another service!" << endl; + } + } + } + n = n.nextSibling(); + } + } + else + kdDebug() << "Program location file: " << programLocationFileName << " not found in archive" << endl; + } + return true; +} + +TQStringList ResourceTVAnytime::subresources() const +{ + //const_cast<ResourceTVAnytime*>( this )->doLoad(); + return mServiceMap.keys(); +} + +const TQString +ResourceTVAnytime::labelForSubresource( const TQString& subresource ) const +{ + Service s = mServiceMap[ subresource ]; + return s.name(); +} + +TQString ResourceTVAnytime::subresourceIdentifier( Incidence *incidence ) +{ + return incidence->customProperty( "TVANYWHERE", "SERVICEID" ); +} + +bool ResourceTVAnytime::subresourceActive( const TQString & subresource ) const +{ + Service s = mServiceMap[ subresource ]; + return s.active(); +} + +void ResourceTVAnytime::setSubresourceActive( const TQString & subresource, bool active ) +{ + if ( mServiceMap.contains( subresource ) ) + { + Service s = mServiceMap[ subresource ]; + if ( s.active() != active ) + { + s.setActive( active ); + mServiceMap.insert( subresource, s ); + doLoad(); + mResourceChangedTimer.changeInterval( 150 ); + } + } +} + +KABC::Lock *ResourceTVAnytime::lock() +{ + return &mLock; +} + +void ResourceTVAnytime::cancelLoad() +{ + if ( mDownloadJob ) mDownloadJob->kill(); + mDownloadJob = 0; + if ( mProgress ) mProgress->setComplete(); + mProgress = 0; +} + +void ResourceTVAnytime::slotEmitResourceChanged() +{ + emit resourceChanged( this ); + mResourceChangedTimer.stop(); +} + +#include "kcal_resourcetvanytime.moc" diff --git a/tderesources/tvanytime/kcal_resourcetvanytime.h b/tderesources/tvanytime/kcal_resourcetvanytime.h new file mode 100644 index 000000000..1c8bd9c90 --- /dev/null +++ b/tderesources/tvanytime/kcal_resourcetvanytime.h @@ -0,0 +1,130 @@ + /* + This file is part of tdepim. + + Copyright (c) 2005 Will Stephenson <wstephenson@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KCAL_RESOURCETVANYTIME_H +#define KCAL_RESOURCETVANYTIME_H + +#include <tqtimer.h> + +#include <libtdepim/progressmanager.h> + +#include <libkcal/resourcecached.h> + +#include <kabc/locknull.h> +#include <kio/job.h> +#include <kconfig.h> +#include <tdepimmacros.h> + +#include "service.h" + +class TQDomDocument; +class KTar; +class KTempFile; + +typedef TQMap< TQString, Service > ServiceMap; +typedef TQMap< TQString, TQString > UidMap; + +namespace KCal { + +class TVAnytimePrefsBase; + +/** + This class provides a resource for accessing a BBC TV and radio schedule as a calendar. +*/ +class KDE_EXPORT ResourceTVAnytime : public ResourceCached +{ + Q_OBJECT + + + public: + ResourceTVAnytime(); + + ResourceTVAnytime( const TDEConfig * ); + virtual ~ResourceTVAnytime(); + + void readConfig( const TDEConfig *config ); + void writeConfig( TDEConfig *config ); + + TVAnytimePrefsBase *prefs(); + + TQStringList subresources() const; + const TQString labelForSubresource( const TQString& subresource ) const; + TQString subresourceIdentifier( Incidence *incidence ); + /** Is this subresource active? */ + bool subresourceActive( const TQString& ) const; + /** (De)activate the subresource */ + virtual void setSubresourceActive( const TQString &, bool ); + + bool doOpen(); + void doClose(); + + bool doLoad(); + bool doSave() { return true; } + + KABC::Lock *lock(); + + protected: + void init(); + /** + * Extract the XML from the given filename within the schedule archive + */ + TQDomDocument archiveFileXml( const TQString & name ); + + /** + * Read the tv schedule from the tarball downloaded to mDestination + */ + bool readSchedule(); + + /** + * Read the service information map from the supplied xml + */ + bool readServiceInformation( const TQDomDocument & ); + bool readServices() { return true; } + bool readService( const TQString & serviceId ); + bool readProgrammeInformation( const TQDomDocument & ); + + protected slots: + void slotJobResult( TDEIO::Job * ); + void cancelLoad(); + void slotEmitResourceChanged(); + + private: + TVAnytimePrefsBase *mPrefs; + KABC::LockNull mLock; + + TDEIO::FileCopyJob *mDownloadJob; + KPIM::ProgressItem *mProgress; + + bool mIsShowingError; + + TQTimer mResourceChangedTimer; + KTempFile * mDestination; + KTar * mScheduleArchive; + + ServiceMap mServiceMap; + UidMap mUidMap; + //TODO: read this from subresource config + TQStringList mActiveServices; + +}; + +} + +#endif diff --git a/tderesources/tvanytime/kcal_resourcetvanytime_plugin.cpp b/tderesources/tvanytime/kcal_resourcetvanytime_plugin.cpp new file mode 100644 index 000000000..9ff0ae752 --- /dev/null +++ b/tderesources/tvanytime/kcal_resourcetvanytime_plugin.cpp @@ -0,0 +1,40 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kcal_resourcetvanytime.h" +#include "kcal_resourcetvanytimeconfig.h" +#include <kglobal.h> +#include <klocale.h> + +using namespace KCal; + +typedef KRES::PluginFactory< ResourceTVAnytime, ResourceTVAnytimeConfig > TVAnytimeFactory; +// FIXME: Use K_EXPORT_COMPONENT_FACTORY( kcal_tvanytime, TVAnytimeFactory ); here +// Problem: How do I insert the catalogue??? +extern "C" +{ + void *init_kcal_tvanytime() + { + TDEGlobal::locale()->insertCatalogue( "libkcal" ); + TDEGlobal::locale()->insertCatalogue( "kres_tvanytime" ); + return new TVAnytimeFactory; + } +} diff --git a/tderesources/tvanytime/kcal_resourcetvanytimeconfig.cpp b/tderesources/tvanytime/kcal_resourcetvanytimeconfig.cpp new file mode 100644 index 000000000..f9ec2a499 --- /dev/null +++ b/tderesources/tvanytime/kcal_resourcetvanytimeconfig.cpp @@ -0,0 +1,97 @@ +/* + This file is part of tdepim. + + Copyright (c) 2005 Will Stephenson <wstephenson@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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 <typeinfo> + +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqspinbox.h> +#include <tqwhatsthis.h> + +#include <kconfigskeleton.h> +#include <klocale.h> +#include <kdebug.h> +//#include <kdialogbase.h> +//#include <kstandarddirs.h> +#include <klineedit.h> + +#include <libkcal/resourcecachedconfig.h> + +#include "kcal_resourcetvanytime.h" +#include "kcal_tvanytimeprefs.h" +#include "kcal_resourcetvanytimeconfig.h" + +using namespace KCal; + +ResourceTVAnytimeConfig::ResourceTVAnytimeConfig( TQWidget* parent, const char* name ) + : KRES::ConfigWidget( parent, name ) +{ + resize( 245, 115 ); + TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2 ); + + TQLabel *label = new TQLabel( i18n( "Schedule tarball URL:" ), this ); + mainLayout->addWidget( label, 1, 0 ); + mUrl = new KLineEdit( this ); + mainLayout->addWidget( mUrl, 1, 1 ); + label = new TQLabel( i18n( "Retrieve how many days?" ), this ); + mainLayout->addWidget( label, 2, 0 ); + mDays = new TQSpinBox( this ); + mainLayout->addWidget( mDays, 2, 1 ); + mReloadConfig = new KCal::ResourceCachedReloadConfig( this ); + mainLayout->addMultiCellWidget( mReloadConfig, 3, 3, 0, 1 ); + +} + +void ResourceTVAnytimeConfig::loadSettings( KRES::Resource *resource ) +{ + kdDebug() << "KCal::ResourceTVAnytimeConfig::loadSettings()" << endl; + ResourceTVAnytime *res = static_cast<ResourceTVAnytime *>( resource ); + mResource = res; + + if ( res ) { + if ( !res->prefs() ) { + kdError() << "No PREF" << endl; + return; + } + TDEConfigSkeleton::ItemInt * daysItem = res->prefs()->daysItem(); + mDays->setMinValue( daysItem->minValue().toInt() ); + mDays->setMaxValue( daysItem->maxValue().toInt() ); + TQWhatsThis::add( mDays, daysItem->whatsThis() ); + mUrl->setText( res->prefs()->url() ); + mDays->setValue( res->prefs()->days() ); + mReloadConfig->loadSettings( res ); + } else { + kdError(5700) << "KCalResourceTVAnytimeConfig::loadSettings(): no KCalResourceTVAnytime, cast failed" << endl; + } +} + +void ResourceTVAnytimeConfig::saveSettings( KRES::Resource *resource ) +{ + ResourceTVAnytime *res = static_cast<ResourceTVAnytime*>( resource ); + if ( res ) { + res->prefs()->setUrl( mUrl->text() ); + res->prefs()->setDays( mDays->value() ); + mReloadConfig->saveSettings( res ); + } else { + kdError(5700) << "KCalResourceTVAnytimeConfig::saveSettings(): no KCalResourceTVAnytime, cast failed" << endl; + } +} + +#include "kcal_resourcetvanytimeconfig.moc" diff --git a/tderesources/tvanytime/kcal_resourcetvanytimeconfig.h b/tderesources/tvanytime/kcal_resourcetvanytimeconfig.h new file mode 100644 index 000000000..c99e86e09 --- /dev/null +++ b/tderesources/tvanytime/kcal_resourcetvanytimeconfig.h @@ -0,0 +1,62 @@ +/* + This file is part of tdepim. + + Copyright (c) 2005 Will Stephenson <wstephenson@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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 KCALRESOURCETVANYTIMECONFIG_H +#define KCALRESOURCETVANYTIMECONFIG_H + +#include <kurlrequester.h> +#include <tdepimmacros.h> + +#include <tderesources/resource.h> +#include <tderesources/configwidget.h> + +class TQSpinBox; +class KLineEdit; + +namespace KCal { + +class ResourceCachedReloadConfig; +class ResourceCachedSaveConfig; + +/** + Configuration widget for TVAnytime resource. + @see KCal::ResourceTVAnytime +*/ +class KDE_EXPORT ResourceTVAnytimeConfig : public KRES::ConfigWidget +{ +Q_OBJECT + + public: + ResourceTVAnytimeConfig( TQWidget *parent = 0, const char *name = 0 ); + + public slots: + virtual void loadSettings( KRES::Resource *resource ); + virtual void saveSettings( KRES::Resource *resource ); + + private: + KLineEdit *mUrl; + TQSpinBox *mDays; + ResourceCachedReloadConfig *mReloadConfig; + ResourceCachedSaveConfig *mSaveConfig; + ResourceTVAnytime *mResource; +}; + +} + +#endif diff --git a/tderesources/tvanytime/kcal_tvanytime.desktop b/tderesources/tvanytime/kcal_tvanytime.desktop new file mode 100644 index 000000000..9f6eef3c2 --- /dev/null +++ b/tderesources/tvanytime/kcal_tvanytime.desktop @@ -0,0 +1,51 @@ +[Desktop Entry] +Name=TV Schedules +Name[af]=TV skedules +Name[ar]=جداول التلفزة +Name[bg]=Разписание на ТВ +Name[ca]=Programació de la TV +Name[cs]=TV programy +Name[da]=Tv-oversigt +Name[de]=Fernsehprogramm +Name[el]=Προγράμματα τηλεόρασης +Name[es]=Programación de TV +Name[et]=Telekavad +Name[eu]=TB planifikazioak +Name[fa]=زمانبندیهای تلویزیون +Name[fi]=TV-ohjelmat +Name[fr]=Programmes TV +Name[fy]=Televissjeprogrammearring +Name[ga]=Sceidil Teilifíse +Name[gl]=Programación de TV +Name[hu]=TV-műsorok +Name[is]=Sjónvarpsdagskrár +Name[it]=Programmi TV +Name[ja]=TV 番組予定 +Name[ka]=ტელეპროგრამა +Name[kk]=TV кестелері +Name[km]=កាលវិភាគទូរទស្សន៍ +Name[lt]=TV tvarkaraščiai +Name[mk]=ТВ програми +Name[nb]=TV-program +Name[nds]=Feernsehprogramm +Name[ne]=टीभी कार्यतालिका +Name[nl]=Televisieprogrammering +Name[nn]=TV-program +Name[pl]=Program telewizyjny +Name[pt]=Programação de TV +Name[pt_BR]=Horários de TV +Name[ru]=Программы телепередач +Name[sk]=TV programy +Name[sl]=TV spored +Name[sr]=ТВ програм +Name[sr@Latn]=TV program +Name[sv]=Tv-tablåer +Name[tr]=TV Programı +Name[uk]=Програма телебачення +Name[zh_CN]=电视日程安排 +Name[zh_TW]=電視時刻表 +X-TDE-Library=kcal_tvanytime +Type=Service +ServiceTypes=KResources/Plugin +X-TDE-ResourceFamily=calendar +X-TDE-ResourceType=tvschedule diff --git a/tderesources/tvanytime/kcal_tvanytimeprefs.cpp b/tderesources/tvanytime/kcal_tvanytimeprefs.cpp new file mode 100644 index 000000000..26f3f7ef3 --- /dev/null +++ b/tderesources/tvanytime/kcal_tvanytimeprefs.cpp @@ -0,0 +1,33 @@ +/* + This file is part of KDE. + + Copyright (c) 2005 Will Stephenson <wstephenson@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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 "kcal_tvanytimeprefs.h" + +using namespace KCal; + +TVAnytimePrefs::TVAnytimePrefs() + : TVAnytimePrefsBase() +{ +} + +TQString TVAnytimePrefs::scheduleUrl() const +{ + return url(); +} diff --git a/tderesources/tvanytime/kcal_tvanytimeprefs.h b/tderesources/tvanytime/kcal_tvanytimeprefs.h new file mode 100644 index 000000000..2ab10802e --- /dev/null +++ b/tderesources/tvanytime/kcal_tvanytimeprefs.h @@ -0,0 +1,37 @@ +/* + This file is part of KDE. + + Copyright (c) 2005 Will Stephenson <wstephenson@kde.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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 TVANYTIMEPREFS_H +#define TVANYTIMEPREFS_H + +#include "kcal_tvanytimeprefsbase.h" + +namespace KCal { + +class TVAnytimePrefs : public TVAnytimePrefsBase +{ + public: + TVAnytimePrefs(); + + TQString scheduleUrl() const; +}; + +} + +#endif diff --git a/tderesources/tvanytime/kcal_tvanytimeprefsbase.kcfgc b/tderesources/tvanytime/kcal_tvanytimeprefsbase.kcfgc new file mode 100644 index 000000000..6693e4148 --- /dev/null +++ b/tderesources/tvanytime/kcal_tvanytimeprefsbase.kcfgc @@ -0,0 +1,11 @@ +# Code generation options for kconfig_compiler +File=tderesources_kcal_tvanytime.kcfg +ClassName=TVAnytimePrefsBase +NameSpace=KCal +Singleton=false +Mutators=true +Inherits=KResourcePrefs +IncludeFiles=libtdepim/kresourceprefs.h +GlobalEnums=true +ItemAccessors=true +SetUserTexts=true diff --git a/tderesources/tvanytime/service.cpp b/tderesources/tvanytime/service.cpp new file mode 100644 index 000000000..f713f7b18 --- /dev/null +++ b/tderesources/tvanytime/service.cpp @@ -0,0 +1,224 @@ +/*************************************************************************** + * Copyright (C) 2005 by Will Stephenson * + * wstephenson@kde.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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 "service.h" + +Service::Service() : mActive( true ) +{ + +} + +Service::Service( bool active, const TQString & name, const TQString & owner, const KURL & serviceUrl, const KURL & logo, const TQStringList & genres ) +: mActive( active ), mName( name ), mOwner( owner ), mServiceUrl( serviceUrl ), mLogo( logo ), mGenres( genres ) +{ +} + +void Service::setActive( bool active ) +{ + mActive = active; +} + +void Service::setName( const TQString & name ) +{ + mName = name; +} + +void Service::setProgramInformation( const ProgramInformationMap & map ) +{ + mProgInfo = map; +} + +bool Service::active() const +{ + return mActive; +} + +TQString Service::name() const +{ + return mName; +} + +bool Service::loadXML( const TQDomElement & top ) +{ + if ( top.tagName() != "ServiceInformation" ) { + tqWarning( "XML error: Top tag was %s instead of the expected service information", + top.tagName().ascii() ); + return false; + } + + setId( top.attribute( "serviceId" ) ); + + for ( TQDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement e = n.toElement(); + loadAttribute( e ); + } else + tqWarning( "Node is not a comment or an element???" ); + } + return true; +} + +bool Service::loadAttribute( const TQDomElement& element ) +{ + TQString tagName = element.tagName(); + if ( tagName == "Name" ) { + TQDomNode cn = element.firstChild(); + TQDomText t = cn.toText(); + mName = t.data(); + } + else if ( tagName == "Owner" ) { + TQDomNode cn = element.firstChild(); + TQDomText t = cn.toText(); + mOwner = t.data(); + } + else if ( tagName == "ServiceURL" ) { + TQDomNode cn = element.firstChild(); + TQDomText t = cn.toText(); + mServiceUrl = t.data(); + } + // TODO: parse logo data + // TODO: parse genre data + return true; +} + +TQRegExp ScheduleEvent::sRegExp( "PT(\\d{2})H(\\d{2})M(\\d{2})S" ); + +bool ScheduleEvent::loadXML( const TQDomElement & top ) +{ + if ( top.tagName() != "ScheduleEvent" ) { + tqWarning( "XML error: Top tag was %s instead of the expected event", + top.tagName().ascii() ); + return false; + } + + mCrid = top.attribute( "serviceId" ); + + for ( TQDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement e = n.toElement(); + loadAttribute( e ); + } else + tqWarning( "Node is not a comment or an element???" ); + } + return true; +} + +bool ScheduleEvent::loadAttribute( const TQDomElement& element ) +{ + TQString tagName = element.tagName(); + if ( tagName == "ProgramURL" ) { + TQDomNode cn = element.firstChild(); + TQDomText t = cn.toText(); + mUrl = t.data(); + } + else if ( tagName == "Program" ) { + mCrid = element.attribute( "crid" ); + } + else if ( tagName == "PublishedStartTime" ) { + TQDomNode cn = element.firstChild(); + TQDomText t = cn.toText(); + mStartTime = TQDateTime::fromString( t.data(), TQt::ISODate ); + } + else if ( tagName == "PublishedDuration" ) { + TQDomNode cn = element.firstChild(); + TQDomText t = cn.toText(); + TQString duration = t.data(); + if ( sRegExp.search( duration ) != -1 ) + { + mDuration = 0; + mDuration += 60 * 60 * sRegExp.cap( 1 ).toUInt(); + mDuration += 60 * sRegExp.cap( 2 ).toUInt(); + mDuration += sRegExp.cap( 3 ).toUInt(); + } + } + return true; +} + +ProgramInformationMap Service::programmeInformation() const +{ + return mProgInfo; +} + +ProgramInformation::ProgramInformation( const TQString & title, const TQString &synopsis ) +: mTitle( title ), mSynopsis( synopsis ) +{ + +} + +bool ProgramInformation::loadXML( const TQDomElement & top ) +{ + if ( top.tagName() != "ProgramInformation" ) { + tqWarning( "XML error: Top tag was %s instead of the expected program information", + top.tagName().ascii() ); + return false; + } + + setId( top.attribute( "programId" ) ); + + for ( TQDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement e = n.toElement(); + if ( e.tagName() == "BasicDescription" ) + { + for ( TQDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement e = n.toElement(); + loadAttribute( e ); + } + } + } + } else + tqWarning( "Node is not a comment or an element???" ); + } + return true; +} + +bool ProgramInformation::loadAttribute( const TQDomElement& element ) +{ + TQString tagName = element.tagName(); + if ( tagName == "Title" ) { + TQDomNode cn = element.firstChild(); + TQDomText t = cn.toText(); + mTitle = t.data(); + } + else if ( tagName == "Synopsis" ) { + TQDomNode cn = element.firstChild(); + TQDomText t = cn.toText(); + mSynopsis = t.data(); + } + else if ( tagName == "Genre" ) { + TQDomNode name = element.firstChild(); + TQDomElement nameElem = name.toElement(); + if ( nameElem.tagName() == "Name" ) { + TQDomNode cn = nameElem.firstChild(); + TQDomText t = cn.toText(); + mGenres.append( t.data() ); + } + } + return true; +} diff --git a/tderesources/tvanytime/service.h b/tderesources/tvanytime/service.h new file mode 100644 index 000000000..78570fe1f --- /dev/null +++ b/tderesources/tvanytime/service.h @@ -0,0 +1,111 @@ +/*************************************************************************** + * Copyright (C) 2005 by Will Stephenson * + * wstephenson@kde.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * 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 SERVICE_H +#define SERVICE_H + +#include <tqdatetime.h> +#include <tqdom.h> +#include <tqmap.h> +#include <tqregexp.h> +#include <tqstring.h> +#include <tqstringlist.h> +#include <kurl.h> + + +class ProgramInformation { + public: + ProgramInformation() {} + ProgramInformation( const TQString & title, const TQString &synopsis ); + virtual ~ProgramInformation() {} + + TQString id() const { return mId; } + TQString title() const { return mTitle; } + TQString synopsis() const { return mSynopsis; } + TQStringList genres() const { return mGenres; } + + void setId ( const TQString & id ) { mId = id; } + void setGenres( const TQStringList & genres ) { mGenres = genres; } + bool loadXML( const TQDomElement & ); + bool loadAttribute( const TQDomElement& element ); + + private: + TQString mId; + TQString mTitle; + TQString mSynopsis; + TQStringList mGenres; +}; + +typedef TQMap< TQString, ProgramInformation > ProgramInformationMap; + +class ScheduleEvent { + public: + ScheduleEvent() {} + virtual ~ScheduleEvent() {} + + TQString crid() const { return mCrid; } + TQDateTime startTime() const { return mStartTime; } + uint duration() const { return mDuration; } + TQString programUrl() const { return mUrl; } + + bool loadXML( const TQDomElement & ); + bool loadAttribute( const TQDomElement& element ); + + private: + TQString mCrid; + TQString mUrl; + TQDateTime mStartTime; + uint mDuration; + + static TQRegExp sRegExp; +}; + +class Service { + public: + Service(); + Service( bool active, const TQString & name, const TQString & owner, const KURL & serviceUrl, const KURL & logo, const TQStringList & genres ); + virtual ~Service() {} + + void setId( const TQString & id ) { mId = id; } + void setActive( bool active ); + void setName( const TQString& name ); + void setProgramInformation( const ProgramInformationMap & map ); + + TQString id() const { return mId; } + bool active() const; + TQString name() const; + ProgramInformationMap programmeInformation() const; + + bool loadXML( const TQDomElement & ); + bool loadDescription( const TQDomElement & ); + bool loadAttribute( const TQDomElement& element ); + + private: + TQString mId; + bool mActive; + TQString mName; + TQString mOwner; + KURL mServiceUrl; + KURL mLogo; + TQStringList mGenres; + ProgramInformationMap mProgInfo; +}; + +#endif diff --git a/tderesources/tvanytime/tderesources_kcal_tvanytime.kcfg b/tderesources/tvanytime/tderesources_kcal_tvanytime.kcfg new file mode 100644 index 000000000..5140468d7 --- /dev/null +++ b/tderesources/tvanytime/tderesources_kcal_tvanytime.kcfg @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 + http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > + <kcfgfile name="tderesources_kcal_bbcschedulerc" /> + <group name="General" > + <entry key="Url" type="String" > + <label>Schedule URL</label> + <whatsthis>URL of TV AnyWhere schedule</whatsthis> + </entry> + <entry key="Days" type="Int" > + <label>How many days?</label> + <whatsthis>Show the next n days</whatsthis> + <min>1</min> + <default>3</default> + <max>7</max> + </entry> + </group> +</kcfg> diff --git a/tderesources/tvanytime/tvanytime.tdevelop b/tderesources/tvanytime/tvanytime.tdevelop new file mode 100644 index 000000000..4359032fb --- /dev/null +++ b/tderesources/tvanytime/tvanytime.tdevelop @@ -0,0 +1,202 @@ +<?xml version = '1.0'?> +<tdevelop> + <general> + <author>Will Stephenson</author> + <email>wstephenson@kde.org</email> + <version>0.1</version> + <projectmanagement>KDevKDEAutoProject</projectmanagement> + <primarylanguage>C++</primarylanguage> + <keywords> + <keyword>C++</keyword> + <keyword>Code</keyword> + <keyword>Qt</keyword> + <keyword>KDE</keyword> + </keywords> + <versioncontrol>kdevsubversion</versioncontrol> + <ignoreparts/> + <projectdirectory>.</projectdirectory> + <absoluteprojectpath>false</absoluteprojectpath> + <description/> + </general> + <kdevautoproject> + <general> + <activetarget>libkcal_tvanytime.la</activetarget> + <useconfiguration>debug</useconfiguration> + </general> + <run> + <mainprogram>src/tvanytime</mainprogram> + <directoryradio>executable</directoryradio> + </run> + <configurations> + <optimized> + <builddir>optimized</builddir> + <ccompiler>kdevgccoptions</ccompiler> + <cxxcompiler>kdevgppoptions</cxxcompiler> + <f77compiler>kdevg77options</f77compiler> + <cxxflags>-O2 -g0</cxxflags> + </optimized> + <debug> + <configargs>--enable-debug=full</configargs> + <builddir>/space/kde/svn/head/build/tdepim/tderesources/tvanytime</builddir> + <ccompiler>kdevgccoptions</ccompiler> + <cxxcompiler>kdevgppoptions</cxxcompiler> + <f77compiler>kdevg77options</f77compiler> + <cxxflags>-O0 -g3</cxxflags> + <envvars/> + <topsourcedir>/space/kde/svn/head/src/tdepim/tderesources/tvanytime</topsourcedir> + <cppflags/> + <ldflags/> + <ccompilerbinary/> + <cxxcompilerbinary/> + <f77compilerbinary/> + <cflags/> + <f77flags/> + </debug> + </configurations> + <make> + <envvars> + <envvar value="1" name="WANT_AUTOCONF_2_5" /> + <envvar value="1" name="WANT_AUTOMAKE_1_6" /> + </envvars> + <abortonerror>true</abortonerror> + <numberofjobs>1</numberofjobs> + <dontact>false</dontact> + <makebin>unsermake </makebin> + <prio>0</prio> + </make> + </kdevautoproject> + <kdevfileview> + <groups> + <group pattern="*.cpp;*.cxx;*.h" name="Sources" /> + <group pattern="*.ui" name="User Interface" /> + <group pattern="*.png" name="Icons" /> + <group pattern="*.po;*.ts" name="Translations" /> + <group pattern="*" name="Others" /> + <hidenonprojectfiles>false</hidenonprojectfiles> + <hidenonlocation>false</hidenonlocation> + </groups> + <tree> + <hidepatterns>*.o,*.lo,CVS</hidepatterns> + <hidenonprojectfiles>false</hidenonprojectfiles> + </tree> + </kdevfileview> + <kdevdoctreeview> + <ignoretocs> + <toc>ada</toc> + <toc>ada_bugs_gcc</toc> + <toc>bash</toc> + <toc>bash_bugs</toc> + <toc>clanlib</toc> + <toc>w3c-dom-level2-html</toc> + <toc>fortran_bugs_gcc</toc> + <toc>gnome1</toc> + <toc>gnustep</toc> + <toc>gtk</toc> + <toc>gtk_bugs</toc> + <toc>haskell</toc> + <toc>haskell_bugs_ghc</toc> + <toc>java_bugs_gcc</toc> + <toc>java_bugs_sun</toc> + <toc>pascal_bugs_fp</toc> + <toc>php</toc> + <toc>php_bugs</toc> + <toc>perl</toc> + <toc>perl_bugs</toc> + <toc>python</toc> + <toc>python_bugs</toc> + <toc>ruby</toc> + <toc>ruby_bugs</toc> + <toc>sdl</toc> + <toc>w3c-svg</toc> + <toc>sw</toc> + <toc>w3c-uaag10</toc> + <toc>wxwidgets_bugs</toc> + </ignoretocs> + <ignoreqt_xml> + <toc>qmake User Guide</toc> + </ignoreqt_xml> + </kdevdoctreeview> + <kdevdebugger> + <general> + <dbgshell>libtool</dbgshell> + <programargs/> + <gdbpath/> + <configGdbScript/> + <runShellScript/> + <runGdbScript/> + <breakonloadinglibs>true</breakonloadinglibs> + <separatetty>false</separatetty> + <floatingtoolbar>false</floatingtoolbar> + </general> + <display> + <staticmembers>false</staticmembers> + <demanglenames>true</demanglenames> + <outputradix>10</outputradix> + </display> + </kdevdebugger> + <kdevfilecreate> + <filetypes/> + <useglobaltypes> + <type ext="ui" /> + <type ext="cpp" /> + <type ext="h" /> + </useglobaltypes> + </kdevfilecreate> + <kdevdocumentation> + <projectdoc> + <docsystem>Doxygen Documentation Collection</docsystem> + <docurl>tvanytime.tag</docurl> + </projectdoc> + </kdevdocumentation> + <substmap> + <APPNAME>tvanytime</APPNAME> + <APPNAMELC>tvanytime</APPNAMELC> + <APPNAMESC>Bbcschedule</APPNAMESC> + <APPNAMEUC>BBCSCHEDULE</APPNAMEUC> + <AUTHOR>Will Stephenson</AUTHOR> + <EMAIL>wstephenson@kde.org</EMAIL> + <LICENSE>GPL</LICENSE> + <LICENSEFILE>COPYING</LICENSEFILE> + <VERSION>0.1</VERSION> + <YEAR>2005</YEAR> + <dest>/space/kde/head/src/tdepim/tderesources/tvanytime</dest> + </substmap> + <kdevcppsupport> + <references> + <pcs>tdelibs</pcs> + <pcs>project</pcs> + <pcs>libkcal</pcs> + </references> + <codecompletion> + <includeGlobalFunctions>true</includeGlobalFunctions> + <includeTypes>true</includeTypes> + <includeEnums>true</includeEnums> + <includeTypedefs>false</includeTypedefs> + <automaticCodeCompletion>true</automaticCodeCompletion> + <automaticArgumentsHint>true</automaticArgumentsHint> + <automaticHeaderCompletion>true</automaticHeaderCompletion> + <codeCompletionDelay>250</codeCompletionDelay> + <argumentsHintDelay>400</argumentsHintDelay> + <headerCompletionDelay>250</headerCompletionDelay> + </codecompletion> + <qt> + <used>false</used> + <version>3</version> + <root>/usr/lib/qt3</root> + </qt> + <creategettersetter> + <prefixGet/> + <prefixSet>set</prefixSet> + <prefixVariable>m_,_</prefixVariable> + <parameterName>theValue</parameterName> + <inlineGet>true</inlineGet> + <inlineSet>true</inlineSet> + </creategettersetter> + </kdevcppsupport> + <cppsupportpart> + <filetemplates> + <interfacesuffix>.h</interfacesuffix> + <implementationsuffix>.cpp</implementationsuffix> + </filetemplates> + </cppsupportpart> +</tdevelop> |