//-----------------------------------------------------------------
//  The All Code Reader for Linux BETA 1 by William Yu (c)1999
//
//  You are free to modify this code under the GNU Public License.
//  Please do not remove this header.
//-----------------------------------------------------------------

#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <qstring.h>
#include <qstrlist.h>
#include <qapplication.h>
#include <qtabdialog.h>
#include <qlistbox.h>
#include <qlistview.h>
#include <qdir.h>
#include <qlayout.h>
#include <qpainter.h>
#include <qlineedit.h>
#include <qmultilinedit.h>
#include <qbitmap.h>
#include <qpushbutton.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qmessagebox.h>

#include "ac.xpm"
#include "yes.xpm"
#include "tag.xpm"
#include "black.xpm"

char *rtrim(char *text)
{
   int i;

   for (i = strlen(text)-1; i > 0; i--)
      if (text[i] == ' ')
        text[i] = 0;
      else
        break;

   return text;
}


int token(char *returned, char *text, int start, char delim)
  {
     unsigned int i;

     for (i = start; i <= strlen(text); i++)
       {
         if (text[i] == delim) 
           {
              returned[i-start] = 0;
              return i+1;
           }
         returned[i-start] = text[i];
       }

     return i;
  }

class InstallModal : public QDialog {
        Q_OBJECT
private slots:
    void InstallOne();

private:
    char *package;

public:
        InstallModal( QWidget *parent, const char *name );
        void AddPackage(const char *text) { strcpy(package, text); install_one->setText(text); }
        ~InstallModal();

        QPushButton *install_all, *install_one, *cancel;
        QLabel *label1, *label2, *label3;
        QLineEdit *lineedit;
};

    InstallModal::InstallModal( QWidget *parent, const char *name )
        : QDialog( parent, name, TRUE )
    {
        QLabel *label4 = new QLabel("Install Path:", this);
                label4->move(15, 150);
        label1 = new QLabel("Too lazy to implement",this);
                label1->move(117, 10);
                label1->setAutoResize(TRUE);
        label2 = new QLabel("Just installs this package",this);
                label2->move(117, 67);
                label2->setAutoResize(TRUE);
        label3 = new QLabel("I'm not down with it.",this);
                label3->move(117, 117);
                label3->setAutoResize(TRUE);
        lineedit = new QLineEdit(this);
                lineedit->setGeometry(100,154,150,25);

        setCaption("Install Code Packages...");
        resize(290,200);

        package = new char[100];
        install_all = new QPushButton( "*.*", this );
        install_all->setGeometry( 10,10, 100,30 );
        connect( install_all, SIGNAL(clicked()), SLOT(accept()) );
        install_one = new QPushButton( "None", this );
        install_one->setGeometry( 10,60, 100,30 );
        connect( install_one, SIGNAL(clicked()), SLOT(InstallOne()));
        cancel = new QPushButton( "&Cancel", this );
        cancel->setGeometry( 10,110, 100,30 );
        connect( cancel, SIGNAL(clicked()), SLOT(reject()) );
    }

    InstallModal::~InstallModal()
    {
       delete package;
    }

class ACReader : public QWidget
{
  Q_OBJECT

  public:
    ACReader(QWidget *parent=0, const char *name=0);

  private slots:
    void dirlistbox_ItemSelected (int);
    void packetviewbox_ItemSelected (QListViewItem *);
    void snippetviewbox_ItemSelected (QListViewItem *);
    void extractsnippet ();

  private:
    void resizeEvent(QResizeEvent *);
    void Get_DirList(const char *filespec="*");
    void Get_PacketList(const char *filespec="*.*");
    void setPacketPath(const char *packet);

    typedef struct Snippet_Structure
      {
         Q_INT32 size_index;
         Q_INT8  newcode;
         Q_INT16 num_lines;
         Q_INT32 size_snippet;
         Q_INT8  state;
         Q_INT32 reserved;
         Q_INT16 length1;
         char    *short_desc;
         Q_INT16 length2;
         char    *long_desc;
         Q_INT8  screen_shot;
      };

    QString PacketPath;
    QTabDialog *tabw;
    QListBox *dirlistbox;
    QListView *packetviewbox, *snippetviewbox;
    QMultiLineEdit *viewsnippet;
    QWidget *sel_snippet, *view_snippet;
};


