• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kgpg

  • sources
  • kde-4.14
  • kdeutils
  • kgpg
  • editor
kgpgmd5widget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 #include "kgpgmd5widget.h"
11 
12 #include <QHBoxLayout>
13 #include <QClipboard>
14 #include <QLabel>
15 #include <QFile>
16 
17 #include <KApplication>
18 #include <KMessageBox>
19 #include <KLineEdit>
20 #include <KLocale>
21 #include <KCodecs>
22 #include <KLed>
23 
24 
25 Md5Widget::Md5Widget(QWidget *parent, const KUrl &url)
26  : KDialog(parent)
27 {
28  setCaption(i18n("MD5 Checksum"));
29  setButtons(Apply | Close);
30  setDefaultButton(Close);
31  setButtonText(Apply, i18n("Compare MD5 with Clipboard"));
32 
33  QFile f(url.path());
34  KMD5 checkfile;
35 
36  if (f.open(QIODevice::ReadOnly)) {
37  checkfile.update(f);
38  f.close();
39  }
40 
41  m_md5sum = QLatin1String( checkfile.hexDigest().constData() );
42 
43  QWidget *page = new QWidget(this);
44 
45  QLabel *firstlabel = new QLabel(page);
46  firstlabel->setText(i18n("MD5 sum for <b>%1</b> is:", url.fileName()));
47 
48  KLineEdit *md5lineedit = new KLineEdit(m_md5sum, page);
49  md5lineedit->setReadOnly(true);
50 
51  m_led = new KLed(QColor(80, 80, 80), KLed::Off, KLed::Sunken, KLed::Circular, page);
52  QSizePolicy policy(QSizePolicy::Fixed, QSizePolicy::Fixed);
53  policy.setVerticalStretch(0);
54  policy.setHorizontalStretch(0);
55  policy.setHeightForWidth(m_led->sizePolicy().hasHeightForWidth());
56  m_led->setSizePolicy(policy);
57 
58  m_label = new QLabel(page);
59  m_label->setText(i18n("<b>Unknown status</b>"));
60 
61  QHBoxLayout *ledlayout = new QHBoxLayout();
62  ledlayout->addWidget(m_led);
63  ledlayout->addWidget(m_label);
64 
65  QVBoxLayout *dialoglayout = new QVBoxLayout(page);
66  dialoglayout->setMargin(marginHint());
67  dialoglayout->setSpacing(spacingHint());
68  dialoglayout->addWidget(firstlabel);
69  dialoglayout->addWidget(md5lineedit);
70  dialoglayout->addLayout(ledlayout);
71  dialoglayout->addStretch();
72 
73  setMainWidget(page);
74 
75  connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
76 }
77 
78 void Md5Widget::slotApply()
79 {
80  QString text = KApplication::clipboard()->text().remove(QLatin1Char( ' ' ));
81  if (!text.isEmpty())
82  {
83  if (text.length() != m_md5sum.length())
84  KMessageBox::sorry(this, i18n("Clipboard content is not a MD5 sum."));
85  else
86  if (text == m_md5sum)
87  {
88  m_label->setText(i18n("<b>Correct checksum</b>, file is ok."));
89  m_led->setColor(QColor(Qt::green));
90  m_led->on();
91  }
92  else
93  {
94  m_label->setText(i18n("<b>Wrong checksum, <em>file corrupted</em></b>"));
95  m_led->setColor(QColor(Qt::red));
96  m_led->on();
97  }
98  }
99 }
100 
101 #include "kgpgmd5widget.moc"
QSizePolicy::setVerticalStretch
void setVerticalStretch(uchar stretchFactor)
QWidget
Md5Widget::Md5Widget
Md5Widget(QWidget *parent=0, const KUrl &url=KUrl())
Definition: kgpgmd5widget.cpp:25
QSizePolicy
QHBoxLayout
KDialog
QString::remove
QString & remove(int position, int n)
QFile
kgpgmd5widget.h
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::isEmpty
bool isEmpty() const
QVBoxLayout
QLabel::setText
void setText(const QString &)
QString
QColor
QLayout::setMargin
void setMargin(int margin)
QLatin1Char
QFile::close
virtual void close()
Md5Widget::slotApply
void slotApply()
Definition: kgpgmd5widget.cpp:78
QLatin1String
QBoxLayout::addStretch
void addStretch(int stretch)
QString::length
int length() const
QSizePolicy::setHorizontalStretch
void setHorizontalStretch(uchar stretchFactor)
QLabel
QBoxLayout::setSpacing
void setSpacing(int spacing)
QSizePolicy::setHeightForWidth
void setHeightForWidth(bool dependent)
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal