~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to incidenceeditor-ng/main.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2010  Bertjan Broeksema <broeksema@kde.org>
 
3
  Copyright (C) 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU General Public License as published by
 
7
  the Free Software Foundation; either version 2 of the License, or
 
8
  (at your option) any later version.
 
9
 
 
10
  This program is distributed in the hope that it will be useful,
 
11
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
  GNU General Public License for more details.
 
14
 
 
15
  You should have received a copy of the GNU General Public License along
 
16
  with this program; if not, write to the Free Software Foundation, Inc.,
 
17
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
18
*/
 
19
 
 
20
#include <iostream>
 
21
 
 
22
#include <KAboutData>
 
23
#include <KApplication>
 
24
#include <KCmdLineArgs>
 
25
 
 
26
#include <calendarsupport/kcalprefs.h>
 
27
 
 
28
#include <Akonadi/Item>
 
29
#include <KCalCore/Event>
 
30
#include <KCalCore/Todo>
 
31
#include <KCalCore/Journal>
 
32
 
 
33
#include "korganizereditorconfig.h"
 
34
#include "eventortododialog.h"
 
35
#include "incidencedefaults.h"
 
36
 
 
37
using namespace IncidenceEditorNG;
 
38
 
 
39
int main( int argc, char **argv )
 
40
{
 
41
  KAboutData about( "IncidenceEditorNGApp",
 
42
                    "korganizer",
 
43
                    ki18n( "KOrganizer" ),
 
44
                    "0.1",
 
45
                    ki18n( "KDE application to run the KOrganizer incidenceeditor." ),
 
46
                    KAboutData::License_LGPL,
 
47
                    ki18n( "(C) 2010 Bertjan Broeksema" ),
 
48
                    ki18n( "Run the KOrganizer incidenceeditor ng." ),
 
49
                    "http://kdepim.kde.org",
 
50
                    "kdepim@kde.org" );
 
51
  about.addAuthor( ki18n( "Bertjan Broeksema" ), ki18n( "Author" ), "broeksema@kde.org" );
 
52
  about.setProgramIconName( "korganizer" );
 
53
 
 
54
  KCmdLineOptions options;
 
55
  options.add( "new-event", ki18n( "Creates a new event" ) );
 
56
  options.add( "new-todo", ki18n( "Creates a new todo" ) );
 
57
  options.add( "new-journal", ki18n( "Creates a new journal" ) );
 
58
  options.add( "+item",
 
59
               ki18n( "Loads an existing item, or returns without doing anything "
 
60
                      "when the item is not an event or todo." ) );
 
61
 
 
62
  KCmdLineArgs::addCmdLineOptions( options );
 
63
  KCmdLineArgs::init( argc, argv, &about );
 
64
  KApplication app;
 
65
 
 
66
  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
67
  Akonadi::Item item( -1 );
 
68
 
 
69
  IncidenceDefaults defaults;
 
70
  // Set the full emails manually here, to avoid that we get dependencies on
 
71
  // KCalPrefs all over the place.
 
72
  defaults.setFullEmails( CalendarSupport::KCalPrefs::instance()->fullEmails() );
 
73
  // NOTE: At some point this should be generalized. That is, we now use the
 
74
  //       freebusy url as a hack, but this assumes that the user has only one
 
75
  //       groupware account. Which doesn't have to be the case necessarily.
 
76
  //       This method should somehow depend on the calendar selected to which
 
77
  //       the incidence is added.
 
78
  if ( CalendarSupport::KCalPrefs::instance()->useGroupwareCommunication() ) {
 
79
    defaults.setGroupWareDomain(
 
80
      KUrl( CalendarSupport::KCalPrefs::instance()->freeBusyRetrieveUrl() ).host() );
 
81
  }
 
82
 
 
83
  if ( args->isSet( "new-event" ) ) {
 
84
    std::cout << "Creating new event..." << std::endl;
 
85
    KCalCore::Event::Ptr event( new KCalCore::Event );
 
86
    defaults.setDefaults( event );
 
87
    item.setPayload<KCalCore::Event::Ptr>( event );
 
88
  } else if ( args->isSet( "new-todo" ) ) {
 
89
    std::cout << "Creating new todo..." << std::endl;
 
90
    KCalCore::Todo::Ptr todo( new KCalCore::Todo );
 
91
    defaults.setDefaults( todo );
 
92
    item.setPayload<KCalCore::Todo::Ptr>( todo );
 
93
  } else if ( args->isSet( "new-journal" ) ) {
 
94
    std::cout << "Creating new journal..." << std::endl;
 
95
    KCalCore::Journal::Ptr journal( new KCalCore::Journal );
 
96
    defaults.setDefaults( journal );
 
97
    item.setPayload<KCalCore::Journal::Ptr>( journal );
 
98
  } else if ( args->count() == 1 ) {
 
99
    if ( argc == 2 ) {
 
100
      bool ok = false;
 
101
      qint64 id = QString( argv[1] ).toLongLong( &ok );
 
102
      if ( !ok ) {
 
103
        std::cerr << "Invalid akonadi item id given." << std::endl;
 
104
        return 1;
 
105
      }
 
106
 
 
107
      item.setId( id );
 
108
      std::cout << "Trying to load Akonadi Item " << QString::number( id ).toLatin1().data();
 
109
      std::cout << "..." << std::endl;
 
110
    } else {
 
111
      std::cerr << "Invalid argument count." << std::endl << std::endl;
 
112
      return 1;
 
113
    }
 
114
  } else {
 
115
    std::cerr << "Invalid usage." << std::endl << std::endl;
 
116
    return 1;
 
117
  }
 
118
 
 
119
  EditorConfig::setEditorConfig( new KOrganizerEditorConfig );
 
120
 
 
121
  EventOrTodoDialog dialog;
 
122
  dialog.load( item ); // The dialog will show up once the item is loaded.
 
123
 
 
124
  return app.exec();
 
125
}