ACReader::ACReader (QWidget *parent, const char *name) : QWidget( parent, name )
{
    tabw = new QTabDialog(this);
        tabw->setBackgroundPixmap(black_xpm);
    QWidget *sel_packet = new QWidget(this);
    sel_snippet = new QWidget(this);
    view_snippet = new QWidget(this);
    dirlistbox = new QListBox(sel_packet);
    packetviewbox = new QListView(sel_packet);
    snippetviewbox = new QListView(sel_snippet);
    viewsnippet = new QMultiLineEdit(view_snippet);
    QComboBox *Combobox1 = new QComboBox(FALSE, sel_packet, "Combo1");
               Combobox1->move(5,4);
               Combobox1->setFixedSize(100, 21);
               Combobox1->insertItem("*.*");
               Combobox1->insertItem("*.a*");
               Combobox1->setStyle(WindowsStyle);
    QComboBox *Combobox2 = new QComboBox(FALSE, sel_snippet, "Combo2");
               Combobox2->move(5,4);
               Combobox2->setFixedSize(100, 21);
               Combobox2->insertItem("Show All");
               Combobox2->insertItem("Show New");
               Combobox2->insertItem("Show Marked");
               Combobox2->setStyle(WindowsStyle);
    QComboBox *Combobox3 = new QComboBox(FALSE, view_snippet, "Combo2");
               Combobox3->move(5,4);
               Combobox3->setFixedSize(100, 21);
               Combobox3->insertItem("QT Woo!");
               Combobox3->insertItem("GTK+ Woo Hoo");
               Combobox3->insertItem("LessTif Woo");
               Combobox3->setStyle(WindowsStyle);
    QPushButton *Button1 = new QPushButton(sel_packet, "Button1");
             Button1->move(120,4);
             Button1->setFixedSize(50, 21);
             Button1->setText("&Search");
             Button1->setPalette(QPalette(QColor(180,180,255)));
    QPushButton *Button2 = new QPushButton(sel_snippet, "Button2");
             Button2->move(120,4);
             Button2->setFixedSize(50, 21);
             Button2->setText("E&xtract");
             Button2->setPalette(QPalette(QColor(180,180,255)));
             connect(Button2, SIGNAL(clicked()), SLOT(extractsnippet()));
    QPushButton *Button3 = new QPushButton(view_snippet, "Button2");
             Button3->move(120,4);
             Button3->setFixedSize(50, 21);
             Button3->setText("E&xtract");
             Button3->setPalette(QPalette(QColor(180,180,255)));
             connect(Button3, SIGNAL(clicked()), SLOT(extractsnippet()));

    
  // set Application options
    setCaption("All Code Reader 2000 by William Yu");
    resize(550,320);

  // set Tab options
    tabw->move(1,1);
    tabw->resize(525,350);
    tabw->addTab(sel_packet, "Select &Packet");
    tabw->addTab(sel_snippet, "Select &Snippet");
    tabw->addTab(view_snippet, "View Snippet");
    tabw->setOkButton("Exit");

  // set Directory list box options
    Get_DirList("*");
    dirlistbox->move(5,30);
    dirlistbox->resize(105,245);
    connect(dirlistbox, SIGNAL(selected(int)), SLOT(dirlistbox_ItemSelected(int)));

  // set Packet View List options
    packetviewbox->move(120,30);
    packetviewbox->addColumn("Packet",65);
    packetviewbox->addColumn("Description",167);
    packetviewbox->addColumn("Snippets");
    packetviewbox->addColumn("Maintained by");
    packetviewbox->setItemMargin(2);
    Get_PacketList("*.*");
    packetviewbox->show();
    packetviewbox->setFocusPolicy(QWidget::StrongFocus);
    connect(packetviewbox, SIGNAL(doubleClicked(QListViewItem *)), SLOT(packetviewbox_ItemSelected(QListViewItem *)));
    connect(packetviewbox, SIGNAL(returnPressed(QListViewItem *)), SLOT(packetviewbox_ItemSelected(QListViewItem *)));

  // set Snippet list box options
    snippetviewbox->move(5,30);
    snippetviewbox->addColumn("Index");
    snippetviewbox->addColumn("Subject/Description");
    snippetviewbox->addColumn("Contributor");
    snippetviewbox->addColumn("Code of");
    snippetviewbox->addColumn("Extras");
   // snippetviewbox->addColumn("In");
    snippetviewbox->setFocusPolicy(QWidget::StrongFocus);
    snippetviewbox->setItemMargin(2);

  // set View Snippet multilineedit options
    viewsnippet->move(5,30);
    connect(snippetviewbox, SIGNAL(doubleClicked(QListViewItem *)), SLOT(snippetviewbox_ItemSelected(QListViewItem *)));
    connect(snippetviewbox, SIGNAL(returnPressed(QListViewItem *)), SLOT(snippetviewbox_ItemSelected(QListViewItem *)));
}


