~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to aktion/aktion_part.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file is part of the KDE project
 
2
    Copyright (C) 1999,2000 Kurt Granroth <granroth@kde.org>
 
3
 
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 
 
18
*/
 
19
 
 
20
#include "aktion_part.h"
 
21
 
 
22
#include <klocale.h>
 
23
#include <kiconloader.h>
 
24
#include <kinstance.h>
 
25
#include <kaction.h>
 
26
#include <kaboutdata.h>
 
27
 
 
28
#include <kparts/partmanager.h>
 
29
 
 
30
#include "kxanim.h"
 
31
#include <qtimer.h>
 
32
#include <qlabel.h>
 
33
#include <qiconset.h>
 
34
 
 
35
static const char *description = I18N_NOOP("KDE Video Player");
 
36
static const char *version     = "1.99";
 
37
 
 
38
extern "C"
 
39
{
 
40
    /**
 
41
     * This function is the 'main' function of this part.  It takes
 
42
     * the form 'void *init_lib<library name>()'.  It always returns a
 
43
     * new factory object
 
44
     */
 
45
    void *init_libaktion()
 
46
    {
 
47
        return new AktionFactory;
 
48
    }
 
49
};
 
50
 
 
51
/**
 
52
 * We need one static instance of the factory for our C 'main'
 
53
 * function
 
54
 */
 
55
KInstance *AktionFactory::s_instance = 0L;
 
56
 
 
57
AktionFactory::AktionFactory()
 
58
{
 
59
    KGlobal::locale()->insertCatalogue( QString::fromLatin1("aktion") );
 
60
}
 
61
 
 
62
AktionFactory::~AktionFactory()
 
63
{
 
64
    if (s_instance)
 
65
    {
 
66
        delete s_instance->aboutData();
 
67
        delete s_instance;
 
68
    }
 
69
 
 
70
    s_instance = 0;
 
71
}
 
72
 
 
73
QObject *AktionFactory::create(QObject *parent, const char *name, const char*,
 
74
                               const QStringList& )
 
75
{
 
76
    QObject *obj = new AktionPart((QWidget*)parent, name);
 
77
    emit objectCreated(obj);
 
78
    return obj;
 
79
}
 
80
 
 
81
KInstance *AktionFactory::instance()
 
82
{
 
83
    if ( !s_instance )
 
84
        s_instance = new KInstance( aboutData() );
 
85
    return s_instance;
 
86
}
 
87
 
 
88
KAboutData *AktionFactory::aboutData()
 
89
{
 
90
  KAboutData *about = new KAboutData("aktion", I18N_NOOP("aKtion"), version,
 
91
                                     description, KAboutData::License_GPL,
 
92
                                     "(c) 2000 Guillermo P. Marotte");
 
93
  about->addAuthor("Guillermo P. Marotte",0, "g-marotte@usa.net");
 
94
  return about;
 
95
 
96
 
 
97
AktionPart::AktionPart(QWidget *parent, const char *name)
 
98
    : KParts::ReadOnlyPart(parent, name)
 
99
{
 
100
    setInstance(AktionFactory::instance());
 
101
 
 
102
    // create a canvas to insert our widget
 
103
    QWidget *canvas = new QWidget(parent);
 
104
    canvas->setFocusPolicy(QWidget::ClickFocus);
 
105
    canvas->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
 
106
    setWidget(canvas);
 
107
 
 
108
    // create our animation widget
 
109
    widget = new KXAnim(canvas);
 
110
    widget->setLoop(true);
 
111
    widget->show();
 
112
 
 
113
    // create and connect our actions
 
114
    m_playAction = new KAction(i18n("Play"), "1rightarrow",
 
115
                               0, this,
 
116
                               SLOT(slotPlay()), actionCollection(),
 
117
                               "aktion_play");
 
118
 
 
119
    m_pauseAction = new KAction(i18n("Pause"), "player_pause",
 
120
                               0, this,
 
121
                               SLOT(slotPause()), actionCollection(),
 
122
                               "aktion_pause");
 
123
 
 
124
    m_stopAction = new KAction(i18n("Stop"), "player_stop",
 
125
                               0, this,
 
126
                               SLOT(slotStop()), actionCollection(),
 
127
                               "aktion_stop");
 
128
 
 
129
    m_backwardAction = new KAction(i18n("Backward"),
 
130
                                   "2leftarrow",
 
131
                                   0, this,
 
132
                                   SLOT(slotBackward()), actionCollection(),
 
133
                                   "aktion_backward");
 
134
 
 
135
    m_forwardAction = new KAction(i18n("Forward"), "2rightarrow",
 
136
                                  0, this,
 
137
                                  SLOT(slotForward()), actionCollection(),
 
138
                                  "aktion_forward");
 
139
 
 
140
    m_extension = new AktionBrowserExtension(this);
 
141
    setXMLFile("aktion_part.rc");
 
142
}
 
143
 
 
144
AktionPart::~AktionPart()
 
145
{
 
146
    slotStop();
 
147
}
 
148
 
 
149
bool AktionPart::openFile()
 
150
{
 
151
    widget->setFile(m_file);
 
152
    widget->stop();
 
153
    widget->show();
 
154
    QTimer::singleShot(2000, this, SLOT(slotPlay()));
 
155
 
 
156
    return true;
 
157
}
 
158
 
 
159
bool AktionPart::closeURL()
 
160
{
 
161
    slotStop();
 
162
    return ReadOnlyPart::closeURL();
 
163
}
 
164
 
 
165
void AktionPart::slotPlay()
 
166
{
 
167
    widget->play();
 
168
    m_playAction->setEnabled(false);
 
169
    m_pauseAction->setEnabled(true);
 
170
    m_stopAction->setEnabled(true);
 
171
    m_forwardAction->setEnabled(true);
 
172
    m_backwardAction->setEnabled(true);
 
173
}
 
174
 
 
175
void AktionPart::slotPause()
 
176
{
 
177
    widget->pause();
 
178
    m_playAction->setEnabled(true);
 
179
    m_pauseAction->setEnabled(false);
 
180
    m_stopAction->setEnabled(false);
 
181
    m_forwardAction->setEnabled(false);
 
182
    m_backwardAction->setEnabled(false);
 
183
}
 
184
 
 
185
void AktionPart::slotStop()
 
186
{
 
187
    widget->stop();
 
188
    m_playAction->setEnabled(true);
 
189
    m_pauseAction->setEnabled(false);
 
190
    m_stopAction->setEnabled(false);
 
191
    m_forwardAction->setEnabled(false);
 
192
    m_backwardAction->setEnabled(false);
 
193
}
 
194
 
 
195
void AktionPart::slotForward()
 
196
{
 
197
    widget->stepForward();
 
198
}
 
199
 
 
200
void AktionPart::slotBackward()
 
201
{
 
202
    widget->stepBack();
 
203
}
 
204
 
 
205
AktionBrowserExtension::AktionBrowserExtension(AktionPart *parent)
 
206
    : KParts::BrowserExtension(parent, "AktionBrowserExtension")
 
207
{
 
208
}
 
209
 
 
210
AktionBrowserExtension::~AktionBrowserExtension()
 
211
{
 
212
}
 
213
#include "aktion_part.moc"