MainWindowTemps.cpp
上传用户:stc1860
上传日期:2007-01-12
资源大小:234k
文件大小:5k
源码类别:

CA认证

开发平台:

MultiPlatform

  1. /*
  2.  * Copyright (C) 2001 Christian Hohnstaedt.
  3.  *
  4.  *  All rights reserved.
  5.  *
  6.  *
  7.  *  Redistribution and use in source and binary forms, with or without 
  8.  *  modification, are permitted provided that the following conditions are met:
  9.  *
  10.  *  - Redistributions of source code must retain the above copyright notice,
  11.  *    this list of conditions and the following disclaimer.
  12.  *  - Redistributions in binary form must reproduce the above copyright notice,
  13.  *    this list of conditions and the following disclaimer in the documentation
  14.  *    and/or other materials provided with the distribution.
  15.  *  - Neither the name of the author nor the names of its contributors may be 
  16.  *    used to endorse or promote products derived from this software without
  17.  *    specific prior written permission.
  18.  *
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29.  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  30.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  *
  33.  * This program links to software with different licenses from:
  34.  *
  35.  * http://www.openssl.org which includes cryptographic software
  36.  *  written by Eric Young (eay@cryptsoft.com)"
  37.  *
  38.  * http://www.sleepycat.com
  39.  *
  40.  * http://www.trolltech.com
  41.  * 
  42.  *
  43.  *
  44.  * http://www.hohnstaedt.de/xca
  45.  * email: christian@hohnstaedt.de
  46.  *
  47.  * $Id: MainWindowTemps.cpp,v 1.14 2003/01/06 19:35:46 chris Exp $ 
  48.  *
  49.  */                           
  50. #include "MainWindow.h"
  51. void MainWindow::newTemp(int type)
  52. {
  53. pki_temp *temp = new pki_temp("--", type);
  54. if (alterTemp(temp)) {
  55. temps->insertPKI(temp);
  56. }
  57. }
  58. bool MainWindow::alterTemp(pki_temp *temp)
  59. {
  60. NewX509 *dlg = new NewX509(this, NULL, NULL, NULL, NULL, NULL, tempImg, nsImg );
  61. MARK
  62. dlg->setTemp(temp);
  63. MARK
  64. dlg->fromTemplate(temp);
  65. MARK
  66. if (!dlg->exec()) {
  67. delete dlg;
  68. return false;
  69. }
  70. dlg->toTemplate(temp);
  71. delete dlg;
  72. return true;
  73. }
  74. void MainWindow::alterTemp()
  75. {
  76. MARK
  77. pki_temp *temp = (pki_temp *)temps->getSelectedPKI();
  78. if (!temp) return;
  79. MARK
  80. string oldname = temp->getDescription();
  81. alterTemp(temp);
  82. string newname = temp->getDescription();
  83. if (newname!= oldname) {
  84. temp->setDescription(oldname);
  85. temps->renamePKI(temp, newname);
  86. }
  87. temps->updatePKI(temp);
  88. }
  89. void MainWindow::deleteTemp()
  90. {
  91. pki_temp *delTemp = (pki_temp *)temps->getSelectedPKI();
  92. if (!delTemp) return;
  93. if (QMessageBox::information(this,tr(XCA_TITLE),
  94. tr("The template") + ": '" + 
  95. QString::fromLatin1(delTemp->getDescription().c_str()) +
  96. "'n" + tr("is going to be deleted"),
  97. "Delete", "Cancel")
  98. ) return;
  99. temps->deletePKI(delTemp);
  100. }
  101. void MainWindow::insertTemp(pki_temp *temp)
  102. {
  103. temps->insertPKI(temp);
  104. }
  105. void MainWindow::certFromTemp()
  106. {
  107. pki_temp *temp = (pki_temp *)temps->getSelectedPKI();
  108. newCert(temp);
  109. }
  110. void MainWindow::reqFromTemp()
  111. {
  112. pki_temp *temp = (pki_temp *)temps->getSelectedPKI();
  113. newReq(temp);
  114. }
  115. void MainWindow::showPopupTemp(QListViewItem *item, const QPoint &pt, int x) {
  116. CERR( " popup template" );
  117. QPopupMenu *menu = new QPopupMenu(this);
  118. QPopupMenu *subMenu = new QPopupMenu(this);
  119. if (!item) {
  120. menu->insertItem(tr("New Template"),  subMenu);
  121. subMenu->insertItem(tr("Empty"), this, SLOT(newEmpTemp()));
  122. subMenu->insertItem(tr("CA"), this, SLOT(newCATemp()));
  123. subMenu->insertItem(tr("Client"), this, SLOT(newCliTemp()));
  124. subMenu->insertItem(tr("Server"), this, SLOT(newSerTemp()));
  125. }
  126. else {
  127. menu->insertItem(tr("Rename"), this, SLOT(startRenameTemp()));
  128. menu->insertItem(tr("Change"), this, SLOT(alterTemp()));
  129. menu->insertItem(tr("Delete"), this, SLOT(deleteTemp()));
  130. menu->insertItem(tr("Create certificate"), this, SLOT(certFromTemp()));
  131. menu->insertItem(tr("Create request"), this, SLOT(reqFromTemp()));
  132. }
  133. menu->exec(pt);
  134. delete menu;
  135. delete subMenu;
  136. return;
  137. }
  138. void MainWindow::renameTemp(QListViewItem *item, int col, const QString &text)
  139. {
  140. pki_base *pki = temps->getSelectedPKI(item);
  141. string txt =  text.latin1();
  142. temps->renamePKI(pki, txt);
  143. }
  144. void MainWindow::startRenameTemp()
  145. {
  146. #ifdef qt3
  147. CERR("rename" );
  148. pki_base *pki = temps->getSelectedPKI();
  149. CERR("rename" );
  150. if (!pki) return;
  151. QListViewItem *item = (QListViewItem *)pki->getPointer();
  152. item->startRename(0);
  153. #else
  154. CERR ( "rename qt2" );
  155. renamePKI(temps);
  156. #endif
  157. }