void ACReader::resizeEvent(QResizeEvent *)
{
    packetviewbox->triggerUpdate();
    tabw->resize(width()-5, height()+30);
    dirlistbox->resize(100,height()-80);
    packetviewbox->resize(width()-150,height()-80);
    snippetviewbox->resize(width()-30,height()-80);
    viewsnippet->resize(width()-30,height()-80);
}


void ACReader::Get_DirList(const char *filespec)
{
    QDir Directory;
         Directory.setFilter (QDir::Dirs);
    const QStrList *fileslist = Directory.entryList(filespec);

    dirlistbox->clear();
    dirlistbox->insertStrList(fileslist);
}


void ACReader::Get_PacketList(const char *filespec)
{
    QDir Directory;
    QFile acfile;
    Q_INT16 id, iconsize;
    Q_INT32 snippets;
    char *Description = new char[51];
    char *Maintainer = new char[31];
    char *Snippets = new char[9];
    QListViewItem *PacketItem;
    QPixmap pm(ac_xpm);
         //   pm.setMask(pm.createHeuristicMask());
    
    QStrList *fileslist = Directory.entryList(filespec);

    packetviewbox->clear();

    for (char *f = fileslist->first(); f; f = fileslist->next())
      {
         acfile.setName(f);
         if ( acfile.open(IO_ReadOnly) )
           {
              QDataStream s(&acfile);
              s.setByteOrder(QDataStream::LittleEndian);
              s >> id;
              if (id == 257 || id == 258)
                {
                   s.readRawBytes(Description, 50);
                   Description[50] = 0;
                   s.readRawBytes(Maintainer, 30);
                   Maintainer[30] = 0;
                   s >> iconsize;
                   acfile.at(acfile.at()+iconsize);
                   if (id == 257)
                     {
                       s >> snippets;
                       sprintf(Snippets, "%d", (int)snippets);
                     }
                   else
                     strcpy(Snippets, "INSTALL");                    
                   PacketItem = new QListViewItem(packetviewbox,f,rtrim(Description),Snippets,rtrim(Maintainer));
                   PacketItem->setPixmap(0, pm);
                }
              acfile.close();
           }
      }
      /** END FOR **/

    delete Description;
    delete Maintainer;
    delete Snippets;
}


void ACReader::dirlistbox_ItemSelected (int index)
{
    QDir Directory;
    QString fullpath;

    fullpath = Directory.currentDirPath();

    if (fullpath.length() != 1)
       fullpath = fullpath + '/';

    if ( !Directory.cd(dirlistbox->text(index)) )
       warning ("Cannot find directory");
    else
       {
          fullpath = fullpath + dirlistbox->text(index);
          Directory.setCurrent(fullpath);
          Get_DirList();
          Get_PacketList();
       }
}


void ACReader::setPacketPath (const char *packet)
{
    QDir dir;

    PacketPath = dir.currentDirPath();
    if (PacketPath.length() != 1)
       PacketPath = PacketPath + '/';

    PacketPath = PacketPath + packet;
}


