29 #include <QFileDialog> 
   30 #include <QMessageBox> 
   31 #include <QPushButton> 
   32 #include <QScrollArea> 
   33 #include <QDataStream> 
   34 #include <QButtonGroup> 
   35 #include <QVBoxLayout> 
   36 #include <QHBoxLayout> 
   43 #define HEADER_LENGTH   32 
   44 #define CODE_ERROR      0x0000 
   45 #define CODE_DIR        0x0010 
   46 #define CODE_DIR_END    0x0018 
   47 #define CODE_FILE       0x0020 
   48 #define CODE_LIBRARY    0x0040 
   54   all = 
new QVBoxLayout(
this);
 
   58   QHBoxLayout *h2 = 
new QHBoxLayout();
 
   61     setWindowTitle(tr(
"Create Project Package"));
 
   63     QHBoxLayout *h1 = 
new QHBoxLayout();
 
   65     QLabel *packLabel = 
new QLabel(tr(
"Package:"));
 
   67     QPushButton *ButtBrowse = 
new QPushButton(tr(
"Browse"));
 
   68     connect(ButtBrowse, SIGNAL(clicked()), SLOT(
slotBrowse()));
 
   69     h1->addWidget(packLabel);
 
   71     h1->addWidget(ButtBrowse);
 
   73     LibraryCheck = 
new QCheckBox(tr(
"include user libraries"));
 
   76     Group = 
new QGroupBox(tr(
"Choose projects:"));
 
   79     QScrollArea *scrollArea = 
new QScrollArea(
Group);
 
   80     scrollArea->setWidgetResizable(
true);
 
   82     QWidget *scrollWidget = 
new QWidget();
 
   84     QVBoxLayout *checkBoxLayout = 
new QVBoxLayout();
 
   85     scrollWidget->setLayout(checkBoxLayout);
 
   86     scrollArea->setWidget(scrollWidget);
 
   88     QVBoxLayout *areaLayout = 
new QVBoxLayout();
 
   89     areaLayout->addWidget(scrollArea);
 
   90     Group->setLayout(areaLayout);
 
   94     QPushButton *ButtCreate = 
new QPushButton(tr(
"Create"));
 
   95     h2->addWidget(ButtCreate);
 
   96     connect(ButtCreate, SIGNAL(clicked()), SLOT(
slotCreate()));
 
   97     QPushButton *ButtCancel = 
