2022-10-15 15:25:25 +03:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License version 2, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
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 <KAboutData>
|
|
|
|
#include <KCmdLineArgs>
|
|
|
|
#include <KApplication>
|
|
|
|
#include <KLocale>
|
|
|
|
#include <KEMailDialog>
|
2022-10-19 18:27:41 +03:00
|
|
|
#include <KHelpMenu>
|
2022-10-15 15:25:25 +03:00
|
|
|
#include <KDebug>
|
|
|
|
|
|
|
|
static QStringList splitMailArg(const QString &arg)
|
|
|
|
{
|
|
|
|
return arg.split(QLatin1Char(','));
|
|
|
|
}
|
|
|
|
|
2023-07-12 20:12:44 +03:00
|
|
|
class KMailDialog : public KEMailDialog
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
KMailDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = 0);
|
|
|
|
~KMailDialog();
|
|
|
|
};
|
|
|
|
|
|
|
|
KMailDialog::KMailDialog(QWidget *parent, Qt::WindowFlags flags)
|
|
|
|
: KEMailDialog(parent, flags)
|
|
|
|
{
|
|
|
|
KConfigGroup kconfiggroup(KGlobal::config(), "KMailDialog");
|
|
|
|
restoreDialogSize(kconfiggroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
KMailDialog::~KMailDialog()
|
|
|
|
{
|
|
|
|
KConfigGroup kconfiggroup(KGlobal::config(), "KMailDialog");
|
|
|
|
saveDialogSize(kconfiggroup);
|
|
|
|
KGlobal::config()->sync();
|
|
|
|
}
|
|
|
|
|
2022-10-15 15:25:25 +03:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
KAboutData aboutData(
|
|
|
|
"kmail", 0, ki18n("KMail"),
|
|
|
|
"1.0.0", ki18n("Simple e-mail sender for KDE."),
|
|
|
|
KAboutData::License_GPL_V2,
|
2023-08-10 17:48:01 +03:00
|
|
|
ki18n("(c) 2022 Ivailo Monev")
|
2022-10-15 15:25:25 +03:00
|
|
|
);
|
|
|
|
|
2023-08-24 16:50:34 +03:00
|
|
|
aboutData.addAuthor(ki18n("Ivailo Monev"), ki18n("Maintainer"), "xakepa10@gmail.com");
|
2022-10-15 15:25:25 +03:00
|
|
|
aboutData.setProgramIconName(QLatin1String("internet-mail"));
|
|
|
|
|
|
|
|
KCmdLineArgs::init(argc, argv, &aboutData);
|
|
|
|
KCmdLineOptions option;
|
|
|
|
option.add("+[url]", ki18n("URL to be opened"));
|
|
|
|
KCmdLineArgs::addCmdLineOptions(option);
|
|
|
|
|
2022-10-16 14:21:17 +03:00
|
|
|
KApplication *kapplication = new KApplication();
|
2024-05-09 09:03:17 +03:00
|
|
|
kapplication->enableSessionManagement();
|
2023-07-12 20:12:44 +03:00
|
|
|
KMailDialog kmaildialog;
|
|
|
|
kmaildialog.setButtons(KDialog::Ok | KDialog::Close | KDialog::Help);
|
|
|
|
kmaildialog.show();
|
|
|
|
KHelpMenu khelpmenu(&kmaildialog, &aboutData, true);
|
|
|
|
kmaildialog.setButtonMenu(KDialog::Help, (QMenu*)khelpmenu.menu());
|
2022-10-15 15:25:25 +03:00
|
|
|
|
|
|
|
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
|
|
|
|
for (int pos = 0; pos < args->count(); pos++) {
|
|
|
|
const KUrl argurl = args->url(pos);
|
|
|
|
|
|
|
|
if (argurl.hasQueryItem("subject")) {
|
2023-07-12 20:12:44 +03:00
|
|
|
kmaildialog.setSubject(argurl.queryItemValue("subject"));
|
2022-10-15 15:25:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList mailto;
|
|
|
|
if (argurl.hasQueryItem("to")) {
|
|
|
|
mailto.append(splitMailArg(argurl.queryItemValue("to")));
|
|
|
|
}
|
|
|
|
if (argurl.hasQueryItem("cc")) {
|
|
|
|
mailto.append(splitMailArg(argurl.queryItemValue("cc")));
|
|
|
|
}
|
2022-10-15 15:33:13 +03:00
|
|
|
if (mailto.isEmpty()) {
|
2022-11-17 04:06:25 +02:00
|
|
|
mailto.append(argurl.path());
|
2022-10-15 15:33:13 +03:00
|
|
|
}
|
2023-07-12 20:12:44 +03:00
|
|
|
kmaildialog.setTo(mailto);
|
2022-10-15 15:25:25 +03:00
|
|
|
|
|
|
|
if (argurl.hasQueryItem("body")) {
|
2023-07-12 20:12:44 +03:00
|
|
|
kmaildialog.setMessage(argurl.queryItemValue("body"));
|
2022-10-15 15:25:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argurl.hasQueryItem("attach")) {
|
2023-07-12 20:12:44 +03:00
|
|
|
kmaildialog.setAttach(splitMailArg(argurl.queryItemValue("attach")));
|
2022-10-15 15:25:25 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-16 14:21:17 +03:00
|
|
|
return kapplication->exec();
|
2022-10-15 15:25:25 +03:00
|
|
|
}
|
2023-07-12 20:12:44 +03:00
|
|
|
|
|
|
|
#include "main.moc"
|