void ACReader::packetviewbox_ItemSelected (QListViewItem *item)
{
    QFile acfile(item->text(0));
    Q_INT16 id, iconsize;
    Q_INT32 snippets, len;
    Snippet_Structure Snippet;
    char *Text = new char[51];
    char *Subject = new char[51];
    char *Author = new char[41];
    char *CodeOf = new char[31];
    char *Snippets = new char[5];
    char *Index = new char[12];
    char *Extras = new char[5];
    char ch = 227;
    int i, st;
    QPixmap pm(yes_xpm);
            pm.setMask(pm.createHeuristicMask());
    QPixmap pm2(tag_xpm);
            pm2.setMask(pm2.createHeuristicMask());

    setPacketPath(item->text(0));
    if (acfile.open(IO_ReadOnly))
    {
       QDataStream s(&acfile);
       QListViewItem *SnippetItem;
         
       s.setByteOrder(QDataStream::LittleEndian);
       s >> id;
       if (id == 258)
       {
         InstallModal InstallCDP(this, "Install");

         InstallCDP.AddPackage(item->text(0));

         if (InstallCDP.exec()) Get_PacketList();
       }
       else
       {
         snippetviewbox->clear();
         tabw->showPage(sel_snippet);
         snippetviewbox->setFocus();
         s.readRawBytes(Text, 50);
         s.readRawBytes(Text, 30);
         s >> iconsize;
         acfile.at(acfile.at()+iconsize);
         s >> snippets;
         for (i = 1; i <= (int)snippets; i++)
           {
             sprintf(Snippets,"%4d", i);
             sprintf(Index, "%d", acfile.at());
             s >> Snippet.size_index;
             s >> Snippet.newcode;
             s >> Snippet.num_lines;
             s >> Snippet.size_snippet;
             s >> Snippet.state;
             s >> Snippet.reserved;
             s >> Snippet.length1;
             Snippet.short_desc = new char[Snippet.length1+1];
             s.readRawBytes(Snippet.short_desc, Snippet.length1);
             //Subject = strtok(Snippet.short_desc, ch);
             st = token(Subject, Snippet.short_desc, 0, ch);
             Subject[50] = 0;              // no overkill...
             //Author = strtok(NULL, ch);
             st = token(Author, Snippet.short_desc, st, ch);
             Author[40] = 0;
             //CodeOf = strtok(NULL, ch);
             st = token(CodeOf, Snippet.short_desc, st, ch);
             CodeOf[30] = 0;
             s >> Snippet.length2;
             Extras[3] = 0;
             if (Snippet.length2 > 0)
                Extras[0] = 'I';
             else
                Extras[0] = ' ';
             if (Snippet.state != 0 && Snippet.state != 7)
                Extras[1] = 'B';
             else
                Extras[1] = ' ';
           // Just skip long description
             acfile.at(acfile.at()+Snippet.length2);
             s >> Snippet.screen_shot;
             len = 0;
             if (Snippet.screen_shot > 0)
               {
                  Extras[2] = 'S';
                  s >> len;
                  acfile.at(acfile.at()+len);
                  len += 4;
               }
             else
               Extras[2] = ' ';
             Snippet.size_index -= (21+Snippet.length1+Snippet.length2+len);
           // Skip source code
             acfile.at(acfile.at()+Snippet.size_index);
             SnippetItem = new QListViewItem(snippetviewbox, Snippets, Subject, Author,
                               CodeOf, Extras, Index, 0);
             if (Snippet.newcode == 1) SnippetItem->setPixmap(0,pm);
             if (Snippet.newcode == 2) SnippetItem->setPixmap(0,pm2);

             //delete SnippetItem;
             delete Snippet.short_desc;
           }
         acfile.close();
       }
       // END IF //
    }
    // END IF //

    delete Text;
    delete Snippets;
    delete Subject;
    delete Author;
    delete CodeOf;
    delete Extras;
}


void ACReader::snippetviewbox_ItemSelected (QListViewItem *item)
{
    QFile acfile(PacketPath);
    Q_INT32 i, max, pos;
    char ch = 227;

    if ( acfile.open(IO_ReadOnly) )
      {
        QDataStream s(&acfile);
        Snippet_Structure Snippet;
        char *Text;

        viewsnippet->clear();
        tabw->showPage(view_snippet);
        s.setByteOrder(QDataStream::LittleEndian);
        pos = atoi(item->text(5));
        acfile.at(pos);            // goto index

             s >> Snippet.size_index;
             s >> Snippet.newcode;
             s >> Snippet.num_lines;
             s >> Snippet.size_snippet;
             s >> Snippet.state;
             s >> Snippet.reserved;
             s >> Snippet.length1;
             acfile.at(acfile.at()+Snippet.length1);
             s >> Snippet.length1;
             acfile.at(acfile.at()+Snippet.length1);
             s >> Snippet.screen_shot;
             if (Snippet.screen_shot > 0)
               {
                  s >> pos;
                  acfile.at(acfile.at()+pos);
               }
             max = Snippet.size_snippet - Snippet.num_lines;
             Text = new char[max];
            s.readRawBytes(Text, max);
            Text[max] = 0;
            for (i=0;i < max; i++)
              {
                if (Text[i] == ch)
                  {
                    Text[i] = '\n'; Snippet.num_lines--;
                    if (Snippet.num_lines == 0)
                      { Text[i] = 0; break; }
                  }
              }

          viewsnippet->setText(Text);
        acfile.close();
        delete Text;
      }
}


