diff options
Diffstat (limited to 'konsolekalendar')
31 files changed, 4603 insertions, 0 deletions
diff --git a/konsolekalendar/COPYING b/konsolekalendar/COPYING new file mode 100644 index 000000000..54754ab4b --- /dev/null +++ b/konsolekalendar/COPYING @@ -0,0 +1,341 @@ + 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) 19yy <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) 19yy 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/konsolekalendar/HACKS b/konsolekalendar/HACKS new file mode 100644 index 000000000..e001d539a --- /dev/null +++ b/konsolekalendar/HACKS @@ -0,0 +1,9 @@ +MidnightCommander +------------------- +To see all events of the current year from a iCalendar file in the +viewer of the MidnightCommander add the following line to your +$HOME/.mc/bindings + +# iCalendar +shell/.ics + View=%view{ascii} konsolekalendar --file %f --all --startdate "`date +01.01.%%Y`" --enddate "`date +31.12.%%Y`" diff --git a/konsolekalendar/Mainpage.dox b/konsolekalendar/Mainpage.dox new file mode 100644 index 000000000..5b46a4dee --- /dev/null +++ b/konsolekalendar/Mainpage.dox @@ -0,0 +1,28 @@ +/** \mainpage %KonsoleKalendar API Overview + +\section intro Introduction + +%KonsoleKalendar is a command line interface to KDE calendars. +It lets you view, insert, remove, or modify calendar events by way of +the command line or from a scripting language. +Additionally, %KonsoleKalendar can create a new KDE calendar, +export a KDE calendar to a variety of other formats, and +import another KDE calendar. + +\section map Road Map to the Classes + +KCal::KonsoleKalendar is the base class. + +KCal::KonsoleKalendarVariables holds all the command line arguments plus some. + +KCal::KonsoleKalendarEpoch is for timestamps expressed as epochs. + +KCal::KonsoleKalendarExports manages the export functionality. + +KCal::KonsoleKalendarAdd manages the event insert capability. + +KCal::KonsoleKalendarDelete manages the event removal capability. + +KCal::KonsoleKalendarChange manages the event modification capability. + +*/ diff --git a/konsolekalendar/Makefile.am b/konsolekalendar/Makefile.am new file mode 100644 index 000000000..1fa54aa0d --- /dev/null +++ b/konsolekalendar/Makefile.am @@ -0,0 +1,26 @@ +SUBDIRS = pixmaps + +INCLUDES= -I$(top_srcdir)/libkcal \ + -I$(top_srcdir)/libemailfunctions \ + -I$(top_srcdir) $(all_includes) + +METASOURCES = AUTO + +bin_PROGRAMS = konsolekalendar + +konsolekalendar_SOURCES = konsolekalendarepoch.cpp konsolekalendardelete.cpp \ + konsolekalendarchange.cpp konsolekalendarvariables.cpp \ + konsolekalendaradd.cpp konsolekalendarexports.cpp konsolekalendar.cpp \ + stdcalendar.cpp main.cpp +konsolekalendar_LDADD = $(top_builddir)/libkcal/libkcal.la $(top_builddir)/libkdepim/libkdepim.la +konsolekalendar_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +appsdir = $(kde_appsdir)/Utilities +xdg_apps_DATA = konsolekalendar.desktop + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/konsolekalendar.pot + +include $(top_srcdir)/admin/Doxyfile.am + +konsolekalendar.o: ../libkcal/htmlexportsettings.h diff --git a/konsolekalendar/ROADMAP b/konsolekalendar/ROADMAP new file mode 100644 index 000000000..333366ec7 --- /dev/null +++ b/konsolekalendar/ROADMAP @@ -0,0 +1,20 @@ +Inner Version| | From KDE version +-------------+---------------------------------------+------------- +1.0 | Everything working now | 3.2 +1.2 | New stable version | 3.3 +1.3.1 | Make new parsing code | cvs +1.3.2 | Make new Output with macroexpander | cvs +1.3.3 | Start remove old parts of input | cvs +1.3.4 | New remote calendar support | cvs +1.3.5 | Remove old input system.. | cvs +1.3.6 | Test..test..test it baby | cvs +1.4 | Start creating outputs try to find | + | People who need these.. | cvs +1.5 | Implement possibility to execute app | cvs +1.5.1 | Do something;) +2.0 | Seek new maintainer | 4.0 + | RegExp output because everyone | + | Want to have they kind of output | + +Remember these are the highlights! There going to be plenty of other stuff. + diff --git a/konsolekalendar/TODO b/konsolekalendar/TODO new file mode 100644 index 000000000..ba4cdb625 --- /dev/null +++ b/konsolekalendar/TODO @@ -0,0 +1,3 @@ +Todo: +Make new plans + diff --git a/konsolekalendar/examples/README b/konsolekalendar/examples/README new file mode 100644 index 000000000..d770ef288 --- /dev/null +++ b/konsolekalendar/examples/README @@ -0,0 +1,8 @@ +Here are some nice example scripts how to use konsolekalendar. + + * tcm2kcal.pl + Parses TCM (Turner Classic Movies) schedule from the web site to ICS + You need lynx and the Date::Calc to use this script + (you can install Date::Calc using 'perl -MCPAN -e 'install Date::Calc') + + * testkalendar.sh is crappy test script.. diff --git a/konsolekalendar/examples/tcm2kcal.pl b/konsolekalendar/examples/tcm2kcal.pl new file mode 100755 index 000000000..1fb3be311 --- /dev/null +++ b/konsolekalendar/examples/tcm2kcal.pl @@ -0,0 +1,288 @@ +#!/usr/bin/perl -w + +# tcm2kcal.pl -- converts a Turner Classic Movies (TCM) calendar +# web page into a KDE calendar file. +############################################################################ +# Copyright (c) 2003-2004 Allen Winter <winter@kde.org> # +# All rights reserved. # +# 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 script is used to help test konsolekalendar. +# +# Modify $konkal, $cal, and $TCM as necessary for your needs. +# +# Requirements: +# lynx +# konsolekalendar (from KDE). +# Date-Calc perl module (from CPAN). +# +# Options: -d, delete entries from KDE calendar file +# -c, change entries in KDE calendar by re-writing movie titles in all caps. +# -m <month>, where month is an integer 1 thru 12 +# default is current month +# -y <year>, where year is an integer YYYY +# default is current year +# -f <file>, where file is location of output KDE calendar +# default is $HOME/.kde/share/apps/korganizer/tcm.ics +# -w <konsolekalendar> where konsolekalendar is located + +use strict; +use Env qw(HOME); +use Getopt::Std; +use Date::Calc qw(Today Month_to_Text + Add_Delta_DHMS Add_Delta_Days + Day_of_Week Day_of_Week_to_Text + Month_to_Text); + +#location of konsolekalendar program +my($konkal)="/usr/bin/konsolekalendar"; + +#location of new TCM KDE calendar +my($cal)="$HOME/.kde/share/apps/korganizer/tcm.ics"; + +#default program execution mode +my($mode)="--add"; + +#current date information +my($year,$month,$d) = Today(); + +#parse command line +&parse(); + +my($mmonth)=Month_to_Text($month); + +#location of TCM monthly calendar web page +my($TCM)="http://www.turnerclassicmovies.com/Schedule/Print/0,,$month-$year|0|,00.html"; +print "Processing $TCM ...\n"; + +if( open(GET, "lynx -dump -nolist -connect_timeout=3 '$TCM'|") ) { +} else { + die "Failed to get the TCM calendar page.\n"; +} + +if( $mode eq "--add" ) { + if( ! -r $cal ) { + if( system("$konkal --create --file $cal") ) { + print "Failure Condition Encountered. Unable to Create KDE Calendar.\n"; exit 1; + } + } +} + +my($tday,$mday); +my($day)=1; +my($lastampm)="AM"; +my($line)=""; +my($event)=""; +my($num)=0; +while($line=<GET>) { + + #prepare line + chomp($line); + $line=&rmleadwhite($line); + + #skip junk lines + next if( ! $line ); + next if( $line =~ m/^\[/ ); + next if( $line =~ m/^All Times Eastern/ ); + next if( $line =~ m/^$mmonth[[:space:]]*$year/ ); + + #start new day if line begins with a DD Sunday|Monday|...|Friday|Saturday + ($tday,$mday) = split(" ",$line); + if( $tday =~ m/^[0-9]*$/ ) { + if( $tday >= 1 && $tday <= 31 ) { + if( $mday =~ m/day$/ ) { + &process() if( $event ); +# print "New day starting: $tday $mday\n"; + $day = $tday; + $event = ""; + next; + } + } + } + + #start a new event if line begins with a HH:MM[[space]]AM|PM + if( $line =~ m/^[0-9]*:[0-9][0-9][[:space:]]*[A,P]M/ ) { + &process() if( $event ); + $event = "$line"; + } else { + $event = $event . " " . $line; + } +} + +#process remaining event, if there is one. +&process() if( $event ); + +close(GET); +print "$num movies processed\n"; + +##### END MAIN ##### + +sub rmleadwhite() { + #remove leading white space + my($x)=@_; + ($x)=~s+^[[:space:]]*++; + return($x); +} + +sub parse() { + #parse command line + + our($opt_h, $opt_d, $opt_c, $opt_m, $opt_y, $opt_f, $opt_w); + getopts('hdcm:y:f:w:'); + + $mode="--delete" if( $opt_d ); + $mode="--change" if( $opt_c ); + $month=$opt_m if( $opt_m ); + $year=$opt_y if( $opt_y ); + $cal=$opt_f if( $opt_f ); + $konkal=$opt_w if( $opt_w ); + +# if( $opt_h ) { +# print "help here!\r\n"; +# } // if + +} + +sub process() { + #remove any evil double quotes from the event string + $event =~ s/\"//g; + + ### Compute starting date + my($date) = sprintf("%4d-%02d-%02d",$year,$month,$day); + + ### Compute starting time + my($ttime,$ampm) = split(" ",$event); + my($hour,$min) = split(":",$ttime); + + # adjust the hour by am or pm + $hour += 12 if( $ampm =~ m/[Pp][Mm]/ && $hour < 12 ); + $hour -= 12 if( $ampm =~ m/[Aa][Mm]/ && $hour == 12 ); + + my($time) = sprintf("%02d:%02d",$hour,$min); + + # advance day (for the enddate) if we have moved from pm to am + if($lastampm =~ m/[Pp][Mm]/ && $ampm =~ m/[Aa][Mm]/ ) { + ($year, $month, $day) = Add_Delta_Days($year,$month, $day, 1); + } + + # format start date and time for "greping" later + my($gdate) = sprintf("\"%s %02d %s %4d\"", + Day_of_Week_to_Text(Day_of_Week($year,$month,$day)), + $day, + Month_to_Text($month), + $year); + my($ghour) = $hour; + if( $ghour == 12 ) { + $ampm = "pm"; + } + if( $ghour > 12 ) { + $ghour -= 12; + $ampm = "pm" + } + if( $ghour == 0 ) { + $ghour = 12; + $ampm = "am"; + } + my($gtime) = sprintf("\"%02d:%02d %s\"",$ghour,$min,lc($ampm)); + + ### Compute Movie End Datetime by adding Movie Duration to Start Datetime + + # derive duration + my($duration) = $event; + $duration =~ s/CC//g; + $duration =~ s/LBX//g; + $duration =~ s/DVS//g; + my(@d) = reverse(split(" ",$duration)); + $duration=$d[0]; + $duration =~ s/m\.$//g; + #print "DURATION COMPUTATION ERROR\n" if( $duration < 1 || $duration > 300); + + my($endyear,$endmonth,$endday,$endhh, $endmm, $endss) = Add_Delta_DHMS( + $year,$month,$day,$hour,$min,0, + 0, 0, $duration, 0); + # format end datetime + my($enddate) = sprintf("%4d-%02d-%02d",$endyear,$endmonth,$endday); + my($endtime) = sprintf("%02d:%02d",$endhh,$endmm); + my($genddate) = sprintf("\"%s %02d %s %4d\"", + Day_of_Week_to_Text(Day_of_Week($endyear,$endmonth,$endday)), + $endday, + Month_to_Text($endmonth), + $endyear); + $ampm = "am"; + if( $endhh == 12 ) { + $ampm = "pm"; + } + if( $endhh > 12 ) { + $endhh -= 12; + $ampm = "pm"; + } + if( $endhh == 0 ) { + $endhh = 12; + $ampm = "am"; + } + my($gendtime) = sprintf("\"%02d:%02d %s\"",$endhh,$endmm,lc($ampm)); + + # Derive Movie Title + my($tmp) = split("[)]",$event); + my($tmp2,$title) = split("^[0-9]*:[0-9][0-9][[:space:]]*[A,P]M",$tmp); + $title=&rmleadwhite($title); + $title=$title . ")"; + if( $title =~ m/\([[:space:]]\)/ ) { + print "SKIPPING MOVIE WITHOUT A TITLE\n"; + return; + } + + my($gtitle) = "\"" . $title . "\""; + + # "Grep line". + # Due to events across multiple days, search for ending date/time only. +# my($UID)=&find_uid("$gdate,$gtime,$genddate,$gendtime,$gtitle"); + my($UID)=&find_uid(",$genddate,$gendtime,$gtitle"); + + # New Title for Change Mode + $title=uc($title) if( $mode eq "--change" ); + +# print "EVENT start datetime=$date, $time, title=$title, end datetime=$enddate, $endtime, duration=$duration\n"; + $lastampm=$ampm; + + # Run konsolekalendar to insert/change/delete the event + if( system("$konkal $mode $UID --file $cal --date $date --time $time --end-date $enddate --end-time $endtime --summary \"$title\" --description \"$event\"") ) { + $mode =~ s/--//; + print "Failure Condition Encountered. Unable to $mode Event.\n"; exit 1; + } + + $num++; +} + +sub find_uid() { + + my($line); + my($grepline) = shift; + my($UID)=""; + + if( $mode ne "--add" ) { + if( open(VIEW, "$konkal --view --all --export-type csv --file $cal |") ) { + while($line=<VIEW>) { + if( index($line,$grepline) >= 0) { + my(@u) = reverse(split(",",$line)); + chomp($u[0]); + $UID="--uid=$u[0]"; + last; + } + } + if( $UID eq "" ) { + print "Failure Condition Encoutered. Unable to locate Event $grepline in calendar.\n"; exit 1; + } + } else { + die "Failed to view cal $cal.\n"; + } + close(VIEW); + } + return($UID); +} + +__END__ diff --git a/konsolekalendar/examples/testkalendar.sh b/konsolekalendar/examples/testkalendar.sh new file mode 100644 index 000000000..259d2840c --- /dev/null +++ b/konsolekalendar/examples/testkalendar.sh @@ -0,0 +1,77 @@ +#!/bin/sh +########################################################################################## +# +# *************************************************************************** +# * * +# * 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. * +# * * +# *************************************************************************** +# +########################################################################################## +# +# Purpose of this program is to test konsolekalendar in future this will be more smarter +# +# testkalendar.sh 0.1 +# +########################################################################################## + +#!/bin/sh + +function do_test(){ + +DATE=10 +MONTH=10 +YEAR=2003 + +MINUTE=1 +HOUR=20 + +while [ $DATE -lt 29 ]; do + + +COMMAND="$KONSOLEKALENDAR $1 --time $HOUR:$MINUTE --description $3 --summary $3 --date $YEAR-$MONTH-$DATE --create --file=$2" +echo using command $COMMAND +$COMMAND + +echo "################################ TEXT ##################################" +COMMAND="$KONSOLEKALENDAR --view --time $HOUR:$MINUTE --date $YEAR-$MONTH-$DATE --export-type Text --file=$2" +$COMMAND + +echo "################################ HTML ##################################" +COMMAND="$KONSOLEKALENDAR --view --time $HOUR:$MINUTE --date $YEAR-$MONTH-$DATE --export-type HTML --file=$2" +$COMMAND + + +echo "################################ CSV ##################################" +COMMAND="$KONSOLEKALENDAR --view --time $HOUR:$MINUTE --date $YEAR-$MONTH-$DATE --export-type CSV --file=$2" +$COMMAND + +echo "################################ ORG ##################################" +COMMAND="$KONSOLEKALENDAR --view --time $HOUR:$MINUTE --date $YEAR-$MONTH-$DATE --export-type Text-organizer --file=$2" +$COMMAND + +let DATE=$DATE+1 +let MINUTE=$MINUTE+1 + +done +} + + +KONSOLEKALENDAR=../konsolekalendar +ADDING="--add" +REMOVE="--delete" +CHANGE="--change" +VIEW="--view" + +COMMAND=""; + +FILE="./testcaledar.ics" + +do_test $ADDING $FILE "ADD" +do_test $CHANGE $FILE "CHANGE" +do_test $REMOVE $FILE "REMOVE" + + diff --git a/konsolekalendar/konsolekalendar.cpp b/konsolekalendar/konsolekalendar.cpp new file mode 100644 index 000000000..793c65d40 --- /dev/null +++ b/konsolekalendar/konsolekalendar.cpp @@ -0,0 +1,460 @@ +/******************************************************************************* + * konsolekalendar.cpp * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ +/** + * @file konsolekalendar.cpp + * Provides the KonsoleKalendar class definition. + * @author Tuukka Pasanen + * @author Allen Winter + */ +#include <stdio.h> +#include <stdlib.h> +#include <iostream> + +#include <qdatetime.h> +#include <qfile.h> +#include <qtextstream.h> + +#include <kdebug.h> +#include <klocale.h> + +#include <libkcal/calendarlocal.h> +#include <libkcal/resourcecalendar.h> +#include <libkcal/calendarresources.h> +#include <libkcal/calendar.h> +#include <libkcal/event.h> +#include <libkcal/htmlexport.h> +#include <libkdepim/kpimprefs.h> + +#include "konsolekalendar.h" +#include "konsolekalendaradd.h" +#include "konsolekalendarchange.h" +#include "konsolekalendardelete.h" +#include "konsolekalendarexports.h" + +using namespace KCal; +using namespace std; + +KonsoleKalendar::KonsoleKalendar( KonsoleKalendarVariables *variables ) +{ + m_variables = variables; +} + +KonsoleKalendar::~KonsoleKalendar() +{ +} + +bool KonsoleKalendar::importCalendar() +{ + KonsoleKalendarAdd add( m_variables ); + + kdDebug() << "konsolecalendar.cpp::importCalendar() | importing now!" + << endl; + return( add.addImportedCalendar() ); +} + +bool KonsoleKalendar::createCalendar() +{ + bool status = false; + CalendarLocal newCalendar( KPimPrefs::timezone() ); + + if ( m_variables->isDryRun() ) { + cout << i18n( "Create Calendar <Dry Run>: %1" ). + arg( m_variables->getCalendarFile() ).local8Bit() + << endl; + } else { + kdDebug() << "konsolekalendar.cpp::createCalendar() | " + << "Creating calendar file: " + << m_variables->getCalendarFile().local8Bit() + << endl; + + if ( m_variables->isVerbose() ) { + cout << i18n( "Create Calendar <Verbose>: %1" ). + arg( m_variables->getCalendarFile() ).local8Bit() + << endl; + } + + if ( newCalendar.save( m_variables->getCalendarFile() ) ) { + newCalendar.close(); + status = true; + } + } + return status; +} + +bool KonsoleKalendar::showInstance() +{ + bool status = true; + QFile f; + QString title; + Event *event; + + if ( m_variables->isDryRun() ) { + cout << i18n( "View Events <Dry Run>:" ).local8Bit() + << endl; + printSpecs(); + } else { + + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "open export file" + << endl; + + if ( m_variables->isExportFile() ) { + f.setName( m_variables->getExportFile() ); + if ( !f.open( IO_WriteOnly ) ) { + status = false; + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "unable to open export file " + << m_variables->getExportFile() + << endl; + } + } else { + f.open( IO_WriteOnly, stdout ); + } + + if ( status ) { + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "opened successful" + << endl; + + if ( m_variables->isVerbose() ) { + cout << i18n( "View Event <Verbose>:" ).local8Bit() + << endl; + printSpecs(); + } + + QTextStream ts( &f ); + + if ( m_variables->getExportType() != ExportTypeHTML && + m_variables->getExportType() != ExportTypeMonthHTML ) { + + if ( m_variables->getAll() ) { + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "view all events sorted list" + << endl; + + Event::List sortedList = + m_variables->getCalendar()->events( EventSortStartDate ); + if( sortedList.count() > 0 ) + { + QDate dt, firstdate, lastdate; + firstdate = sortedList.first()->dtStart().date(); + lastdate = sortedList.last()->dtStart().date(); + for ( dt = firstdate; + dt <= lastdate && status != false; + dt = dt.addDays(1) ) { + Event::List events = + m_variables->getCalendar()->events( dt, + EventSortStartDate, + SortDirectionAscending ); + status = printEventList( &ts, &events, dt ); + } + } + + } else if ( m_variables->isUID() ) { + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "view events by uid list" + << endl; + //TODO: support a list of UIDs + event = m_variables->getCalendar()->event( m_variables->getUID() ); + //If this UID represents a recurring Event, + //only the first day of the Event will be printed + status = printEvent ( &ts, event, event->dtStart().date() ); + + } else if ( m_variables->isNext() ) { + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "Show next activity in calendar" + << endl; + + QDateTime datetime = m_variables->getStartDateTime(); + datetime = datetime.addDays( 720 ); + + QDate dt; + for ( dt = m_variables->getStartDateTime().date(); + dt <= datetime.date(); + dt = dt.addDays(1) ) { + Event::List events = + m_variables->getCalendar()->events( dt, + EventSortStartDate, + SortDirectionAscending ); + // finished here when we get the next event + if ( events.count() > 0 ) { + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "Got the next event" + << endl; + printEvent( &ts, events.first(), dt ); + return true; + } + } + } else { + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "view raw events within date range list" + << endl; + + QDate dt; + for ( dt = m_variables->getStartDateTime().date(); + dt <= m_variables->getEndDateTime().date() && status != false; + dt = dt.addDays(1) ) { + Event::List events = + m_variables->getCalendar()->events( dt, + EventSortStartDate, + SortDirectionAscending ); + status = printEventList( &ts, &events, dt ); + } + } + } else { + QDate firstdate, lastdate; + if ( m_variables->getAll() ) { + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "HTML view all events sorted list" + << endl; + // sort the events for this date by start date + // in order to determine the date range. + Event::List *events = + new Event::List ( m_variables->getCalendar()->rawEvents( + EventSortStartDate, + SortDirectionAscending ) ); + firstdate = events->first()->dtStart().date(); + lastdate = events->last()->dtStart().date(); + } else if ( m_variables->isUID() ) { + // TODO + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "HTML view events by uid list" << endl; + cout << i18n("Sorry, export to HTML by UID is not supported yet") + .local8Bit() << endl; + return( false ); + } else { + kdDebug() << "konsolekalendar.cpp::showInstance() | " + << "HTML view raw events within date range list" + << endl; + firstdate = m_variables->getStartDateTime().date(); + lastdate = m_variables->getEndDateTime().date(); + } + + HTMLExportSettings htmlSettings( "Konsolekalendar" ); + + //TODO: get progname and url from the values set in main + htmlSettings.setCreditName( "KonsoleKalendar" ); + htmlSettings.setCreditURL( "http://pim.kde.org/components/konsolekalendar.php" ); + + htmlSettings.setExcludePrivate( true ); + htmlSettings.setExcludeConfidential( true ); + + htmlSettings.setEventView( false ); + htmlSettings.setMonthView( false ); + if ( m_variables->getExportType() == ExportTypeMonthHTML ) { + title = i18n( "Events:" ); + htmlSettings.setMonthView( true ); + } else { + if ( firstdate == lastdate ) { + title = i18n( "Events: %1" ) + .arg( firstdate.toString( Qt::TextDate ) ); + } else { + title = i18n( "Events: %1 - %2" ) + .arg( firstdate.toString( Qt::TextDate ) ) + .arg( lastdate.toString( Qt::TextDate ) ); + } + htmlSettings.setEventView( true ); + } + htmlSettings.setEventTitle( title ); + htmlSettings.setEventAttendees( true ); +// Not supporting Todos yet +// title = "To-Do List for " + firstdate.toString(Qt::TextDate); +// if ( firstdate != lastdate ) { +// title += " - " + lastdate.toString(Qt::TextDate); +// } + htmlSettings.setTodoListTitle( title ); + htmlSettings.setTodoView( false ); +// htmlSettings.setTaskCategories( false ); +// htmlSettings.setTaskAttendees( false ); +// htmlSettings.setTaskDueDate( true ); + + htmlSettings.setDateStart( QDateTime( firstdate ) ); + htmlSettings.setDateEnd( QDateTime( lastdate ) ) ; + + KCal::HtmlExport *Export; + Export = new HtmlExport( m_variables->getCalendar(), &htmlSettings ); + status = Export->save( &ts ); + delete Export; + } + f.close(); + } + } + return status; +} + +bool KonsoleKalendar::printEventList( QTextStream *ts, + Event::List *eventList, QDate date ) +{ + bool status = true; + + if ( eventList->count() ) { + Event *singleEvent; + Event::List::ConstIterator it; + + for ( it = eventList->begin(); + it != eventList->end() && status != false; + ++it ) { + singleEvent = *it; + + status = printEvent( ts, singleEvent, date ); + } + } + + return( status ); +} + +bool KonsoleKalendar::printEvent( QTextStream *ts, Event *event, QDate dt ) +{ + bool status = false; + bool sameDay = true; + KonsoleKalendarExports exports; + + if ( event ) { + switch ( m_variables->getExportType() ) { + + case ExportTypeCSV: + kdDebug() << "konsolekalendar.cpp::printEvent() | " + << "CSV export" + << endl; + status = exports.exportAsCSV( ts, event, dt ); + break; + + case ExportTypeTextShort: + kdDebug() + << "konsolekalendar.cpp::printEvent() | " + << "TEXT-SHORT export" + << endl; + if ( dt.daysTo( m_saveDate ) ) { + sameDay = false; + m_saveDate = dt; + } + status = exports.exportAsTxtShort( ts, event, dt, sameDay ); + break; + + case ExportTypeHTML: + // this is handled separately for now + break; + + default:// Default export-type is ExportTypeText + kdDebug() << "konsolekalendar.cpp::printEvent() | " + << "TEXT export" + << endl; + status = exports.exportAsTxt( ts, event, dt ); + break; + } + } + return( status ); +} + +bool KonsoleKalendar::addEvent() +{ + kdDebug() << "konsolecalendar.cpp::addEvent() | " + << "Create Adding" + << endl; + KonsoleKalendarAdd add( m_variables ); + kdDebug() << "konsolecalendar.cpp::addEvent() | " + << "Adding Event now!" + << endl; + return( add.addEvent() ); +} + +bool KonsoleKalendar::changeEvent() +{ + + kdDebug() << "konsolecalendar.cpp::changeEvent() | " + << "Create Changing" + << endl; + KonsoleKalendarChange change( m_variables ); + kdDebug() << "konsolecalendar.cpp::changeEvent() | " + << "Changing Event now!" + << endl; + return( change.changeEvent() ); +} + +bool KonsoleKalendar::deleteEvent() +{ + kdDebug() << "konsolecalendar.cpp::deleteEvent() | " + << "Create Deleting" + << endl; + KonsoleKalendarDelete del( m_variables ); + kdDebug() << "konsolecalendar.cpp::deleteEvent() | " + << "Deleting Event now!" + << endl; + return( del.deleteEvent() ); +} + +bool KonsoleKalendar::isEvent( QDateTime startdate, + QDateTime enddate, QString summary ) +{ + // Search for an event with specified start and end datetime stamp and summary + + Event *event; + Event::List::ConstIterator it; + + bool found = false; + + Event::List eventList( m_variables->getCalendar()-> + rawEventsForDate( startdate.date(), + EventSortStartDate, + SortDirectionAscending ) ); + for ( it = eventList.begin(); it != eventList.end(); ++it ) { + event = *it; + if ( event->dtEnd() == enddate && event->summary() == summary ) { + found = true; + break; + } + } + return found; +} + +void KonsoleKalendar::printSpecs() +{ + cout << i18n( " What: %1" ). + arg( m_variables->getSummary() ).local8Bit() + << endl; + + cout << i18n( " Begin: %1" ). + arg( m_variables->getStartDateTime().toString( Qt::TextDate ) ).local8Bit() + << endl; + + cout << i18n( " End: %1" ). + arg( m_variables->getEndDateTime().toString( Qt::TextDate ) ).local8Bit() + << endl; + + if ( m_variables->getFloating() == true ) { + cout << i18n( " No Time Associated with Event" ).local8Bit() + << endl; + } + + cout << i18n( " Desc: %1" ). + arg( m_variables->getDescription() ).local8Bit() + << endl; + + cout << i18n( " Location: %1" ). + arg( m_variables->getLocation() ).local8Bit() + << endl; +} diff --git a/konsolekalendar/konsolekalendar.desktop b/konsolekalendar/konsolekalendar.desktop new file mode 100644 index 000000000..43c2bab88 --- /dev/null +++ b/konsolekalendar/konsolekalendar.desktop @@ -0,0 +1,29 @@ +[Desktop Entry] +Name=KonsoleKalendar +Name[af]=Konsole Kalender +Name[cs]=Konzolový kalendář +Name[de]=Konsolen-Kalender +Name[eo]=KonzolKalendaro +Name[fy]=Konsole-aginda +Name[hi]=कंसोल-कैलेंडर +Name[hu]=Konsole-naptár +Name[ja]=コンソールカレンダー +Name[mk]=КонзоленКалендар +Name[ms]=Kalendar Konsole +Name[nb]=KonsoleKalender +Name[nds]=Konsole-Kalenner +Name[ne]=कन्सोल क्यालेन्डर +Name[nl]=Konsole-agenda +Name[nn]=KonsoleKalender +Name[ro]=Calendar de consolă +Name[sr]=Конзолни календар +Name[sr@Latn]=Konzolni kalendar +Name[ta]=கான்சோல் நாள்காட்டி +Name[uk]=Календар для консолі +Exec=kdialog --sorry "konsolekalendar is a command-line only program. Please read the handbook at help:/konsolekalendar for more info." +Icon=konsolekalendar +Type=Application +DocPath=konsolekalendar/index.html +Terminal=false +NoDisplay=true +Categories=Qt;KDE;Utility;X-KDE-More; diff --git a/konsolekalendar/konsolekalendar.h b/konsolekalendar/konsolekalendar.h new file mode 100644 index 000000000..f41ed4ccb --- /dev/null +++ b/konsolekalendar/konsolekalendar.h @@ -0,0 +1,144 @@ +/******************************************************************************* + * konsolekalendar.h * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ + +#ifndef _KONSOLEKALENDAR_H +#define _KONSOLEKALENDAR_H + +#include <qdatetime.h> + +#include <kapplication.h> + +#include <libkcal/calendarlocal.h> +#include <libkcal/resourcecalendar.h> +#include <libkcal/event.h> + +#include "konsolekalendarvariables.h" + +/** + * @file konsolekalendar.h + * Provides the KonsoleKalendar class definition. + */ + +namespace KCal +{ +/** + * The base class of the project. + * @author Tuukka Pasanen + */ + class KonsoleKalendar + { + public: + /** + * Constructs a KonsoleKalendar object from command line arguments. + */ + KonsoleKalendar( KonsoleKalendarVariables *variables ); + /** + * Destructor + */ + ~KonsoleKalendar(); + + /** + * Visualize what we need. + */ + bool showInstance(); + + /** + * Imports calendar file + */ + bool importCalendar(); + + /** + * Add event to calendar + */ + bool addEvent(); + + /** + * Change event + */ + bool changeEvent(); + + /** + * Delete event + */ + bool deleteEvent(); + + /** + * Detect if event already exists + * + * @param startdate Starting date + * @param enddate Ending date + * @param summary Which summary event should have have + */ + bool isEvent( QDateTime startdate, QDateTime enddate, QString summary ); + + /** + * Creates calendar file (If it doesn't exists) + */ + bool createCalendar(); + + private: + + /** + * Print event specs for dryrun and verbose options + */ + void printSpecs(); + + /** + * Prints event list in many formats + * + * @param eventlist which event we should print + * @param dt is the date to use when printing the event for recurring events + */ + bool printEventList( QTextStream *ts, Event::List *eventList, QDate dt ); + + /** + * Prints a single event in many formats + * + * @param event which we should print + * @param dt is the date to use when printing the event for recurring events + */ + bool printEvent( QTextStream *ts, Event *event, QDate dt ); + + /** + * Variables that changes stuff in programm + */ + KonsoleKalendarVariables *m_variables; + + /** + * Calendar file itself + */ + ResourceCalendar *m_Calendar; + + /** + * This is usefull if we like to have same day events to same system + */ + QDate m_saveDate; + + }; + +} +#endif diff --git a/konsolekalendar/konsolekalendaradd.cpp b/konsolekalendar/konsolekalendaradd.cpp new file mode 100644 index 000000000..2f48d1b84 --- /dev/null +++ b/konsolekalendar/konsolekalendaradd.cpp @@ -0,0 +1,168 @@ +/******************************************************************************* + * konsolekalendaradd.cpp * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ +/** + * @file konsolekalendaradd.cpp + * Provides the KonsoleKalendarAdd class definition. + * @author Tuukka Pasanen + * @author Allen Winter + */ +#include <stdlib.h> +#include <iostream> + +#include <qdatetime.h> +#include <qobject.h> + +#include <kdebug.h> +#include <kstandarddirs.h> +#include <klocale.h> + +#include <libkcal/calendarlocal.h> +#include <libkcal/calendar.h> +#include <libkcal/event.h> +#include <libkdepim/kpimprefs.h> + +#include "konsolekalendaradd.h" + +using namespace KCal; +using namespace std; + +KonsoleKalendarAdd::KonsoleKalendarAdd( KonsoleKalendarVariables *vars ) +{ + m_variables = vars; +} + +KonsoleKalendarAdd::~KonsoleKalendarAdd() +{ +} + +/** + * Adds event to Calendar + */ + +bool KonsoleKalendarAdd::addEvent() +{ + bool status = true; + + kdDebug() << "konsolekalendaradd.cpp::addEvent()" << endl; + + if ( m_variables->isDryRun() ) { + cout << i18n( "Insert Event <Dry Run>:" ).local8Bit() + << endl; + printSpecs(); + } else { + if ( m_variables->isVerbose() ) { + cout << i18n( "Insert Event <Verbose>:" ).local8Bit() + << endl; + printSpecs(); + } + + Event *event = new Event(); + + event->setDtStart( m_variables->getStartDateTime() ); + event->setDtEnd( m_variables->getEndDateTime() ); + event->setSummary( m_variables->getSummary() ); + event->setFloats( m_variables->getFloating() ); + event->setDescription( m_variables->getDescription() ); + event->setLocation( m_variables->getLocation() ); + + if ( m_variables->getCalendar()->addEvent( event ) ) { + cout << i18n( "Success: \"%1\" inserted" ). + arg( m_variables->getSummary() ).local8Bit() + << endl; + + m_variables->getCalendar()->save(); + + } else { + cout << i18n( "Failure: \"%1\" not inserted" ). + arg( m_variables->getSummary() ).local8Bit() + << endl; + status = false; + } + } + + kdDebug() << "konsolekalendaradd.cpp::addEvent() | Done " << endl; + return status; +} + +bool KonsoleKalendarAdd::addImportedCalendar() +{ + +// If --file specified, then import into that file +// else, import into the standard calendar + + QString fileName; + if ( m_variables->getCalendarFile().isEmpty() ) + fileName = locateLocal( "data", "korganizer/std.ics" ); + else + fileName = m_variables->getCalendarFile(); + + CalendarLocal *cal = new CalendarLocal( KPimPrefs::timezone() ); + if ( !cal->load( fileName ) || + !cal->load( m_variables->getImportFile() ) || + !cal->save( fileName ) ) { + kdDebug() + << "konsolekalendaradd.cpp::importCalendar() | " + << "Can't import file: " + << m_variables->getImportFile() + << endl; + return false; + } + kdDebug() + << "konsolekalendaradd.cpp::importCalendar() | " + << "Successfully imported file: " + << m_variables->getImportFile() + << endl; + return true; +} + +void KonsoleKalendarAdd::printSpecs() +{ + cout << i18n( " What: %1" ). + arg( m_variables->getSummary() ).local8Bit() + << endl; + + cout << i18n( " Begin: %1" ). + arg( m_variables->getStartDateTime().toString( Qt::TextDate ) ).local8Bit() + << endl; + + cout << i18n( " End: %1" ). + arg( m_variables->getEndDateTime().toString( Qt::TextDate ) ).local8Bit() + << endl; + + if ( m_variables->getFloating() == true ) { + cout << i18n( " No Time Associated with Event" ).local8Bit() + << endl; + } + + cout << i18n( " Desc: %1" ). + arg( m_variables->getDescription() ).local8Bit() + << endl; + + cout << i18n( " Location: %1" ). + arg( m_variables->getLocation() ).local8Bit() + << endl; +} diff --git a/konsolekalendar/konsolekalendaradd.h b/konsolekalendar/konsolekalendaradd.h new file mode 100644 index 000000000..d1c9a2960 --- /dev/null +++ b/konsolekalendar/konsolekalendaradd.h @@ -0,0 +1,83 @@ +/******************************************************************************* + * konsolekalendaradd.h * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ + +#ifndef _KONSOLEKALENDARADD_H_ +#define _KONSOLEKALENDARADD_H_ + +#include "konsolekalendarvariables.h" + +/** + * @file konsolekalendaradd.h + * Provides the KonsoleKalendarAdd class definition. + */ + +namespace KCal +{ + /** + * Class to manage the Event insertion capability. + * @author Tuukka Pasanen + * @author Allen Winter + */ + class KonsoleKalendarAdd + { + public: + /** + * Constructs a KonsoleKalendarAdd object from command line arguments. + * @param vars is a KonsoleKalendarVariable object with Event information. + */ + KonsoleKalendarAdd( KonsoleKalendarVariables *vars ); + /** + * Destructor + */ + ~KonsoleKalendarAdd(); + + /** + * Add the Event. + */ + bool addEvent(); + + /** + * Imports calendar file to current Calendar. + */ + bool addImportedCalendar(); + + private: + + /** + * Print event specs for dryrun and verbose options + */ + void printSpecs(); + + /** + * Variable to how to make it + */ + KonsoleKalendarVariables *m_variables; + + }; + +} +#endif diff --git a/konsolekalendar/konsolekalendarchange.cpp b/konsolekalendar/konsolekalendarchange.cpp new file mode 100644 index 000000000..fffd38cc9 --- /dev/null +++ b/konsolekalendar/konsolekalendarchange.cpp @@ -0,0 +1,180 @@ +/******************************************************************************* + * konsolekalendarchange.cpp * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ +/** + * @file konsolekalendarchange.cpp + * Provides the KonsoleKalendarChange class definition. + * @author Tuukka Pasanen + * @author Allen Winter + */ +#include <stdlib.h> +#include <iostream> + +#include <kdebug.h> +#include <klocale.h> + +#include "konsolekalendarchange.h" + +using namespace KCal; +using namespace std; + +KonsoleKalendarChange::KonsoleKalendarChange( KonsoleKalendarVariables *vars ) +{ + m_variables = vars; +} + +KonsoleKalendarChange::~KonsoleKalendarChange() +{ +} + +bool KonsoleKalendarChange::changeEvent() +{ + bool status = false; + + kdDebug() << "konsolekalendarchange.cpp::changeEvent()" << endl; + + /* + * Retrieve event on the basis of the unique string ID + */ + Event *event = m_variables->getCalendar()->event( m_variables->getUID() ); + if ( event ) { + if ( m_variables->isDryRun() ) { + cout << i18n( "Change Event <Dry Run>:" ).local8Bit() + << endl; + printSpecs( event ); + + cout << i18n( "To Event <Dry Run>:" ).local8Bit() + << endl; + printSpecs(); + } else { + kdDebug() << "konsolekalendarchange.cpp:changeEvent() : " + << m_variables->getUID().local8Bit() + << endl; + + if ( m_variables->isVerbose() ) { + cout << i18n( "Change Event <Verbose>:" ).local8Bit() + << endl; + printSpecs( event ); + + cout << i18n( "To Event <Dry Run>:" ).local8Bit() + << endl; + printSpecs(); + } + + if ( m_variables->isStartDateTime() ) { + event->setDtStart( m_variables->getStartDateTime() ); + } + + if ( m_variables->isEndDateTime() ) { + event->setDtEnd( m_variables->getEndDateTime() ); + } + + event->setFloats( m_variables->getFloating() ); + + if ( m_variables->isSummary() ) { + event->setSummary( m_variables->getSummary() ); + } + + if ( m_variables->isDescription() ) { + event->setDescription( m_variables->getDescription() ); + } + + if ( m_variables->isLocation() ) { + event->setLocation( m_variables->getLocation() ); + } + + if ( m_variables->getCalendar()->addEvent( event ) ) { + cout << i18n( "Success: \"%1\" changed" ) + .arg( event->summary() ).local8Bit() + << endl; + + m_variables->getCalendar()->save(); + status = true; + } else { + cout << i18n( "Failure: \"%1\" not changed" ) + .arg( event->summary() ).local8Bit() + << endl; + } + } + } + + kdDebug() << "konsolekalendarchange.cpp::changeEvent() | Done " << endl; + return status; +} + +void KonsoleKalendarChange::printSpecs( Event *event ) +{ + cout << i18n( " UID: %1" ). + arg( event->uid() ).local8Bit() + << endl; + + cout << i18n( " What: %1" ). + arg( event->summary() ).local8Bit() + << endl; + + cout << i18n( " Begin: %1" ). + arg( event->dtStart().toString( Qt::TextDate ) ).local8Bit() + << endl; + + cout << i18n( " End: %1" ). + arg( event->dtEnd().toString( Qt::TextDate ) ).local8Bit() + << endl; + + cout << i18n( " Desc: %1" ). + arg( event->description() ).local8Bit() + << endl; + + cout << i18n( " Location: %1" ). + arg( event->location() ).local8Bit() + << endl; +} + +void KonsoleKalendarChange::printSpecs() +{ + cout << i18n( " UID: %1" ). + arg( m_variables->getUID() ).local8Bit() + << endl; + + cout << i18n( " What: %1" ). + arg( m_variables->getSummary() ).local8Bit() + << endl; + + cout << i18n( " Begin: %1" ). + arg( m_variables->getStartDateTime().toString( Qt::TextDate ) ).local8Bit() + << endl; + + cout << i18n( " End: %1" ). + arg( m_variables->getEndDateTime().toString( Qt::TextDate ) ).local8Bit() + << endl; + + cout << i18n( " Desc: %1" ). + arg( m_variables->getDescription() ).local8Bit() + << endl; + + cout << i18n( " Location: %1" ). + arg( m_variables->getLocation() ).local8Bit() + << endl; +} diff --git a/konsolekalendar/konsolekalendarchange.h b/konsolekalendar/konsolekalendarchange.h new file mode 100644 index 000000000..80e8f8c2e --- /dev/null +++ b/konsolekalendar/konsolekalendarchange.h @@ -0,0 +1,83 @@ +/******************************************************************************* + * konsolekalendarchange.h * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ + +#ifndef _KONSOLEKALENDARCHANGE_H_ +#define _KONSOLEKALENDARCHANGE_H_ + +#include "konsolekalendarvariables.h" + +/** + * @file konsolekalendarchange.h + * Provides the KonsoleKalendarChange class definition. + */ + +namespace KCal +{ + /** + * Class to manage the Event modification capability. + * @author Tuukka Pasanen + * @author Allen Winter + */ + class KonsoleKalendarChange + { + public: + + /** + * Constructs a KonsoleKalendarChange object from command line arguments. + * @param vars is a KonsoleKalendarVariable object with Event information. + */ + KonsoleKalendarChange( KonsoleKalendarVariables *vars ); + /** + * Destructor + */ + ~KonsoleKalendarChange(); + + /** + * Modify the Event. + */ + bool changeEvent(); + + private: + + /** + * Print Event specs for dryrun and verbose options. + * @param event is the Event to print. + */ + void printSpecs( Event *event ); + /* + * Print Event specs as provided from the command line arguments. + */ + void printSpecs(); + + /** + * Variables are here + */ + KonsoleKalendarVariables *m_variables; + }; + +} +#endif diff --git a/konsolekalendar/konsolekalendardelete.cpp b/konsolekalendar/konsolekalendardelete.cpp new file mode 100644 index 000000000..02d676272 --- /dev/null +++ b/konsolekalendar/konsolekalendardelete.cpp @@ -0,0 +1,118 @@ +/******************************************************************************* + * konsolekalendardelete.cpp * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ +/** + * @file konsolekalendardelete.cpp + * Provides the KonsoleKalendarDelete class definition. + * @author Tuukka Pasanen + * @author Allen Winter + */ +#include <stdlib.h> +#include <iostream> + +#include <kdebug.h> +#include <klocale.h> + +#include "konsolekalendardelete.h" + +using namespace KCal; +using namespace std; + +KonsoleKalendarDelete::KonsoleKalendarDelete( KonsoleKalendarVariables *vars ) +{ + m_variables = vars; +} + +KonsoleKalendarDelete::~KonsoleKalendarDelete() +{ +} + +bool KonsoleKalendarDelete::deleteEvent() +{ + bool status = false; + + kdDebug() << "konsolekalendardelete.cpp::deleteEvent()" << endl; + + /* + * Retrieve event on the basis of the unique string ID + */ + Event *event = m_variables->getCalendar()->event( m_variables->getUID() ); + if ( event ) { + if ( m_variables->isDryRun() ) { + cout << i18n( "Delete Event <Dry Run>:" ).local8Bit() + << endl; + printSpecs( event ); + } else { + kdDebug() << "konsolekalendardelete.cpp:deleteEvent() : " + << m_variables->getUID().local8Bit() + << endl; + + if ( m_variables->isVerbose() ) { + cout << i18n( "Delete Event <Verbose>:" ).local8Bit() + << endl; + printSpecs( event ); + } + + m_variables->getCalendar()->deleteEvent( event ); + cout << i18n( "Success: \"%1\" deleted" ) + .arg( event->summary() ).local8Bit() + << endl; + + m_variables->getCalendar()->save(); + status = true; + } + } + + kdDebug() << "konsolekalendardelete.cpp::deleteEvent() | Done " << endl; + return status; +} + +void KonsoleKalendarDelete::printSpecs( Event *event ) +{ + cout << i18n( " UID: %1" ). + arg( m_variables->getUID() ).local8Bit() + << endl; + + cout << i18n( " What: %1" ). + arg( event->summary() ).local8Bit() + << endl; + + cout << i18n( " Begin: %1" ). + arg( event->dtStart().toString( Qt::TextDate ) ).local8Bit() + << endl; + + cout << i18n( " End: %1" ). + arg( event->dtEnd().toString( Qt::TextDate ) ).local8Bit() + << endl; + + cout << i18n( " Desc: %1" ). + arg( event->description() ).local8Bit() + << endl; + + cout << i18n( " Location: %1" ). + arg( event->location() ).local8Bit() + << endl; +} diff --git a/konsolekalendar/konsolekalendardelete.h b/konsolekalendar/konsolekalendardelete.h new file mode 100644 index 000000000..2a01990f0 --- /dev/null +++ b/konsolekalendar/konsolekalendardelete.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * konsolekalendardelete.h * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ + +#ifndef _KONSOLEKALENDARDELETE_H_ +#define _KONSOLEKALENDARDELETE_H_ + +#include "konsolekalendarvariables.h" + +/** + * @file konsolekalendardelete.h + * Provides the KonsoleKalendarDelete class definition. + */ + +namespace KCal +{ + /** + * Class to manage the Event removal capability. + * @author Tuukka Pasanen + * @author Allen Winter + */ + class KonsoleKalendarDelete + { + public: + + /** + * Constructs a KonsoleKalendarDelete object from command line arguments. + */ + KonsoleKalendarDelete( KonsoleKalendarVariables *vars ); + /** + * Destructor + */ + ~KonsoleKalendarDelete(); + + /** + * Delete the Event. + */ + bool deleteEvent(); + + private: + + /** + * Print event specs for dryrun and verbose options. + */ + void printSpecs( Event *event ); + + /** + * What we need to delete + */ + KonsoleKalendarVariables *m_variables; + }; + +} +#endif diff --git a/konsolekalendar/konsolekalendarepoch.cpp b/konsolekalendar/konsolekalendarepoch.cpp new file mode 100644 index 000000000..c070d2532 --- /dev/null +++ b/konsolekalendar/konsolekalendarepoch.cpp @@ -0,0 +1,176 @@ +/******************************************************************************* + * konsolekalendarepoch.cpp * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ +/** + * @file konsolekalendarepoch.cpp + * Provides the KonsoleKalendarEpoch class definition. + * @author Tuukka Pasanen + * @author Allen Winter + */ +#include <stdlib.h> +#include <iostream> + +#include <qdatetime.h> +#include "konsolekalendarepoch.h" + +using namespace KCal; +using namespace std; + +KonsoleKalendarEpoch::KonsoleKalendarEpoch() +{ +} + +KonsoleKalendarEpoch::~KonsoleKalendarEpoch() +{ +} + +// By "epoch" we mean the number of seconds since 00:00:00 UTC on January 1 1970 + +// Function to convert an epoch value into a QDateTime +QDateTime KonsoleKalendarEpoch::epoch2QDateTime( uint epoch ) +{ + QDateTime dt; + dt.setTime_t( epoch, Qt::UTC ); + return( dt ); +} + +// Function to convert a QDateTime value into an epoch +uint KonsoleKalendarEpoch::QDateTime2epoch( QDateTime dt ) +{ + // THIS FUNCTION CAN BE OFF BY 1 HOUR DUE TO DAYLIGHT SAVINGS TIME. + // SORRY QT DOESN'T HANDLE DAYLIGHT SAVINGS TIME. + + // Compute #seconds to subtract for local timezone difference from UTC. + int offset = QDateTime::currentDateTime( Qt::UTC ).toTime_t() + - QDateTime::currentDateTime( Qt::LocalTime ).toTime_t(); + return( dt.toTime_t() - offset ); +} + +#if defined (TEST) +// Pass -DTEST to the compile command to create the test program, e.g: +// cc -DTEST -I/usr/local/KDE/include konsolekalendarepoch.cpp +// -L/usr/local/KDE/lib -lqt-mt -pthread +main() +{ + uint epoch; + QDateTime dt; + + cout << endl; + cout << "NOTE: Some tests may be off by 1 hour (3600 secs) " + << "due to daylight savings time" + << endl << endl; + + // Test1 + epoch = 0; + dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch ); + cout << "TEST 1:" << endl; + cout << "epoch=" + << epoch + << " converts to " + << dt.toString( Qt::TextDate ) + << endl; + + epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt ); + cout << "date=" + << dt.toString( Qt::TextDate ) + << " converts to " + << "epoch=" + << epoch + << endl; + + // Test2 + epoch = 100000; + dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch ); + cout << "TEST 2:" << endl; + cout << "epoch=" + << epoch + << " converts to " + << dt.toString( Qt::TextDate ) + << endl; + + epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt ); + cout << "date=" + << dt.toString( Qt::TextDate ) + << " converts to " + << "epoch=" + << epoch + << endl; + + // Test3 + epoch = 10000000; + dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch ); + cout << "TEST 3:" << endl; + cout << "epoch=" + << epoch + << " converts to " + << dt.toString( Qt::TextDate ) + << endl; + + epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt ); + cout << "date=" + << dt.toString( Qt::TextDate ) + << " converts to " + << "epoch=" + << epoch + << endl; + + // Test4 + epoch = 1000000000; + dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch ); + cout << "TEST 4:" << endl; + cout << "epoch=" + << epoch + << " converts to " + << dt.toString( Qt::TextDate ) + << endl; + + epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt ); + cout << "date=" + << dt.toString( Qt::TextDate ) + << " converts to " + << "epoch=" + << epoch + << endl; + + // Test5 + epoch = 10000000000; + dt = KonsoleKalendarEpoch::epoch2QDateTime( epoch ); + cout << "TEST 5:" << endl; + cout << "epoch=" + << epoch + << " converts to " + << dt.toString( Qt::TextDate ) + << endl; + + epoch = KonsoleKalendarEpoch::QDateTime2epoch( dt ); + cout << "date=" + << dt.toString( Qt::TextDate ) + << " converts to " + << "epoch=" + << epoch + << endl; +} +#endif diff --git a/konsolekalendar/konsolekalendarepoch.h b/konsolekalendar/konsolekalendarepoch.h new file mode 100644 index 000000000..e6db6d77e --- /dev/null +++ b/konsolekalendar/konsolekalendarepoch.h @@ -0,0 +1,72 @@ +/******************************************************************************* + * konsolekalendarepoch.h * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ + +#ifndef _KONSOLEKALENDAREPOCH_H_ +#define _KONSOLEKALENDAREPOCH_H_ + +#include <qdatetime.h> + +/** + * @file konsolekalendarepoch.h + * Provides the KonsoleKalendarEpoch class definition. + */ + +namespace KCal +{ + /** + * Class for timestamps expressed as epochs. + * @author Allen Winter + */ + class KonsoleKalendarEpoch + { + public: + /** + * Constructor. + */ + KonsoleKalendarEpoch(); + /** + * Destructor + */ + ~KonsoleKalendarEpoch(); + + /** + * Converts epoch time to QDateTime format. + * @param epoch epoch time. + */ + static QDateTime epoch2QDateTime( uint epoch ); + + /** + * Converts QT DateTime to epoch format. + * @param dt is a QDateTime to convert to an epoch. + */ + static uint QDateTime2epoch( QDateTime dt ); + + }; + +} + +#endif diff --git a/konsolekalendar/konsolekalendarexports.cpp b/konsolekalendar/konsolekalendarexports.cpp new file mode 100644 index 000000000..cad79964a --- /dev/null +++ b/konsolekalendar/konsolekalendarexports.cpp @@ -0,0 +1,243 @@ +/******************************************************************************* + * konsolekalendarexports.cpp * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ +/** + * @file konsolekalendarexports.cpp + * Provides the KonsoleKalendarExports class definition. + * @author Tuukka Pasanen + * @author Allen Winter + */ +#include <stdlib.h> +#include <iostream> + +#include <qdatetime.h> + +#include <kdebug.h> +#include <klocale.h> + +#include <libkcal/calendarlocal.h> +#include <libkcal/calendar.h> +#include <libkcal/event.h> + +#include "konsolekalendarexports.h" + +using namespace KCal; +using namespace std; + +KonsoleKalendarExports::KonsoleKalendarExports( KonsoleKalendarVariables *vars ) +{ + m_variables = vars; + m_firstEntry = true; +} + + +KonsoleKalendarExports::~KonsoleKalendarExports() +{ +} + +bool KonsoleKalendarExports::exportAsTxt( QTextStream *ts, + Event *event, QDate date ) +{ + + // Export "Text" Format: + // + // Date:\t<Incidence Date>(dddd yyyy-MM-dd) + // [\t<Incidence Start Time>(hh:mm) - <Incidence End Time>(hh:mm)] + // Summary: + // \t<Incidence Summary | "(no summary available)"> + // Location: + // \t<Incidence Location | "(no location available)"> + // Description: + // \t<Incidence Description | "(no description available)"> + // UID: + // \t<Incidence UID> + // -------------------------------------------------- + + // Print Event Date (in user's prefered format) + *ts << i18n( "Date:" ) + << "\t" + << KGlobal::locale()->formatDate( date ) + << endl; + + // Print Event Starttime - Endtime, for Non-Floating Events Only + if ( !event->doesFloat() ) { + *ts << "\t" + << KGlobal::locale()->formatTime( event->dtStart().time() ) + << " - " + << KGlobal::locale()->formatTime( event->dtEnd().time() ); + } + *ts << endl; + + // Print Event Summary + *ts << i18n( "Summary:" ) + << endl; + if ( !event->summary().isEmpty() ) { + *ts << "\t" + << event->summary() + << endl; + } else { + *ts << "\t" + << i18n( "(no summary available)" ) + << endl; + } + + // Print Event Location + *ts << i18n( "Location:" ) + << endl; + if ( !event->location().isEmpty() ) { + *ts << "\t" + <<event->location() + << endl; + } else { + *ts << "\t" + << i18n( "(no location available)" ) + << endl; + } + + // Print Event Description + *ts << i18n( "Description:" ) + << endl; + if ( !event->description().isEmpty() ) { + *ts << "\t" + << event->description() + << endl; + } else { + *ts << "\t" + << i18n( "(no description available)" ) + << endl; + } + + // Print Event UID + *ts << i18n( "UID:" ) + << endl + << "\t" + << event->uid() + << endl; + + // Print Line Separator + *ts << "--------------------------------------------------" + << endl; + + return true; +} + +bool KonsoleKalendarExports::exportAsTxtShort( QTextStream *ts, + Event *event, QDate date, + bool sameday ) +{ + + // Export "Text-Short" Format: + // + // [--------------------------------------------------] + // {<Incidence Date>(dddd yyyy-MM-dd)] + // [<Incidence Start Time>(hh:mm) - <Incidence End Time>(hh:mm) | "\t"] + // \t<Incidence Summary | \t>[, <Incidence Location>] + // \t\t<Incidence Description | "\t"> + + if ( !sameday ) { + // If a new date, then Print the Event Date (in user's prefered format) + *ts << KGlobal::locale()->formatDate( date ) << ":" + << endl; + } + + // Print Event Starttime - Endtime + if ( !event->doesFloat() ) { + *ts << KGlobal::locale()->formatTime( event->dtStart().time() ) + << " - " + << KGlobal::locale()->formatTime( event->dtEnd().time() ); + } else { + *ts << i18n( "[all day]\t" ); + } + *ts << "\t"; + + // Print Event Summary + *ts << event->summary().replace( QChar( '\n' ), QChar( ' ' ) ); + + // Print Event Location + if ( !event->location().isEmpty() ) { + if ( !event->summary().isEmpty() ) { + *ts << ", "; + } + *ts << event->location().replace( QChar( '\n' ), QChar( ' ' ) ); + } + *ts << endl; + + // Print Event Description + if ( !event->description().isEmpty() ) { + *ts << "\t\t\t" + << event->description().replace( QChar( '\n' ), QChar( ' ' ) ) + << endl; + } + +// By user request, no longer print UIDs if export-type==short + + return true; +} + +QString KonsoleKalendarExports::processField( QString field, QString dquote ) +{ + // little function that processes a field for CSV compliance: + // 1. Replaces double quotes by a pair of consecutive double quotes + // 2. Surrounds field with double quotes + + QString double_dquote = dquote + dquote; + QString retField = dquote + field.replace( dquote, double_dquote ) + dquote; + return retField; +} + +#define pF( x ) processField( ( x ), dquote ) + +bool KonsoleKalendarExports::exportAsCSV( QTextStream *ts, + Event *event, QDate date ) +{ + + // Export "CSV" Format: + // + // startdate,starttime,enddate,endtime,summary,location,description,UID + + QString delim = i18n( "," ); // character to use as CSV field delimiter + QString dquote = i18n( "\"" ); // character to use to quote CSV fields + + if ( !event->doesFloat() ) { + *ts << pF( KGlobal::locale()->formatDate( date ) ) + << delim << pF( KGlobal::locale()->formatTime( event->dtStart().time() ) ) + << delim << pF( KGlobal::locale()->formatDate( date ) ) + << delim << pF( KGlobal::locale()->formatTime( event->dtEnd().time() ) ); + } else { + *ts << pF( KGlobal::locale()->formatDate( date ) ) + << delim << pF( "" ) + << delim << pF( KGlobal::locale()->formatDate( date ) ) + << delim << pF( "" ); + } + + *ts << delim << pF( event->summary().replace( QChar('\n'), QChar(' ') ) ) + << delim << pF( event->location().replace( QChar('\n'), QChar(' ') ) ) + << delim << pF( event->description().replace( QChar('\n'), QChar(' ') ) ) + << delim << pF( event->uid() ) + << endl; + + return true; +} diff --git a/konsolekalendar/konsolekalendarexports.h b/konsolekalendar/konsolekalendarexports.h new file mode 100644 index 000000000..dc2f44eca --- /dev/null +++ b/konsolekalendar/konsolekalendarexports.h @@ -0,0 +1,101 @@ +/******************************************************************************* + * konsolekalendarexports.h * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ + +#ifndef _KONSOLEKALENDAREXPORTS_H_ +#define _KONSOLEKALENDAREXPORTS_H_ + +#include <qtextstream.h> + +#include "konsolekalendarvariables.h" + +/** + * @file konsolekalendarexports.h + * Provides the KonsoleKalendarExports class definition. + */ + +namespace KCal +{ + /** + * Class to manage the Export functionality. + * @author Tuukka Pasanen + * @author Allen Winter + */ + class KonsoleKalendarExports + { + public: + + /** + * Constructs a KonsoleKalendarChange object from command line arguments. + * @param vars is a KonsoleKalendarVariable object with Event information. + */ + KonsoleKalendarExports( KonsoleKalendarVariables *vars = 0 ); + /** + * Destructor + */ + ~KonsoleKalendarExports(); + + /** + * Export the Event in Text Mode. + * @param ts pointer to the output QTextStream. + * @param event pointer to the Event to export. + * @param date is the QDate to be exported for. + */ + bool exportAsTxt( QTextStream *ts, Event *event, QDate date ); + /** + * Export the Event in Short Text Mode. + * @param ts pointer to the output QTextStream. + * @param event pointer to the Event to export. + * @param date is the QDate to be exported for. + * @param sameday flags that this Event is on the same date as the + * previously exported Event. + */ + bool exportAsTxtShort( QTextStream *ts, Event *event, QDate date, + bool sameday ); + /** + * Export the Event in Comma-Separated Values (CSV) Mode. + * @param ts pointer to the output QTextStream. + * @param event pointer to the Event to export. + * @param date is the QDate to be exported for. + */ + bool exportAsCSV( QTextStream *ts, Event *event, QDate date ); + + private: + KonsoleKalendarVariables *m_variables; + bool m_firstEntry; + /** + * Processes a field for Comma-Separated Value (CSV) compliance: + * 1. Replaces double quotes by a pair of consecutive double quotes + * 2. Surrounds field with double quotes + * @param field is the field value to be processed. + * @param dquote is a QString containing the double quote character. + */ + QString processField( QString field, QString dquote ); + + }; + +} +#endif diff --git a/konsolekalendar/konsolekalendarvariables.cpp b/konsolekalendar/konsolekalendarvariables.cpp new file mode 100644 index 000000000..bba7864bd --- /dev/null +++ b/konsolekalendar/konsolekalendarvariables.cpp @@ -0,0 +1,333 @@ +/******************************************************************************* + * konsolekalendarvariables.cpp * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ +/** + * @file konsolekalendarvariables.cpp + * Provides the KonsoleKalendarVariables class definition. + * @author Tuukka Pasanen + * @author Allen Winter + */ +#include <klocale.h> +#include <kdebug.h> +#include <kglobal.h> +#include <kconfig.h> +#include <kstandarddirs.h> + +#include <qdatetime.h> +#include <qstring.h> +#include <qstringlist.h> + +#include <stdlib.h> +#include <iostream> +#include <stdio.h> +#include <unistd.h> +#include <time.h> + +#include "konsolekalendarvariables.h" + +using namespace KCal; +using namespace std; + +KonsoleKalendarVariables::KonsoleKalendarVariables() +{ + m_bIsUID = false; + m_bIsStartDateTime = false; + m_bIsEndDateTime = false; + m_bNext = false; + m_bVerbose = false; + m_bDryRun = false; + m_bUseEvents = false; + m_bUseTodos = false; + m_bUseJournals = false; + m_calendar = ""; + m_exportType = ExportTypeText; + m_bIsExportFile = false; + m_bDescription = false; + m_description = ""; + m_bLocation = false; + m_location = "Default location"; + m_bSummary = false; + m_summary = "Default summary"; + m_bFloating = true; +} + +KonsoleKalendarVariables::~KonsoleKalendarVariables() +{ + // delete m_resource; +} + +void KonsoleKalendarVariables::setUID( QString uid ) +{ + m_bIsUID = true; + m_UID = uid; +} + +QString KonsoleKalendarVariables::getUID() +{ + return m_UID; +} + +bool KonsoleKalendarVariables::isUID() +{ + return m_bIsUID; +} + +void KonsoleKalendarVariables::setStartDateTime( QDateTime start ) +{ + m_bIsStartDateTime = true; + m_startDateTime = start; +} + +QDateTime KonsoleKalendarVariables::getStartDateTime() +{ + return m_startDateTime; +} + +bool KonsoleKalendarVariables::isStartDateTime() +{ + return m_bIsStartDateTime; +} + +void KonsoleKalendarVariables::setEndDateTime( QDateTime end ) +{ + m_bIsEndDateTime = true; + m_endDateTime = end; +} + +QDateTime KonsoleKalendarVariables::getEndDateTime() +{ + return m_endDateTime; +} + +bool KonsoleKalendarVariables::isEndDateTime() +{ + return m_bIsEndDateTime; +} + +void KonsoleKalendarVariables::setNext( bool next ) +{ + m_bNext = next; +} + +bool KonsoleKalendarVariables::isNext() +{ + return m_bNext; +} + +void KonsoleKalendarVariables::setVerbose( bool verbose ) +{ + m_bVerbose = verbose; +} + +bool KonsoleKalendarVariables::isVerbose() +{ + return m_bVerbose; +} + +void KonsoleKalendarVariables::setDryRun( bool dryrun ) +{ + m_bDryRun = dryrun; +} + +bool KonsoleKalendarVariables::isDryRun() +{ + return m_bDryRun; +} + +void KonsoleKalendarVariables::setUseEvents( bool useEvents ) +{ + m_bUseEvents = useEvents; +} + +bool KonsoleKalendarVariables::getUseEvents() +{ + return( m_bUseEvents ); +} + +void KonsoleKalendarVariables::setUseTodos( bool useTodos ) +{ + m_bUseTodos = useTodos; +} + +bool KonsoleKalendarVariables::getUseTodos() +{ + return( m_bUseTodos ); +} + +void KonsoleKalendarVariables::setUseJournals( bool useJournals ) +{ + m_bUseJournals = useJournals; +} + +bool KonsoleKalendarVariables::getUseJournals() +{ + return( m_bUseJournals ); +} + +void KonsoleKalendarVariables::setCalendarFile( QString calendar ) +{ + m_calendar = calendar; +} + +QString KonsoleKalendarVariables::getCalendarFile() +{ + return m_calendar; +} + +void KonsoleKalendarVariables::setImportFile( QString calendar ) +{ + m_import = calendar; +} + +QString KonsoleKalendarVariables::getImportFile() +{ + return m_import; +} + +void KonsoleKalendarVariables::setCalendar( CalendarResources *resources ) +{ + m_calendarResources = resources; +} + +CalendarResources *KonsoleKalendarVariables::getCalendar() +{ + return m_calendarResources; +} + +void KonsoleKalendarVariables::setExportType( ExportType exportType ) +{ + m_exportType = exportType; +} + +ExportType KonsoleKalendarVariables::getExportType() +{ + return m_exportType; +} + +void KonsoleKalendarVariables::setExportFile( QString export_file ) +{ + m_exportFile = export_file; + m_bIsExportFile = true; +} + +bool KonsoleKalendarVariables::isExportFile() +{ + return m_bIsExportFile; +} + +QString KonsoleKalendarVariables::getExportFile() +{ + return m_exportFile; +} + +bool KonsoleKalendarVariables::isAll() +{ + return m_bAll; +} + +void KonsoleKalendarVariables::setAll( bool all ) +{ + m_bAll = all; +} + +bool KonsoleKalendarVariables::getAll() +{ + return m_bAll; +} + +void KonsoleKalendarVariables::setDescription( QString description ) +{ + m_bDescription = true; + m_description = description; +} + +QString KonsoleKalendarVariables::getDescription() +{ + return m_description; +} + +bool KonsoleKalendarVariables::isDescription() +{ + return m_bDescription; +} + +void KonsoleKalendarVariables::setLocation( QString location ) +{ + m_bLocation = true; + m_location = location; +} + +QString KonsoleKalendarVariables::getLocation() +{ + return m_location; +} + +bool KonsoleKalendarVariables::isLocation() +{ + return m_bLocation; +} + +void KonsoleKalendarVariables::setSummary( QString summary ) +{ + m_bSummary = true; + m_summary = summary; +} + +QString KonsoleKalendarVariables::getSummary() +{ + return m_summary; +} + +bool KonsoleKalendarVariables::isSummary() +{ + return m_bSummary; +} + +void KonsoleKalendarVariables::setFloating( bool floating ) +{ + m_bFloating = floating; +} + +bool KonsoleKalendarVariables::getFloating() +{ + return m_bFloating; +} + +void KonsoleKalendarVariables::setDaysCount( int count ) +{ + m_daysCount = count; + m_bDaysCount = true; +} + +int KonsoleKalendarVariables::getDaysCount() +{ + return m_daysCount; +} + +bool KonsoleKalendarVariables::isDaysCount() +{ + return m_bDaysCount; +} diff --git a/konsolekalendar/konsolekalendarvariables.h b/konsolekalendar/konsolekalendarvariables.h new file mode 100644 index 000000000..ccba49348 --- /dev/null +++ b/konsolekalendar/konsolekalendarvariables.h @@ -0,0 +1,399 @@ +/******************************************************************************* + * konsolekalendarvariables.h * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ + +#ifndef _KONSOLEKALENDARVARIABLES_H_ +#define _KONSOLEKALENDARVARIABLES_H_ + +#include <libkcal/calendarlocal.h> +#include <libkcal/calendarresources.h> +#include <libkcal/resourcelocal.h> +#include <libkcal/resourcecalendar.h> +#include <libkcal/event.h> + +#include <qstring.h> +#include <qdatetime.h> + +/** + * @file konsolekalendarvariables.h + * Provides the KonsoleKalendarVariables class definition. + */ + +namespace KCal +{ + /** + * ExportType is the type of Export output + */ + enum ExportType + { + /** Export none */ + ExportTypeNone, + /** Export as text (default) */ + ExportTypeText, + /** Export as compact text */ + ExportTypeTextShort, + /** Export HTML for the specified time span */ + ExportTypeHTML, + /** Export HTML for the time span on month boundaries */ + ExportTypeMonthHTML, + /** Export XHTML (NOT AVAILABLE YET) */ + ExportTypeXHTML, + /** Export XML (NOT AVAILABLE YET) */ + ExportTypeXML, + /** Export Comma-Separated Values */ + ExportTypeCSV, + /** Export VCard (NOT AVAILABLE YET) */ + ExportTypeVCard + }; + + /** + * This class provides all the variables for the program. + * @author Tuukka Pasanen + * @author Allen Winter + */ + class KonsoleKalendarVariables + { + public: + /** + * Construct an empty KonsoleKalendarVariables object. + */ + KonsoleKalendarVariables(); + /** + * Destructor + */ + ~KonsoleKalendarVariables(); + + /** + * Set switch to use Events. + * @param useEvents if true, operation uses Events. + */ + void setUseEvents( bool useEvents ); + /** + * Get use Events switch. + * @return true if operation using Events is specified. + */ + bool getUseEvents(); + + /** + * Set switch to use Todos. + * @param useTodos if true, operation uses Todos. + */ + void setUseTodos( bool useTodos ); + /** + * Get use Todos switch. + * @return true if operation using Todos is specified. + */ + bool getUseTodos(); + + /** + * Set switch to use Journals. + * @param useJournals if true, operation uses Journals. + */ + void setUseJournals( bool useJournals ); + /** + * Get use Journals switch. + * @return true if operation using Journals is specified. + */ + bool getUseJournals(); + + /** + * Sets start date. + * @param start is the start date. + */ + void setStartDateTime( QDateTime start ); + + /** + * Get start date. + * @return start date. + */ + QDateTime getStartDateTime(); + + /** + * Is there start date? + * @return true if there is false is there isn't. + */ + bool isStartDateTime(); + + /** + * Sets end date. + * @param end is the enddate. + */ + void setEndDateTime( QDateTime end ); + + /** + * Get end date. + * @return end date. + */ + QDateTime getEndDateTime(); + + /** + * Is there end date? + * @return true if there is false is there isn't. + */ + bool isEndDateTime(); + + /** + * Sets the UID, the unique tag for VCard entry. + * @param uid unique tag for VCard entry. + */ + void setUID( QString uid ); + + /** + * Get UID, the unique tag for VCard entry. + * @return UID number. + */ + QString getUID(); + + /** + * Is there UID set? + * @return true there is UID false there isn't. + */ + bool isUID(); + + /** + * Show only next activity and exit. + * @param next true or false. + */ + void setNext( bool next ); + + /** + * Should we show only next activity and exit? + */ + bool isNext(); + + /** + * Should program be more verbose? + * @param verbose a flag to set verbosity. + */ + void setVerbose( bool verbose ); + + /** + * Should program be more verbose? + */ + bool isVerbose(); + + /** + * Should we only try to run it and do nothing? + * @param dryrun false no and true just test it. + */ + void setDryRun( bool dryrun ); + + /** + * Is this program only in testing mode? + * @return true yes false no. + */ + bool isDryRun(); + + /** + * Set calendar file + * @param calendar Calendar files full path. + */ + void setCalendarFile( QString calendar ); + + /** + * Returns fullpath to calendar file. + * @return calendar file. + */ + QString getCalendarFile(); + + /** + * Set file to import active calendar. + * @param calendar Calendar file to import. + */ + void setImportFile( QString calendar ); + + /** + * Return import filename. + * @return File that should be imported. + */ + QString getImportFile(); + + /** + * Add description. + * @param description to event. + */ + void setDescription( QString description ); + + /** + * Return description. + * @return description of event. + */ + QString getDescription(); + + /** + * Is there an event description? + * @return true is there is description false there isn't. + */ + bool isDescription(); + + /** + * Add location information. + * @param location location where the event occurs. + */ + void setLocation( QString location ); + + /** + * Return location information. + * @return location where event is occurring. + */ + QString getLocation(); + + /** + * Is there event location information available? + * @return true is there is description false there isn't. + */ + bool isLocation(); + + /** + * Add summary. + * @param summary event summary. + */ + void setSummary( QString summary ); + + /** + * Get summary. + * @return summary. + */ + QString getSummary(); + + /** + * Is there an event summary? + * @return true there is false there isn't. + */ + bool isSummary(); + + /** + * View all option. + * @param all flag to view all Events. + */ + void setAll( bool all ); + /** + * Return all option. + */ + bool getAll(); + /** + * Is the all option set? + */ + bool isAll(); + + /** + * Set if Event is floating. + * @param floating if true then the Event is floating. + */ + void setFloating( bool floating ); + /** + * Return if Event is floating. + */ + bool getFloating(); + + /** + * Set calendar resources for global use. + */ + + void setCalendar( CalendarResources *resources ); + + /** + * Get global calendar resources. + */ + + CalendarResources *getCalendar(); + + /** + * Set output file. + */ + void setExportFile( QString export_file ); + + /** + * To what file we'll output. + */ + QString getExportFile(); + + /** + * Has an Export File been set? + */ + bool isExportFile(); + + /** + * Set export type that'll we use. + */ + void setExportType( ExportType exportType ); + + /** + * What export type to use. + */ + ExportType getExportType(); + + /** + * Set how many day should be seen. + */ + + void setDaysCount( int count ); + + /** + * Is there some cound of days should be seen. + */ + bool isDaysCount(); + + /** + * Get how many day should be seen. + */ + + int getDaysCount(); + + private: + bool m_bIsUID; + QString m_UID; + bool m_bIsStartDateTime; + QDateTime m_startDateTime; + bool m_bIsEndDateTime; + QDateTime m_endDateTime; + bool m_bNext; + bool m_bVerbose; + bool m_bDryRun; + bool m_bUseEvents; + bool m_bUseTodos; + bool m_bUseJournals; + QString m_calendar; + QString m_import; + ExportType m_exportType; + bool m_bIsExportFile; + QString m_exportFile; + bool m_bAll; + bool m_bDescription; + QString m_description; + bool m_bLocation; + QString m_location; + bool m_bSummary; + QString m_summary; + bool m_bFloating; + bool m_bDaysCount; + int m_daysCount; + CalendarResources *m_calendarResources; + }; + +} + +#endif diff --git a/konsolekalendar/main.cpp b/konsolekalendar/main.cpp new file mode 100644 index 000000000..3792d083e --- /dev/null +++ b/konsolekalendar/main.cpp @@ -0,0 +1,989 @@ +/******************************************************************************* + * main.cpp * + * * + * KonsoleKalendar is a command line interface to KDE calendars * + * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> * + * Copyright (C) 2003-2005 Allen Winter <winter@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. * + * * + * As a special exception, permission is given to link this program * + * with any edition of Qt, and distribute the resulting executable, * + * without including the source code for Qt in the source distribution. * + * * + ******************************************************************************/ +/** + * @file main.cpp + * KonsoleKalendar main program. + * @author Tuukka Pasanen + * @author Allen Winter + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#if TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +#else +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# else +# include <time.h> +# endif +#endif + +#include <kcmdlineargs.h> +#include <kaboutdata.h> +#include <klocale.h> +#include <kglobal.h> +#include <kconfig.h> +#include <kstandarddirs.h> +#include <kdebug.h> + +#include <libkcal/calformat.h> +#include <libkcal/calendarresources.h> +#include <libkcal/resourcelocal.h> + +#include <qdatetime.h> +#include <qfile.h> +#include <qfileinfo.h> + +#include <stdlib.h> +#include <iostream> + +#include "stdcalendar.h" +#include "konsolekalendar.h" +#include "konsolekalendarepoch.h" + +#include "konsolekalendarvariables.h" + +using namespace KCal; +using namespace std; + +static const char progName[] = "konsolekalendar"; +static const char progDisplay[] = "KonsoleKalendar"; +static const char progVersion[] = "1.3.5"; +static const char progDesc[] = "A command line interface to KDE calendars"; +static const char progURL[] = "pim.kde.org/components/konsolekalendar.php"; + + +static KCmdLineOptions options[] = +{ + { "verbose", + I18N_NOOP( "Print helpful runtime messages" ), 0 }, + { "dry-run", + I18N_NOOP( "Print what would have been done, but do not execute" ), 0 }, + { "file <calendar-file>", + I18N_NOOP( "Specify which calendar you want to use" ), 0 }, + + { ":", + I18N_NOOP( "Incidence types (these options can be combined):" ), 0 }, + { "event", + I18N_NOOP( " Operate for Events only (Default)" ), 0 }, + { "todo", + I18N_NOOP( " Operate for To-dos only [NOT WORKING YET]" ), 0 }, + { "journal", + I18N_NOOP( " Operate for Journals only [NOT WORKING YET]" ), 0 }, + + { ":", + I18N_NOOP( "Major operation modes:" ), 0 }, + { "view", + I18N_NOOP( " Print incidences in specified export format" ), 0 }, + { "add", + I18N_NOOP( " Insert an incidence into the calendar" ), 0 }, + { "change", + I18N_NOOP( " Modify an existing incidence" ), 0 }, + { "delete", + I18N_NOOP( " Remove an existing incidence" ), 0 }, + { "create", + I18N_NOOP( " Create new calendar file if one does not exist" ), 0 }, + { "import <import-file>", + I18N_NOOP( " Import this calendar to main calendar" ), 0 }, + { ":", + I18N_NOOP( "Operation modifiers:" ), 0 }, + { "all", + I18N_NOOP( " View all calendar entries" ), 0 }, + { "next", + I18N_NOOP( " View next activity in calendar" ), 0 }, + { "show-next <days>", + I18N_NOOP( " From start date show next # days' activities" ), 0 }, + { "uid <uid>", + I18N_NOOP( " Incidence Unique-string identifier" ), 0 }, + { "date <start-date>", + I18N_NOOP( " Start from this day [YYYY-MM-DD]" ), 0 }, + { "time <start-time>", + I18N_NOOP( " Start from this time [HH:MM:SS]" ), 0 }, + { "end-date <end-date>", + I18N_NOOP( " End at this day [YYYY-MM-DD]" ), 0 }, + { "end-time <end-time>", + I18N_NOOP( " End at this time [HH:MM:SS]" ), 0 }, + { "epoch-start <epoch-time>", + I18N_NOOP( " Start from this time [secs since epoch]" ), 0 }, + { "epoch-end <epoch-time>", + I18N_NOOP( " End at this time [secs since epoch]" ), 0 }, + { "summary <summary>", + I18N_NOOP( " Add summary to incidence (for add/change modes)" ), 0 }, + { "description <description>", + I18N_NOOP( "Add description to incidence (for add/change modes)" ), 0 }, + { "location <location>", + I18N_NOOP( " Add location to incidence (for add/change modes)" ), 0 }, + + { ":", I18N_NOOP( "Export options:" ), 0 }, + { "export-type <export-type>", + I18N_NOOP( "Export file type (Default: text)" ), 0 }, + { "export-file <export-file>", + I18N_NOOP( "Export to file (Default: stdout)" ), 0 }, + { "export-list", + I18N_NOOP( " Print list of export types supported and exit" ), 0 }, + + { "", + I18N_NOOP( "Examples:\n" + " konsolekalendar --view\n" + " konsolekalendar --add --date 2003-06-04 " + "--time 10:00 --end-time 12:00 \\\n" + " --summary \"Doctor Visit\" " + "--description \"Get My Head Examined\"\n" + " konsolekalendar --delete --uid KOrganizer-1740326.803" ), 0 }, + + { "", + I18N_NOOP( "For more information visit the program home page at:\n" + " http://pim.kde.org/components/konsolekalendar.php" ), 0 }, + + KCmdLineLastOption +}; + +int main( int argc, char *argv[] ) +{ + KAboutData aboutData( + progName, // internal program name + I18N_NOOP( progDisplay ), // displayable program name. + progVersion, // version string + I18N_NOOP( progDesc ), // short porgram description + KAboutData::License_GPL, // license type + "(c) 2002-2005, Tuukka Pasanen and Allen Winter", // copyright statement + 0, // any free form text + progURL, // program home page address + "bugs.kde.org" // bug report email address + ); + + aboutData.addAuthor( + "Tuukka Pasanen", // developer's name + I18N_NOOP( "Primary Author" ), // task or role + "illuusio@mailcity.com", // email address + 0 // home page or relevant link + ); + aboutData.addAuthor( + "Allen Winter", // developer's name + I18N_NOOP( "Author" ), // task or role + "winter@kde.org", // email address + 0 // home page or relevant link + ); + + //TODO: KDE 4.0, add the StdCmdLineArgs option to init() + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. + + KApplication app( + false, //do not allowstyles - disable the loading on plugin based styles + false //GUI is not enabled - disable all GUI stuff + ); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + // Default values for start date/time (today at 07:00) + QDate startdate = QDate::currentDate(); + QTime starttime( 7, 0 ); + + // Default values for end date/time (today at 17:00) + QDate enddate = QDate::currentDate(); + QTime endtime( 17, 0 ); + + // Default values for switches + bool view = true; + bool add = false; + bool change = false; + bool del = false; + bool create = false; + bool calendarFile = false; + bool importFile = false; + + QString option; + + KonsoleKalendarVariables variables; + KonsoleKalendarEpoch epochs; + + variables.setFloating( false ); // by default, new events do NOT float + + if ( args->isSet( "verbose" ) ) { + variables.setVerbose( true ); + } + + if ( args->isSet( "dry-run" ) ) { + variables.setDryRun( true ); + } + + /* + * Switch on export list + */ + if ( args->isSet( "export-list" ) ) { + cout << endl; + cout << i18n( "%1 supports these export formats:" ). + arg( progDisplay ).local8Bit() + << endl; + cout << i18n( " %1 [Default]" ). + arg( "Text" ).local8Bit() + << endl; + cout << i18n( " %1 (like %2, but more compact)" ). + arg( "Short", "Text" ).local8Bit() + << endl; + cout << i18n( " %1" ). + arg( "HTML" ).local8Bit() + << endl; + cout << i18n( " %1 (like %2, but in a month view)" ). + arg( "HTMLmonth", "HTML" ).local8Bit() + << endl; + cout << i18n( " %1 (Comma-Separated Values)" ). + arg( "CSV" ).local8Bit() + << endl; + cout << endl; + return 0; + } + + /* + * Set incidence type(s) + */ + if ( args->isSet( "event" ) ) { + variables.setUseEvents( true ); + kdDebug() << "main | parse options | use Events" << endl; + } + if ( args->isSet( "todo" ) ) { + variables.setUseTodos( true ); + kdDebug() << "main | parse options | use To-dos" << endl; + cout << i18n( "Sorry, To-dos are not working yet." ).local8Bit() + << endl; + return 1; + } + if ( args->isSet( "journal" ) ) { + variables.setUseJournals( true ); + kdDebug() << "main | parse options | use Journals" << endl; + cout << i18n( "Sorry, Journals are not working yet." ).local8Bit() + << endl; + return 1; + } + // Use Events if no incidence type is specified on the command line + if ( !args->isSet( "event" ) && + !args->isSet( "todo" ) && + !args->isSet( "journal" ) ) { + variables.setUseEvents( true ); + kdDebug() << "main | parse options | use Events (Default)" << endl; + } + + /* + * Switch on exporting + */ + variables.setExportType( ExportTypeText ); + if ( args->isSet( "export-type" ) ) { + option = args->getOption( "export-type" ); + + if ( option.upper() == "HTML" ) { + kdDebug() << "main | export-type | Export to HTML" << endl; + variables.setExportType( ExportTypeHTML ); + } else if ( option.upper() == "HTMLMONTH" ) { + kdDebug() << "main | export-type | Export to HTML by Month" << endl; + variables.setExportType( ExportTypeMonthHTML ); + } else if ( option.upper() == "CSV" ) { + kdDebug() << "main | export-type | Export to CSV" << endl; + variables.setExportType( ExportTypeCSV ); + } else if ( option.upper() == "TEXT" ) { + kdDebug() << "main | export-type | Export to TEXT (default)" << endl; + variables.setExportType( ExportTypeText ); + } else if ( option.upper() == "SHORT" ) { + kdDebug() << "main | export-type | Export to TEXT-SHORT" << endl; + variables.setExportType( ExportTypeTextShort ); + } else { + cout << i18n( "Invalid Export Type Specified: %1" ). + arg( option ).local8Bit() + << endl; + return 1; + } + } + + /* + * Switch on export file name + */ + if ( args->isSet( "export-file" ) ) { + option = args->getOption( "export-file" ); + + kdDebug() << "main | parse options | " + << "Export File: " + << "(" << option << ")" + << endl; + + variables.setExportFile( option ); + } + + /* + * Switch on View (Print Entries). This is the default mode of operation. + */ + if ( args->isSet( "view" ) ) { + view = true; + + kdDebug() << "main | parse options | " + << "Mode: (Print incidences)" + << endl; + } + + /* + * Switch on Add (Insert Entry) + */ + if ( args->isSet( "add" ) ) { + view = false; + add = true; + + kdDebug() << "main | parse options | " + << "Mode: (Add incidence)" + << endl; + } + + /* + * Switch on Change (Modify Entry) + */ + if ( args->isSet( "change" ) ) { + view = false; + change = true; + + kdDebug() << "main | parse options | " + << "Mode: (Change incidence)" + << endl; + } + + /* + * Switch on Delete (Remove Entry) + */ + if ( args->isSet( "delete" ) ) { + view = false; + del = true; + + kdDebug() << "main | parse options | " + << "Mode: (Delete incidence)" + << endl; + } + + /* + * Switch on Create + */ + if ( args->isSet( "create" ) ) { + view = false; + create = true; + + kdDebug() << "main | parse options | " + << "Calendar File: (Create)" + << endl; + } + + /* + * If there is summary attached. + */ + if ( args->isSet( "summary" ) ) { + option = args->getOption( "summary" ); + + kdDebug() << "main | parse options | " + << "Summary: " + << "(" << option << ")" + << endl; + + variables.setSummary( option ); + } + + /* + * If there is description attached. + */ + if ( args->isSet( "description" ) ) { + option = args->getOption( "description" ); + + kdDebug() << "main | parse options | " + << "Description: " + << "(" << option << ")" + << endl; + + variables.setDescription( option ); + } + + /* + * If there is location information + */ + if ( args->isSet( "location" ) ) { + option = args->getOption( "location" ); + + kdDebug() << "main | parse options | " + << "Location: " + << "(" << option << ")" + << endl; + + variables.setLocation( option ); + } + + /* + * Show next happening and exit + */ + if ( args->isSet( "next" ) ) { + kdDebug() << "main | parse options | " + << "Show next incidence only" + << endl; + + variables.setNext( true ); + } + + /* + * Set incidence unique string identifier + */ + if ( args->isSet( "uid" ) ) { + option = args->getOption( "uid" ); + + kdDebug() << "main | parse options | " + << "incidence UID: " + << "(" << option << ")" + << endl; + + variables.setUID( option ); + } + + /* + * Set starting date for calendar + */ + if ( args->isSet( "date" ) ) { + option = args->getOption( "date" ); + + kdDebug() << "main | parse options | " + << "Start date before conversion: " + << "(" << option << ")" + << endl; + + startdate = QDate::fromString( option, Qt::ISODate ); + if ( !startdate.isValid() ) { + cout << i18n( "Invalid Start Date Specified: %1" ). + arg( option ).local8Bit() + << endl; + return 1; + } + kdDebug() << "main | parse options | " + << "Start date after conversion: " + << "(" << startdate.toString() << ")" + << endl; + } + + /* + * Set starting time + */ + if ( args->isSet( "time" ) ) { + option = args->getOption( "time" ); + + kdDebug() << "main | parse options | " + << "Start time before conversion : " + << "(" << option << ")" + << endl; + + if ( option.upper() != "FLOAT" ) { + starttime = QTime::fromString( option, Qt::ISODate ); + if ( !starttime.isValid() ) { + cout << i18n( "Invalid Start Time Specified: %1" ). + arg( option ).local8Bit() + << endl; + return 1; + } + kdDebug() << "main | parse options | " + << "Start time after conversion: " + << "(" << starttime.toString() << ")" + << endl; + } else { + variables.setFloating( true ); + kdDebug() << "main | parse options | " + << "Floating event time specified" + << endl; + } + } + + /* + * Set end date for calendar + */ + if ( args->isSet( "end-date" ) ) { + option = args->getOption( "end-date" ); + + kdDebug() << "main | parse options | " + << "End date before conversion: " + << "(" << option << ")" + << endl; + + enddate = QDate::fromString( option, Qt::ISODate ); + if ( !enddate.isValid() ) { + cout << i18n( "Invalid End Date Specified: %1" ). + arg( option ).local8Bit() + << endl; + return 1; + } + kdDebug() << "main | parse options | " + << "End date after conversion: " + << "(" << enddate.toString() << ")" + << endl; + } + + /* + * Show next # days and exit + */ + if ( args->isSet( "show-next" ) ) { + bool ok; + + option = args->getOption( "show-next" ); + kdDebug() << "main | parse options | " + << "Show " << option << " days ahead" + << endl; + variables.setDaysCount( option.toInt( &ok, 10 ) ); + + if ( !ok ) { + cout << i18n( "Invalid Date Count Specified: %1" ). + arg( option ).local8Bit() + << endl; + return 1; + } + + enddate = startdate; + enddate = enddate.addDays( variables.getDaysCount() ); + kdDebug() << "main | parse options | " + << "End date after conversion: " + << "(" << enddate.toString() << ")" + << endl; + } + + /* + * Set ending time + */ + if ( args->isSet( "end-time" ) ) { + option = args->getOption( "end-time" ); + + kdDebug() << "main | parse options | " + << "End time before conversion: " + << "(" << option << ")" + << endl; + + if ( option.upper() != "FLOAT" ) { + endtime = QTime::fromString( option, Qt::ISODate ); + if ( !endtime.isValid() ) { + cout << i18n( "Invalid End Time Specified: %1" ). + arg( option ).local8Bit() + << endl; + return 1; + } + + kdDebug() << "main | parse options | " + << "End time after conversion: " + << "(" << endtime.toString() << ")" + << endl; + } else { + variables.setFloating( true ); + kdDebug() << "main | parse options | " + << "Floating event time specified" + << endl; + } + } + + /* + * Set start date/time from epoch + */ + time_t epochstart = 0; + if ( args->isSet( "epoch-start" ) ) { + option = args->getOption( "epoch-start" ); + + kdDebug() << "main | parse options | " + << "Epoch start: " + << "(" << option << ")" + << endl; + + epochstart = ( time_t ) option.toULong( 0, 10 ); + } + + /* + * Set end date/time from epoch + */ + time_t epochend = 0; + if ( args->isSet( "epoch-end" ) ) { + option = args->getOption( "epoch-end" ); + + kdDebug() << "main | parse options | " + << "Epoch end: " + << "(" << option << ")" + << endl; + + epochend = ( time_t ) option.toULong( 0, 10 ); + } + + if ( args->isSet( "all" ) ) { + variables.setAll( true ); + } else { + variables.setAll( false ); + } + + if ( args->isSet( "import" ) ) { + view = false; + importFile = true; + option = args->getOption( "import" ); + variables.setImportFile( option ); + + kdDebug() << "main | parse options | " + << "importing file from: " + << "(" << option << ")" + << endl; + } + + KonsoleKalendar *konsolekalendar = new KonsoleKalendar( &variables ); + + if ( args->isSet( "file" ) ) { + calendarFile = true; + option = args->getOption( "file" ); + variables.setCalendarFile( option ); + + /* + * All modes need to know if the calendar file exists + * This must be done before we get to opening biz + */ + bool exists, remote; + KURL url = KURL::fromPathOrURL( variables.getCalendarFile() ); + if ( url.isLocalFile() ) { + variables.setCalendarFile( url.path() ); + exists = QFile::exists( variables.getCalendarFile() ); + remote = false; + } else if ( url.protocol().isEmpty() ) { + QFileInfo info( variables.getCalendarFile() ); + variables.setCalendarFile( info.absFilePath() ); + exists = QFile::exists( variables.getCalendarFile() ); + remote = false; + } else { + exists = true; // really have no idea if the remote file exists + remote = true; + } + + if ( create ) { + + kdDebug() << "main | createcalendar | " + << "check if calendar file already exists" + << endl; + + if ( remote ) { + cout << i18n( "Attempting to create a remote file %1" ). + arg( variables.getCalendarFile() ).local8Bit() << endl; + return 1; + } else { + if ( exists ) { + cout << i18n( "Calendar %1 already exists" ). + arg( variables.getCalendarFile() ).local8Bit() + << endl; + return 1; + } + } + + if ( konsolekalendar->createCalendar() ) { + cout << i18n( "Calendar %1 successfully created" ). + arg( variables.getCalendarFile() ).local8Bit() + << endl; + return 0; + } else { + cout << i18n( "Unable to create calendar: %1" ). + arg( variables.getCalendarFile() ).local8Bit() + << endl; + return 1; + } + } + + if ( !exists ) { + cout << i18n( "Calendar file not found %1" ). + arg( variables.getCalendarFile() ).local8Bit() + << endl; + cout << i18n( "Try --create to create new calendar file" ).local8Bit() + << endl; + return 1; + } + } + + CalendarResources *calendarResource = NULL; + /* + * Should we use local calendar or resource? + */ + if ( args->isSet( "file" ) ) { + calendarResource = new StdCalendar( variables.getCalendarFile(), + i18n( "Active Calendar" ) ); + } else { + // TODO: when certain resources (kolab) don't try to gain access to + // an X server, or dcopserver, then put back the following line which + // supports all resources, not just the standard resource. + // calendarResource = new StdCalendar(); + calendarResource = new StdCalendar( locateLocal( "data", + "korganizer/std.ics" ), + i18n( "Default Calendar" ) ); + } + if ( !args->isSet( "import" ) ) { + variables.setCalendar( calendarResource ); + calendarResource->load(); + } + + /*************************************************************************** + * Glorious date/time checking and setting code * + ***************************************************************************/ + QDateTime startdatetime, enddatetime; + + // Handle case with either date or end-date unspecified + if ( !args->isSet( "end-date" ) && !args->isSet( "show-next" ) && + args->isSet( "date" ) ) { + enddate = startdate; + kdDebug() << "main | datetimestamp | " + << "setting enddate to startdate" + << endl; + } else if ( args->isSet( "end-date" ) && !args->isSet( "date" ) ) { + startdate = enddate; + kdDebug() << "main | datetimestamp | " + << "setting startdate to enddate" + << endl; + } + + // NOTE: If neither date nor end-date specified, then event will be today. + + // Case: + // End time (or epoch) unspecified, and start time (or epoch) IS specified. + // In this case, set the ending to 1 hour after starting. + if ( !args->isSet( "end-time" ) && !args->isSet( "epoch-end" ) ) { + if ( args->isSet( "time" ) ) { + endtime = starttime.addSecs( 60 * 60 ); // end is 1 hour after start + kdDebug() << "main | datetimestamp | " + << "setting endtime 1 hour after starttime" + << endl; + } else if ( args->isSet( "epoch-start" ) ) { + startdatetime = epochs.epoch2QDateTime( epochstart ); + enddatetime = startdatetime.addSecs( 60 * 60 ); + kdDebug() << "main | datetimestamp | " + << "setting endtime 1 hour after epochstart" + << endl; + } + } + + // Case: + // Time (or epoch) unspecified, and end-time (or epoch) IS specified. + // In this case, set the starting to 1 hour before ending. + if ( !args->isSet( "time" ) && !args->isSet( "epoch-start" ) ) { + if ( args->isSet( "end-time" ) ) { + starttime = endtime.addSecs( -60 * 60 ); // start is 1 hour before end + kdDebug() << "main | datetimestamp | " + << "setting starttime 1 hour before endtime" + << endl; + } else if ( args->isSet( "epoch-end" ) ) { + enddatetime = epochs.epoch2QDateTime( epochend ); + startdatetime = enddatetime.addSecs( -60 * 60 ); + kdDebug() << "main | datetimestamp | " + << "setting starttime 1 before after epochend" + << endl; + } + } + + // Case: + // Time (or epoch) unspecified, and end-time (or epoch) unspecified. + if ( !args->isSet( "time" ) && !args->isSet( "epoch-start" ) && + !args->isSet( "end-time" ) && !args->isSet( "epoch-end" ) ) { + // set default start date/time + startdatetime = QDateTime::QDateTime( startdate, starttime ); + kdDebug() << "main | datetimestamp | " + << "setting startdatetime from " + << "default startdate (today) and starttime" + << endl; + // set default end date/time + enddatetime = QDateTime::QDateTime( enddate, endtime ); + kdDebug() << "main | datetimestamp | " + << "setting enddatetime from " + << "default enddate (today) and endtime" + << endl; + } + + // Set startdatetime, enddatetime if still necessary + if ( startdatetime.isNull() ) { + startdatetime = QDateTime::QDateTime( startdate, starttime ); + kdDebug() << "main | datetimestamp | " + << "setting startdatetime from startdate and starttime" + << endl; + } + if ( enddatetime.isNull() ) { + enddatetime = QDateTime::QDateTime( enddate, endtime ); + kdDebug() << "main | datetimestamp | " + << "setting enddatetime from enddate and endtime" + << endl; + } + + // Float check for add mode: + // Events float if time AND end-time AND epoch times are UNspecified + if ( add ) { + if ( !args->isSet( "time" ) && !args->isSet( "end-time" ) && + !args->isSet( "epoch-start" ) && !args->isSet( "epoch-end" ) ) { + variables.setFloating( true ); + kdDebug() << "main | floatingcheck | " + << "turn-on floating event" + << endl; + } + } + + // Finally! Set the start/end date times + if ( !change ) { + variables.setStartDateTime( startdatetime ); + variables.setEndDateTime( enddatetime ); + } else { + // Do NOT set start/end datetimes in change mode, + // unless they were specified on commandline + if ( args->isSet( "time" ) || args->isSet( "epoch-start" ) || + args->isSet( "end-time" ) || args->isSet( "epoch-end" ) ) { + variables.setStartDateTime( startdatetime ); + variables.setEndDateTime( enddatetime ); + } + } + + // Some more debug prints + kdDebug() << "main | datetimestamp | StartDate=" + << startdatetime.toString( Qt::TextDate ) + << endl; + kdDebug() << "main | datetimestamp | EndDate=" + << enddatetime.toString( Qt::TextDate ) + << endl; + + /*************************************************************************** + * Sanity checks * + ***************************************************************************/ + + // Cannot combine modes + if ( create + view + add + change + del > 1 ) { + cout << i18n( + "Only 1 operation mode " + "(view, add, change, delete, create) " + "permitted at any one time" + ).local8Bit() << endl; + return 1; + } + + // Cannot have a ending before starting + if ( startdatetime > enddatetime ) { + cout << i18n( + "Ending Date/Time occurs before the Starting Date/Time" + ).local8Bit() << endl; + return 1; + } + + /*************************************************************************** + * And away we go with the real work... * + ***************************************************************************/ + + args->clear(); // Free up some memory. + + /* + * Set our application name for use in unique IDs and error messages, + * and product ID for incidence PRODID property + */ + QString prodId = "-//K Desktop Environment//NONSGML %1 %2//EN"; + CalFormat::setApplication( progDisplay, + prodId.arg( progDisplay ).arg( progVersion ) ); + + if ( importFile ) { + if ( konsolekalendar->importCalendar() ) { + cout << i18n( "Calendar %1 successfully imported" ). + arg( variables.getImportFile() ).local8Bit() + << endl; + return 0; + } else { + cout << i18n( "Unable to import calendar: %1" ). + arg( variables.getImportFile() ).local8Bit() + << endl; + return 1; + } + } + + if ( add ) { + if ( !konsolekalendar->isEvent( startdatetime, enddatetime, + variables.getSummary() ) ) { + kdDebug() << "main | modework | " + << "calling addEvent()" + << endl; + konsolekalendar->addEvent(); + } else { + cout << i18n( + "Attempting to insert an event that already exists" + ).local8Bit() << endl; + return 1; + } + } + + if ( change ) { + kdDebug() << "main | modework | " + << "calling changeEvent()" + << endl; + if ( !variables.isUID() ) { + cout << i18n( "Missing event UID: " + "use --uid command line option" ).local8Bit() + << endl; + return 1; + } + if ( konsolekalendar->changeEvent() != true ) { + cout << i18n( "No such event UID: change event failed" ).local8Bit() + << endl; + return 1; + } + kdDebug() << "main | modework | " + << "successful changeEvent()" + << endl; + } + + if ( del ) { + kdDebug() << "main | modework | " + << "calling deleteEvent()" + << endl; + if ( !variables.isUID() ) { + cout << i18n( "Missing event UID: " + "use --uid command line option" ).local8Bit() + << endl; + return 1; + } + if ( konsolekalendar->deleteEvent() != true ) { + cout << i18n( "No such event UID: delete event failed").local8Bit() + << endl; + return 1; + } + kdDebug() << "main | modework | " + << "successful deleteEvent()" + << endl; + } + + if ( view ) { + kdDebug() << "main | modework | " + << "calling showInstance() to view events" + << endl; + if ( !konsolekalendar->showInstance() ) { + cout << i18n( "Cannot open specified export file: %1" ). + arg( variables.getExportFile() ).local8Bit() + << endl; + return 1; + } + } + + delete konsolekalendar; + + calendarResource->close(); + delete calendarResource; + + kdDebug() << "main | exiting" + << endl; + + return 0; +} diff --git a/konsolekalendar/pixmaps/Makefile.am b/konsolekalendar/pixmaps/Makefile.am new file mode 100644 index 000000000..e5515a859 --- /dev/null +++ b/konsolekalendar/pixmaps/Makefile.am @@ -0,0 +1 @@ +KDE_ICON = AUTO diff --git a/konsolekalendar/pixmaps/cr16-app-konsolekalendar.png b/konsolekalendar/pixmaps/cr16-app-konsolekalendar.png Binary files differnew file mode 100644 index 000000000..0a1bfef4b --- /dev/null +++ b/konsolekalendar/pixmaps/cr16-app-konsolekalendar.png diff --git a/konsolekalendar/pixmaps/cr22-app-konsolekalendar.png b/konsolekalendar/pixmaps/cr22-app-konsolekalendar.png Binary files differnew file mode 100644 index 000000000..31c53bf0b --- /dev/null +++ b/konsolekalendar/pixmaps/cr22-app-konsolekalendar.png diff --git a/konsolekalendar/pixmaps/cr32-app-konsolekalendar.png b/konsolekalendar/pixmaps/cr32-app-konsolekalendar.png Binary files differnew file mode 100644 index 000000000..942c48748 --- /dev/null +++ b/konsolekalendar/pixmaps/cr32-app-konsolekalendar.png diff --git a/konsolekalendar/stdcalendar.cpp b/konsolekalendar/stdcalendar.cpp new file mode 100644 index 000000000..6263172c1 --- /dev/null +++ b/konsolekalendar/stdcalendar.cpp @@ -0,0 +1,102 @@ +/* + This file was originally from libkcal, then moved into korganizer. + This version has been hacked for use by konsolekalendar. + + Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> + Copyright (c) 2005 Allen Winter <winter@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 "stdcalendar.h" + +#include <libkcal/resourcecalendar.h> +#include <libkdepim/kpimprefs.h> + +#include <kconfig.h> +#include <kstandarddirs.h> +#include <klocale.h> +#include <kurl.h> + +using namespace KCal; + +StdCalendar::StdCalendar( const QString &fileName, const QString &resName ) + : CalendarResources( KPimPrefs::timezone() ) +{ + mManager = resourceManager(); + if ( mManager->isEmpty() ) { + addFileResource( fileName, resName ); + } else { + CalendarResourceManager::ActiveIterator it; + for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) { + (*it)->load(); + } + } +} + +StdCalendar::StdCalendar() + : CalendarResources( KPimPrefs::timezone() ) +{ + readConfig(); + + mManager = resourceManager(); + if ( mManager->isEmpty() ) { + KConfig config( "korganizerrc" ); + config.setGroup( "General" ); + QString fileName = config.readPathEntry( "Active Calendar" ); + + if ( !fileName.isEmpty() ) { + addFileResource( fileName, i18n( "Active Calendar" ) ); + + } else { + // No resource created, i.e. no path found in config => use default path + addFileResource( locateLocal( "data", "korganizer/std.ics" ), + i18n( "Default Calendar" ) ); + } + } +} + +void StdCalendar::addFileResource( const QString &fileName, + const QString &resName ) +{ + KCal::ResourceCalendar *resource = 0; + + if ( !fileName.isEmpty() ) { + KURL url( fileName ); + if ( url.isLocalFile() ) { + kdDebug() << "Local resource at " << url << endl; + resource = mManager->createResource( "file" ); + if ( resource ) + resource->setValue( "File", url.path() ); + } else { + kdDebug() << "Remote Resource at " << url << endl; + resource = mManager->createResource( "remote" ); + if ( resource ) + resource->setValue( "URL", url.url() ); + } + + if ( resource ) { + resource->setTimeZoneId( KPimPrefs::timezone() ); + resource->setResourceName( resName ); + mManager->add( resource ); + mManager->setStandardResource( resource ); + } + } +} + +StdCalendar::~StdCalendar() +{ +} diff --git a/konsolekalendar/stdcalendar.h b/konsolekalendar/stdcalendar.h new file mode 100644 index 000000000..e217786f5 --- /dev/null +++ b/konsolekalendar/stdcalendar.h @@ -0,0 +1,45 @@ +/* + This file was originally from libkcal, then moved into korganizer. + This version has been hacked for use by konsolekalendar. + + Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> + Copyright (c) 2005 Allen Winter <winter@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 KONSOLEKALENDAR_STDCALENDAR_H +#define KONSOLEKALENDAR_STDCALENDAR_H + +#include <libkcal/calendarresources.h> + +namespace KCal { + +class KDE_EXPORT StdCalendar : public KCal::CalendarResources +{ + public: + StdCalendar(); + StdCalendar( const QString &fileName, const QString &resName ); + ~StdCalendar(); + + void addFileResource( const QString &fileName, const QString &resName ); + + private: + KCal::CalendarResourceManager *mManager; +}; + +} + +#endif |