new QPushButton(tr(
"Cancel"));
 
   98     h2->addWidget(ButtCancel);
 
   99     connect(ButtCancel, SIGNAL(clicked()), SLOT(reject()));
 
  104     QStringList::iterator it;
 
  105     for(it = PrDirs.begin(); it != PrDirs.end(); it++)
 
  106        if((*it).right(4) == 
"_prj"){   
 
  107          QCheckBox *subCheck = 
new QCheckBox((*it).left((*it).length()-4));
 
  108          checkBoxLayout->addWidget(subCheck);
 
  114       ButtCreate->setEnabled(
false);
 
  117       QLabel *noProj = 
new QLabel(tr(
"No projects!"));
 
  118       checkBoxLayout->addWidget(noProj);              
 
  126     setWindowTitle(tr(
"Extract Project Package"));
 
  129     MsgText->setTextFormat(Qt::PlainText);
 
  130     MsgText->setWordWrapMode(QTextOption::NoWrap);
 
  136     ButtClose = 
new QPushButton(tr(
"Close"));
 
  139     connect(
ButtClose, SIGNAL(clicked()), SLOT(accept()));
 
  153   QString s = QFileDialog::getSaveFileName(
 
  155      tr(
"Qucs Packages")+
" (*.qucs);;"+
 
  156      tr(
"Any File")+
" (*)",
 
  157      this, 0, tr(
"Enter a Package File Name"));
 
  158   if(s.isEmpty()) 
return;
 
  163   if(Info.extension().isEmpty())
 
  175   QByteArray FileContent;
 
  177   if(!File.open(QIODevice::ReadOnly)) {
 
  178     QMessageBox::critical(
this, tr(
"Error"),
 
  179                     tr(
"Cannot open \"%1\"!").arg(FileName));
 
  183   Q_ULONG Count = File.size();
 
  184   char *p = (
char*)malloc(Count+FileName.length()+2);
 
  185   strcpy(p, FileName.latin1());
 
  186   File.readBlock(p+FileName.length()+1, Count);
 
  189   Count += FileName.length()+1;
 
  190   FileContent = qCompress((
unsigned char*)p, Count);
 
  193   Stream.writeBytes(FileContent.data(), FileContent.size());
 
  205   QStringList Entries = myDir.entryList(
"*", QDir::Files, QDir::Name);
 
  206   QStringList::iterator it;
 
  207   for(it = Entries.begin(); it != Entries.end(); ++it) {
 
  208     File.setName(myDir.absFilePath(*it));
 
  215   Entries = myDir.entryList(
"*", QDir::Dirs, QDir::Name);
 
  218   for(it = Entries.begin(); it != Entries.end(); ++it) {
 
  219     Stream << Q_UINT32(
CODE_DIR) << (*it).latin1();
 
  220     if(
insertDirectory(myDir.absPath()+QDir::separator()+(*it), Stream) < 0)
 
  232   QStringList Entries = myDir.entryList(
"*", QDir::Files, QDir::Name);
 
  233   QStringList::iterator it;
 
  234   for(it = Entries.begin(); it != Entries.end(); ++it) {
 
  235     File.setName(myDir.absFilePath(*it));
 
  247     QMessageBox::critical(
this, tr(
"Error"), tr(
"Please insert a package name!"));
 
  252   QListIterator<QCheckBox *> i(
BoxList);
 
  262       QMessageBox::critical(
this, tr(
"Error"), tr(
"Please choose at least one project!"));
 
  269   if(Info.extension().isEmpty())
 
  275     if(QMessageBox::information(
this, tr(
"Info"),
 
  276           tr(
"Output file already exists!")+
"\n"+tr(
"Overwrite it?"),
 
  277           tr(
"&Yes"), tr(
"&No"), 0,1,1))
 
  280   if(!PkgFile.open(QIODevice::ReadWrite)) {
 
  281     QMessageBox::critical(
this, tr(
"Error"), tr(
"Cannot create package!"));
 
  284   QDataStream Stream(&PkgFile);
 
  289   strcpy(Header, 
"Qucs package " PACKAGE_VERSION);
 
  298       s = p->text() + 
"_prj";
 
  299       Stream << Q_UINT32(
CODE_DIR) << s.latin1();
 
  320   QByteArray Content = PkgFile.readAll();
 
  321   Q_UINT16 Checksum = qChecksum(Content.data(), Content.size());
 
  326   QMessageBox::information(
this, tr(
"Info"),
 
  327           tr(
"Successfully created Qucs package!"));
 
  339   QString s = QFileDialog::getOpenFileName(
 
  341      tr(
"Qucs Packages")+
" (*.qucs);;"+
 
  342      tr(
"Any File")+
" (*)",
 
  343      this, 0, tr(
"Enter a Package File Name"));
 
  354   if(!PkgFile.open(QIODevice::ReadOnly)) {
 
  355     if(Info.extension().isEmpty()) s += 
".qucs";
 
  357     if(!PkgFile.open(QIODevice::ReadOnly)) {
 
  358       MsgText->append(tr(
"ERROR: Cannot open package!"));
 
  363   QDataStream Stream(&PkgFile);
 
  368   Q_UINT32 Code, Length;
 
  371   QByteArray Content = PkgFile.readAll();
 
  372   if(strncmp(Content.data(), 
"Qucs package ", 13) != 0) {
 
  373     MsgText->append(tr(
"ERROR: File contains wrong header!"));
 
  377   Version = QString(Content.data()+13);
 
  379     MsgText->append(tr(
"ERROR: Wrong version number!"));
 
  387   if(Checksum != qChecksum(Content.data(), Content.size())) {
 
  388     MsgText->append(tr(
"ERROR: Checksum mismatch!"));
 
  396     if(PkgFile.atEnd()) 
break;
 
  397     Stream >> Code >> Length;
 
  405         MsgText->append(tr(
"Leave directory \"%1\"").arg(currDir.absPath()));
 
  417         MsgText->append(tr(
"ERROR: Package is corrupt!"));
 
  424   MsgText->append(tr(
"Successfully extracted package!"));
 
  434   char *p = (
char*)malloc(Count);
 
  435   PkgFile.readBlock(p, Count);
 
  437   if(currDir.cd(QString(p))) { 
 
  438     MsgText->append(tr(
"ERROR: Project directory \"%1\" already exists!").arg(QString(p)));
 
  442   if(!currDir.mkdir(QString(p))) {
 
  443     MsgText->append(tr(
"ERROR: Cannot create directory \"%1\"!").arg(QString(p)));
 
  446   currDir.cd(QString(p));
 
  447   MsgText->append(tr(
"Create and enter directory \"%1\"").arg(currDir.absPath()));
 
  456   char *p = (
char*)malloc(Count);
 
  457   PkgFile.readBlock(p, Count);
 
  458   QByteArray Content = qUncompress((
unsigned char*)p, Count);
 
  462   QFile File(currDir.absFilePath(QString(p)));
 
  463   if(!File.open(QIODevice::WriteOnly)) {
 
  464     MsgText->append(tr(
"ERROR: Cannot create file \"%1\"!").arg(QString(p)));
 
  468   File.writeBlock(p+strlen(p)+1, Content.size()-strlen(p)-1);
 
  470   MsgText->append(tr(
"Create file \"%1\"").arg(QString(p)));
 
  477   char *p = (
char*)malloc(Count);
 
  478   PkgFile.readBlock(p, Count);
 
  479   QByteArray Content = qUncompress((
unsigned char*)p, Count);
 
  484              QDir::convertSeparators(
"/user_lib/") + QString(p));
 
  486     MsgText->append(tr(
"ERROR: User library \"%1\" already exists!").arg(QString(p)));
 
  490   if(!File.open(QIODevice::WriteOnly)) {
 
  491     MsgText->append(tr(
"ERROR: Cannot create library \"%1\"!").arg(QString(p)));
 
  495   File.writeBlock(p+strlen(p)+1, Content.size()-strlen(p)-1);
 
  497   MsgText->append(tr(
"Create library \"%1\"").arg(QString(p)));
 
tQucsSettings QucsSettings
int extractDirectory(QFile &, Q_UINT32, QDir &)
bool checkVersion(QString &Line)
QList< QCheckBox * > BoxList
Definitions and declarations for the main application. 
int extractFile(QFile &, Q_UINT32, QDir &)
int extractLibrary(QFile &, Q_UINT32)
int insertLibraries(QDataStream &)
int insertFile(const QString &, QFile &, QDataStream &)
int insertDirectory(const QString &, QDataStream &)
PackageDialog(QWidget *, bool)