void ACReader::extractsnippet ()
{
   QListViewItem *item;

   item = snippetviewbox->currentItem();
   if (!snippetviewbox->isSelected(item)) 
     {
     }
   else
     {
       QFile acfile(PacketPath);
       Q_INT32 i, max, pos, st;
       char ch = 227;

       if ( acfile.open(IO_ReadOnly) )
         {
           QDataStream s(&acfile);
           Snippet_Structure Snippet;
           char *Text;
           char *Subject = new char[51];
           char *Author = new char[41];
           char *CodeOf = new char[31];
           char *Origin = new char[51];
           char *DateOf = new char[31];
           char *SaveFile = new char[31];

           s.setByteOrder(QDataStream::LittleEndian);
           pos = atoi(item->text(5));
           acfile.at(pos);            // goto index

             s >> Snippet.size_index;
             s >> Snippet.newcode;
             s >> Snippet.num_lines;
             s >> Snippet.size_snippet;
             s >> Snippet.state;
             s >> Snippet.reserved;
             s >> Snippet.length1;
             Snippet.short_desc = new char[Snippet.length1+1];
             s.readRawBytes(Snippet.short_desc, Snippet.length1);
             st = token(Subject, Snippet.short_desc, 0, ch);
             Subject[50] = 0;              // no overkill...
             st = token(Author, Snippet.short_desc, st, ch);
             Author[40] = 0;              // no overkill...
             st = token(CodeOf, Snippet.short_desc, st, ch);
             CodeOf[30] = 0;              // no overkill...
             st = token(Origin, Snippet.short_desc, st, ch);
             Origin[50] = 0;              // no overkill...
             st = token(DateOf, Snippet.short_desc, st, ch);
             DateOf[30] = 0;              // no overkill...
             st = token(SaveFile, Snippet.short_desc, st, ch);
             SaveFile[30] = 0;              // no overkill...

             s >> Snippet.length1;
             acfile.at(acfile.at()+Snippet.length1);
             s >> Snippet.screen_shot;
             if (Snippet.screen_shot > 0)
               {
                  s >> pos;
                  acfile.at(acfile.at()+pos);
               }
             max = Snippet.size_snippet - Snippet.num_lines;
             Text = new char[max];
            s.readRawBytes(Text, max);
            Text[max] = 0;

            switch (
            QMessageBox::information( this, SaveFile,
                                      "You can save the snippet with headers intact,\nor without the headers.\n"
                                      "Please select your choice:",
                                      "With &Header", "With&out", "&Cancel",
                                      0,
                                      2 ))
            {
               case 0: st = 0;
                       break;
               case 1: st = 1;
                       break;
               case 2: st = 2;
                       break;
            }

            if (st != 2)
            {
              QFile efile(SaveFile);

              if ( efile.open(IO_WriteOnly) )
               {
                 QDataStream es(&efile);

                 es.setByteOrder(QDataStream::LittleEndian);

                 if (Snippet.state == 0 || Snippet.state == 7)
                 {
                   for (i=0;i < max; i++)
                   {
                     if (Text[i] == ch)
                     {
                        Text[i] = '\n'; Snippet.num_lines--;
                        if (Snippet.num_lines == 0)
                           { Text[i] = 0; break; }
                     }
                   }
                   if (st == 0)
                   {

es.writeRawBytes("------------------------------------------------------------",70);
                     es << '\n';
                     es.writeRawBytes( " Author: ", 9);
                     es.writeRawBytes(Author, strlen(Author)); 
                     es << '\n';
                     es.writeRawBytes( "Subject: ", 9);
                     es.writeRawBytes(Subject, strlen(Subject)); 
                     es << '\n';
                     es.writeRawBytes( " Origin: ", 9);
                     es.writeRawBytes(Origin, strlen(Origin)); 
                     es << '\n';
                     es.writeRawBytes( "Code of: ", 9);
                     es.writeRawBytes(CodeOf, strlen(CodeOf)); 
                     es << '\n';
                     es.writeRawBytes( "Date of: ", 9);
                     es.writeRawBytes(DateOf, strlen(DateOf)); 
                     es << '\n';
es.writeRawBytes("------------------------------------------------------------",70);
                     es << '\n';
                   }
                 }
                 es.writeRawBytes(Text, max);
                 efile.close();
               }
            }
            /** END IF **/


             delete Text;
             delete Subject;
             delete Author;
             delete CodeOf;
             delete Origin;
             delete DateOf;
             delete SaveFile;
           acfile.close();
         }
     }
}

