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

kgpg

kgpgmd5widget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  ***************************************************************************/
00009 
00010 #include "kgpgmd5widget.h"
00011 
00012 #include <QHBoxLayout>
00013 #include <QClipboard>
00014 #include <QLabel>
00015 #include <QFile>
00016 
00017 #include <KApplication>
00018 #include <KMessageBox>
00019 #include <KLineEdit>
00020 #include <KLocale>
00021 #include <KCodecs>
00022 #include <KLed>
00023 
00024 
00025 Md5Widget::Md5Widget(QWidget *parent, const KUrl &url)
00026          : KDialog(parent)
00027 {
00028     setCaption(i18n("MD5 Checksum"));
00029     setButtons(Apply | Close);
00030     setDefaultButton(Close);
00031     setButtonText(Apply, i18n("Compare MD5 with Clipboard"));
00032 
00033     QFile f(url.path());
00034     f.open(QIODevice::ReadOnly);
00035 
00036     KMD5 checkfile;
00037     checkfile.reset();
00038     checkfile.update(f);
00039 
00040     m_md5sum = checkfile.hexDigest().constData();
00041     f.close();
00042 
00043     QWidget *page = new QWidget(this);
00044 
00045     QLabel *firstlabel = new QLabel(page);
00046     firstlabel->setText(i18n("MD5 sum for <b>%1</b> is:", url.fileName()));
00047 
00048     KLineEdit *md5lineedit = new KLineEdit(m_md5sum, page);
00049     md5lineedit->setReadOnly(true);
00050 
00051     m_led = new KLed(QColor(80, 80, 80), KLed::Off, KLed::Sunken, KLed::Circular, page);
00052     QSizePolicy policy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0);
00053     policy.setVerticalStretch(0);
00054     policy.setHorizontalStretch(0);
00055     policy.setHeightForWidth(m_led->sizePolicy().hasHeightForWidth());
00056     m_led->setSizePolicy(policy);
00057 
00058     m_label = new QLabel(page);
00059     m_label->setText(i18n("<b>Unknown status</b>"));
00060 
00061     QHBoxLayout *ledlayout = new QHBoxLayout();
00062     ledlayout->addWidget(m_led);
00063     ledlayout->addWidget(m_label);
00064 
00065     QVBoxLayout *dialoglayout = new QVBoxLayout(page);
00066     dialoglayout->setMargin(marginHint());
00067     dialoglayout->setSpacing(spacingHint());
00068     dialoglayout->addWidget(firstlabel);
00069     dialoglayout->addWidget(md5lineedit);
00070     dialoglayout->addLayout(ledlayout);
00071     dialoglayout->addStretch();
00072 
00073     setMainWidget(page);
00074 
00075     connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
00076 }
00077 
00078 void Md5Widget::slotApply()
00079 {
00080     QString text = KApplication::clipboard()->text().remove(' ');
00081     if (!text.isEmpty())
00082     {
00083         if (text.length() != m_md5sum.length())
00084             KMessageBox::sorry(this, i18n("Clipboard content is not a MD5 sum."));
00085         else
00086         if (text == m_md5sum)
00087         {
00088             m_label->setText(i18n("<b>Correct checksum</b>, file is ok."));
00089             m_led->setColor(QColor(Qt::green));
00090             m_led->on();
00091         }
00092         else
00093         {
00094             m_label->setText(i18n("<b>Wrong checksum, <em>file corrupted</em></b>"));
00095             m_led->setColor(QColor(Qt::red));
00096             m_led->on();
00097         }
00098     }
00099 }
00100 
00101 #include "kgpgmd5widget.moc"

kgpg

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

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal