summaryrefslogtreecommitdiffstats
path: root/kmoon/kmoonapplet.cpp
blob: e4f55095789e485798d0bc057e17bd4beaf680e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 *   kmoon - a moon phase indicator
 *   $Id$
 *   Copyright (C) 1998,2000  Stephan Kulow
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

#include <tqpopupmenu.h>
#include <tqlayout.h>

#include <tdemessagebox.h>
#include <tdelocale.h>
#include <kiconloader.h>

#include "version.h"
#include "kmoondlg.h"
#include "kmoonwidget.h"
#include "kmoonapplet.h"

const char *description = I18N_NOOP("Moon Phase Indicator for TDE");

extern "C"
{
  KDE_EXPORT KPanelApplet *init(TQWidget *parent, const TQString& configFile)
  {
    TDEGlobal::locale()->insertCatalogue("kmoon");
    return new MoonPAWidget(configFile, KPanelApplet::Normal,
			    KPanelApplet::About|KPanelApplet::Preferences,
			    parent, "kmoonapplet");
  }
}

MoonPAWidget::MoonPAWidget(const TQString& configFile, Type type, int actions,
			   TQWidget *parent, const char *name)
  : KPanelApplet(configFile, type, actions, parent, name)
{
    TDEConfig *config = TDEGlobal::config();
    config->setGroup("General");

    TQVBoxLayout *vbox = new TQVBoxLayout(this, 0,0);
    moon = new MoonWidget(this);
    moon->setAngle(config->readNumEntry("Rotation", 0));
    moon->setNorthHemi(config->readBoolEntry("Northern", true));
    moon->setMask(config->readBoolEntry("Mask", false));
    vbox->addWidget(moon);
    startTimer(1000 * 60 * 20);

    popup = new TQPopupMenu();
    popup->insertItem(SmallIcon("kmoon"),
		      i18n("&About"), this,
		      TQT_SLOT(showAbout()));
    popup->insertItem(SmallIcon("configure"), i18n("&Configure..."), this,
		      TQT_SLOT(settings()));

    // missuse timerEvent for initialising
    timerEvent(0);
}

MoonPAWidget::~MoonPAWidget()
{
  delete moon;
  delete popup;
}

void MoonPAWidget::showAbout()
{
    KDialogBase *dialog = new KDialogBase(
                                i18n("About Moon Phase Indicator"),
                                KDialogBase::Yes,
                                KDialogBase::Yes, KDialogBase::Yes,
                                0, "about", true, true,
                                KStdGuiItem::ok() );

    TQPixmap ret = DesktopIcon("kmoon");
    TQString text = i18n(description) + TQString::fromLatin1("\n\n") +
		   i18n("Written by Stephan Kulow <coolo@kde.org>\n"
                            "\n"
                            "Made an applet by M G Berberich "
                            "<berberic@fmi.uni-passau.de>\n"
                            "\n"
                            "Lunar code by Chris Osburn "
                            "<chris@speakeasy.org>\n"
                            "\n"
                            "Moon graphics by Tim Beauchamp "
                            "<timb@googol.com>");

    dialog->setIcon(ret);

    KMessageBox::createKMessageBox(dialog, ret, text, TQStringList(), TQString(), 0, KMessageBox::Notify);
}

void MoonPAWidget::settings()
{
	KMoonDlg dlg(moon->angle(), moon->northHemi(), moon->mask(),
		     this, "moondlg");
	if (dlg.exec() == KMoonDlg::Accepted) {
		moon->setAngle(dlg.getAngle());
                moon->setNorthHemi(dlg.getNorthHemi());
		moon->setMask(dlg.getMask());
		TDEConfig *config = TDEGlobal::config();
		config->setGroup("General");
		config->writeEntry("Rotation", moon->angle());
                config->writeEntry("Northern", moon->northHemi());
                config->writeEntry("Mask", moon->mask());
                config->sync();
	}
	repaint();
}

void MoonPAWidget::timerEvent( TQTimerEvent * )
{
    time_t clock;
    time(&clock);
    struct tm *t = localtime(&clock);
    moon->calcStatus(mktime(t));
}

void MoonPAWidget::mousePressEvent( TQMouseEvent *e)
{
    if (!popup)
      return;

    if (e->button() == TQt::RightButton) {
      popup->popup(mapToGlobal(e->pos()));
      popup->exec();
    }
    if (e->button() == TQt::LeftButton) {
      showAbout();
    }
}

#include "kmoonapplet.moc"