void InstallModal::InstallOne ()
{
  delete install_all;
  delete cancel;
  delete install_one;
  delete label1;
  delete label2;
  delete label3;
  Q_INT32 bytes, i, newsnips, snippets, size, MP, SnipMP;
  Q_INT16 len;
  Q_INT8 B;
  char *packet = new char[100];
  char *filename = new char[1024];
  char *text = new char[1024];
  QFile acfile(package);

  if ( acfile.open(IO_ReadOnly) )
    {
      QDataStream s(&acfile);

      s.setByteOrder(QDataStream::LittleEndian);

      acfile.at(acfile.at()+86);
      s >> len;
      acfile.at(acfile.at()+len);

    while (!acfile.atEnd())
    {
      s >> B;
      if (B != 0)
        {
           cout << "Sorry, EDIT/DELETE code packages not supported here.\n";
           exit(1);
        }
      s >> len;
      s.readRawBytes(packet, len);
      packet[len] = 0;
      strcpy(filename, lineedit->text());
      strcat(filename, packet);

      QFile packetfile(filename);
      if (packetfile.exists())
        {
           QDataStream spack(&packetfile);

           spack.setByteOrder(QDataStream::LittleEndian);

           // bypass s header
           acfile.at(acfile.at()+80);
           s >> len;
           acfile.at(acfile.at()+len);

           packetfile.open(IO_ReadWrite);
           packetfile.at(packetfile.at()+82);
           spack >> len;
           packetfile.at(packetfile.at()+len);
           SnipMP = packetfile.at();
           spack >> snippets;
           for (i=1;i<=snippets;i++)
             {
               spack >> size;
               spack >> B;
               if (B != 2)
               {
                 B = 0;
                 packetfile.at(packetfile.at()-1);
                 spack << B;
                 packetfile.at(packetfile.at()+(size-5));
               }
             }
             /** END FOR **/

           s >> newsnips;
           if (newsnips > 0)
           {
             s >> size;
             MP = packetfile.at();
             bytes = 0;
             while (bytes < size)
             {
               if (bytes + 1000 > size)
                 {
                    s.readRawBytes(text, size-bytes);
                    spack.writeRawBytes(text, size-bytes);
                 }
               else
                 {
                    s.readRawBytes(text,1000);
                    spack.writeRawBytes(text,1000);
                 }
               bytes += 1000;
             }
             /** END WHILE **/

             packetfile.at(MP);
             for (i=1;i<=newsnips;i++)
             {
               spack >> size;
               spack >> B;
               if (B != 2)
               {
                 B = 1;
                 packetfile.at(packetfile.at()-1);
                 spack << B;
               }
               packetfile.at(packetfile.at()+(size-5));
             }

             packetfile.at(SnipMP);
             snippets = snippets + newsnips;
             spack << snippets;
           }
           /** END IF **/
           packetfile.close();
        }
      else
        {
           QDataStream spack(&packetfile);

           spack.setByteOrder(QDataStream::LittleEndian);

           packetfile.open(IO_ReadWrite);
           B = 1;
           spack << B;    // write header 
           spack << B;
           s.readRawBytes(text, 80);
           spack.writeRawBytes(text, 80);
           s >> len;
           spack << len;
           s.readRawBytes(text, len);
           spack.writeRawBytes(text, len);
           s >> snippets;
           spack << snippets;
           if (snippets > 0)
           {
             s >> size;
             MP = packetfile.at();
             bytes = 0;
             while (bytes < size)
             {
               if (bytes + 1000 > size)
                 {
                    s.readRawBytes(text, size-bytes);
                    spack.writeRawBytes(text, size-bytes);
                 }
               else
                 {
                    s.readRawBytes(text,1000);
                    spack.writeRawBytes(text,1000);
                 }
               bytes += 1000;
             }
             // END WHILE

             packetfile.at(MP);
             for (i=1;i<=snippets;i++)
             {
               spack >> size;
               spack >> B;
               if (B != 2)
               {
                 B = 1;
                 packetfile.at(packetfile.at()-1);
                 spack << B;
               }
               packetfile.at(packetfile.at()+(size-5));
             }
           }
           packetfile.close();
        }      
      }
      // END WHILE

      acfile.remove();
    }

  delete text;
  delete filename;
  delete packet;

  accept();
}

#include "ac.moc"

int main(int argc, char **argv)
{
    QApplication a(argc, argv);
    ACReader AllCodeReader;

    a.setMainWidget(&AllCodeReader);
    AllCodeReader.show();

    return a.exec();
}
