/******************************************************************** * * * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * * * * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * * * ******************************************************************** function: basic codebook pack/unpack/code/decode operations ********************************************************************/ #include "config-tremor.h" #include #include #include "ogg.h" #include "ivorbiscodec.h" #include "codebook.h" #include "misc.h" #include "os.h" /* unpacks a codebook from the packet buffer into the codebook struct, readies the codebook auxiliary structures for decode *************/ int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ long i,j; memset(s,0,sizeof(*s)); /* make sure alignment is correct */ if(oggpack_read(opb,24)!=0x564342)goto _eofout; /* first the basic parameters */ s->dim=oggpack_read(opb,16); s->entries=oggpack_read(opb,24); if(s->entries==-1)goto _eofout; /* codeword ordering.... length ordered or unordered? */ switch((int)oggpack_read(opb,1)){ case 0: /* unordered */ s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); /* allocated but unused entries? */ if(oggpack_read(opb,1)){ /* yes, unused entries */ for(i=0;ientries;i++){ if(oggpack_read(opb,1)){ long num=oggpack_read(opb,5); if(num==-1)goto _eofout; s->lengthlist[i]=num+1; }else s->lengthlist[i]=0; } }else{ /* all entries used; no tagging */ for(i=0;ientries;i++){ long num=oggpack_read(opb,5); if(num==-1)goto _eofout; s->lengthlist[i]=num+1; } } break; case 1: /* ordered */ { long length=oggpack_read(opb,5)+1; s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); for(i=0;ientries;){ long num=oggpack_read(opb,_ilog(s->entries-i)); if(num==-1)goto _eofout; for(j=0;jentries;j++,i++) s->lengthlist[i]=length; length++; } } break; default: /* EOF */ return(-1); } /* Do we have a mapping to unpack? */ switch((s->maptype=oggpack_read(opb,4))){ case 0: /* no mapping */ break; case 1: case 2: /* implicitly populated value mapping */ /* explicitly populated value mapping */ s->q_min=oggpack_read(opb,32); s->q_delta=oggpack_read(opb,32); s->q_quant=oggpack_read(opb,4)+1; s->q_sequencep=oggpack_read(opb,1); { int quantvals=0; switch(s->maptype){ case 1: quantvals=_book_maptype1_quantvals(s); break; case 2: quantvals=s->entries*s->dim; break; } /* quantized values */ s->quantlist=(long *)_ogg_malloc(sizeof(*s->quantlist)*quantvals); for(i=0;iquantlist[i]=oggpack_read(opb,s->q_quant); if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout; } break; default: goto _errout; } /* all set */ return(0); _errout: _eofout: vorbis_staticbook_clear(s); return(-1); } /* the 'eliminate the decode tree' optimization actually requires the codewords to be MSb first, not LSb. This is an annoying inelegancy (and one of the first places where carefully thought out design turned out to be wrong; Vorbis II and future Ogg codecs should go to an MSb bitpacker), but not actually the huge hit it appears to be. The first-stage decode table catches most words so that bitreverse is not in the main execution path. */ static inline ogg_uint32_t bitreverse(register ogg_uint32_t x){ x= ((x>>16)&0x0000ffff) | ((x<<16)&0xffff0000); x= ((x>> 8)&0x00ff00ff) | ((x<< 8)&0xff00ff00); x= ((x>> 4)&0x0f0f0f0f) | ((x<< 4)&0xf0f0f0f0); x= ((x>> 2)&0x33333333) | ((x<< 2)&0xcccccccc); return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa); } static inline long decode_packed_entry_number(codebook *book, oggpack_buffer *b){ int read=book->dec_maxlength; long lo,hi; long lok = oggpack_look(b,book->dec_firsttablen); if (lok >= 0) { long entry = book->dec_firsttable[lok]; if(entry&0x80000000UL){ lo=(entry>>15)&0x7fff; hi=book->used_entries-(entry&0x7fff); }else{ oggpack_adv(b, book->dec_codelengths[entry-1]); return(entry-1); } }else{ lo=0; hi=book->used_entries; } lok = oggpack_look(b, read); while(lok<0 && read>1) lok = oggpack_look(b, --read); if(lok<0)return -1; /* bisect search for the codeword in the ordered list */ { ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok); while(hi-lo>1){ long p=(hi-lo)>>1; long test=book->codelist[lo+p]>testword; lo+=p&(test-1); hi-=p&(-test); } if(book->dec_codelengths[lo]<=read){ oggpack_adv(b, book->dec_codelengths[lo]); return(lo); } } oggpack_adv(b, read); return(-1); } /* Decode side is specced and easier, because we don't need to find matches using different criteria; we simply read and map. There are two things we need to do 'depending': We may need to support interleave. We don't really, but it's convenient to do it here rather than rebuild the vector later. Cascades may be additive or multiplicitive; this is not inherent in the codebook, but set in the code using the codebook. Like interleaving, it's easiest to do it here. addmul==0 -> declarative (set the value) addmul==1 -> additive addmul==2 -> multiplicitive */ /* returns the [original, not compacted] entry number or -1 on eof *********/ long vorbis_book_decode(codebook *book, oggpack_buffer *b) ICODE_ATTR; long vorbis_book_decode(codebook *book, oggpack_buffer *b){ long packed_entry=decode_packed_entry_number(book,b); if(packed_entry>=0) return(book->dec_index[packed_entry]); /* if there's no dec_index, the codebook unpacking isn't collapsed */ return(packed_entry); } /* returns 0 on OK or -1 on eof *************************************/ long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a, oggpack_buffer *b,int n,int point){ int step=n/book->dim; long *entry = (long *)alloca(sizeof(*entry)*step); ogg_int32_t **t = (ogg_int32_t **)alloca(sizeof(*t)*step); int i,j,o; int shift=point-book->binarypoint; if(shift>=0){ for (i = 0; i < step; i++) { entry[i]=decode_packed_entry_number(book,b); if(entry[i]==-1)return(-1); t[i] = book->valuelist+entry[i]*book->dim; } for(i=0,o=0;idim;i++,o+=step) for (j=0;j>shift; }else{ for (i = 0; i < step; i++) { entry[i]=decode_packed_entry_number(book,b); if(entry[i]==-1)return(-1); t[i] = book->valuelist+entry[i]*book->dim; } for(i=0,o=0;idim;i++,o+=step) for (j=0;jbinarypoint; if(shift>=0){ for(i=0;ivaluelist+entry*book->dim; for (j=0;jdim;) a[i++]+=t[j++]>>shift; } }else{ shift = -shift; for(i=0;ivaluelist+entry*book->dim; for (j=0;jdim;) a[i++]+=t[j++]<binarypoint; if(shift>=0){ for(i=0;ivaluelist+entry*book->dim; for (j=0;jdim;){ a[i++]=t[j++]>>shift; } } }else{ shift = -shift; for(i=0;ivaluelist+entry*book->dim; for (j=0;jdim;){ a[i++]=t[j++]<binarypoint; if(shift>=0){ for(i=offset;ivaluelist+entry*book->dim; for (j=0;jdim;j++){ a[chptr++][i]+=t[j]>>shift; if(chptr==ch){ chptr=0; i++; } } } } }else{ shift = -shift; for(i=offset;ivaluelist+entry*book->dim; for (j=0;jdim;j++){ a[chptr++][i]+=t[j]<192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2010 Robert Bieber
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "editorwindow.h"
#include "projectmodel.h"
#include "ui_editorwindow.h"
#include "rbfontcache.h"
#include "rbtextcache.h"
#include "newprojectdialog.h"
#include "projectexporter.h"

#include <QDesktopWidget>
#include <QFileSystemModel>
#include <QSettings>
#include <QFileDialog>
#include <QMessageBox>
#include <QGraphicsScene>
#include <QDir>
#include <QFile>

const int EditorWindow::numRecent = 5;

EditorWindow::EditorWindow(QWidget *parent) :
    QMainWindow(parent), ui(new Ui::EditorWindow), parseTreeSelection(0)
{
    ui->setupUi(this);
    prefs = new PreferencesDialog(this);
    project = 0;
    setupUI();
    loadSettings();
    setupMenus();
}


EditorWindow::~EditorWindow()
{
    delete ui;
    delete prefs;
    if(project)
        delete project;
    delete deviceConfig;
    delete deviceDock;
    delete timer;
    delete timerDock;

    RBFontCache::clearCache();
    RBTextCache::clearCache();
}

void EditorWindow::loadTabFromSkinFile(QString fileName)
{
    docToTop(fileName);

    /* Checking to see if the file is already open */
    for(int i = 0; i < ui->editorTabs->count(); i++)
    {
        TabContent* current = dynamic_cast<TabContent*>
                                (ui->editorTabs->widget(i));
        if(current->file() == fileName)
        {
            ui->editorTabs->setCurrentIndex(i);
            return;
        }
    }

    /* Adding a new document*/
    SkinDocument* doc = new SkinDocument(parseStatus, fileName, project,
                                         deviceConfig);
    addTab(doc);
    ui->editorTabs->setCurrentWidget(doc);

}

void EditorWindow::loadConfigTab(ConfigDocument* doc)
{
    for(int i = 0; i < ui->editorTabs->count(); i++)
    {
        TabContent* current = dynamic_cast<TabContent*>
                              (ui->editorTabs->widget(i));
        if(current->file() == doc->file())
        {
            ui->editorTabs->setCurrentIndex(i);
            doc->deleteLater();
            return;
        }
    }

    addTab(doc);
    ui->editorTabs->setCurrentWidget(doc);

    QObject::connect(doc, SIGNAL(titleChanged(QString)),
                     this, SLOT(tabTitleChanged(QString)));
}

void  EditorWindow::loadSettings()
{

    QSettings settings;

    /* Main Window location */
    settings.beginGroup("EditorWindow");
    QSize size = settings.value("size").toSize();
    QPoint pos = settings.value("position").toPoint();
    QByteArray state = settings.value("state").toByteArray();

    /* Recent docs/projects */
    recentDocs = settings.value("recentDocs", QStringList()).toStringList();
    recentProjects = settings.value("recentProjects",
                                    QStringList()).toStringList();

    settings.endGroup();

    if(!(size.isNull() || pos.isNull() || state.isNull()))
    {
        resize(size);
        move(pos);
        restoreState(state);
    }

}

void EditorWindow::saveSettings()
{

    QSettings settings;

    /* Saving window and panel positions */
    settings.beginGroup("EditorWindow");
    settings.setValue("position", pos());
    settings.setValue("size", size());
    settings.setValue("state", saveState());

    /* Saving recent docs/projects */
    settings.setValue("recentDocs", recentDocs);
    settings.setValue("recentProjects", recentProjects);

    settings.endGroup();
}

void EditorWindow::setupUI()
{
    /* Connecting the tab bar signals */
    QObject::connect(ui->editorTabs, SIGNAL(currentChanged(int)),
                     this, SLOT(shiftTab(int)));
    QObject::connect(ui->editorTabs, SIGNAL(tabCloseRequested(int)),
                     this, SLOT(closeTab(int)));

    /* Connecting the code gen button */
    QObject::connect(ui->fromTree, SIGNAL(pressed()),
                     this, SLOT(updateCurrent()));

    /* Connecting the preferences dialog */
    QObject::connect(ui->actionPreferences, SIGNAL(triggered()),
                     prefs, SLOT(exec()));

    /* Setting up the parse status label */
    parseStatus = new QLabel(this);
    ui->statusbar->addPermanentWidget(parseStatus);

    /* Setting the selection for parse tree highlighting initially NULL */
    parseTreeSelection = 0;

    /* Adding the skin viewer */
    viewer = new SkinViewer(this);
    ui->skinPreviewLayout->addWidget(viewer);

    /* Positioning the device settings dialog */
    deviceDock = new QDockWidget(tr("Device Configuration"), this);
    deviceConfig = new DeviceState(deviceDock);

    deviceDock->setObjectName("deviceDock");
    deviceDock->setWidget(deviceConfig);
    deviceDock->setFloating(true);
    deviceDock->move(QPoint(x() + width() / 2, y() + height() / 2));
    deviceDock->hide();

    /* Positioning the timer panel */
    timerDock = new QDockWidget(tr("Timer"), this);
    timer = new SkinTimer(deviceConfig, timerDock);

    timerDock->setObjectName("timerDock");
    timerDock->setWidget(timer);
    timerDock->setFloating(true);
    timerDock->move(QPoint(x() + width() / 2, y() + height() / 2));
    timerDock->hide();

    shiftTab(-1);
}

void EditorWindow::setupMenus()
{
    /* Adding actions to the toolbar */
    ui->toolBar->addAction(ui->actionNew_Document);
    ui->toolBar->addAction(ui->actionOpen_Document);
    ui->toolBar->addAction(ui->actionSave_Document);
    ui->toolBar->addAction(ui->actionSave_Document_As);

    ui->toolBar->addSeparator();
    ui->toolBar->addAction(ui->actionUndo);
    ui->toolBar->addAction(ui->actionRedo);

    ui->toolBar->addSeparator();
    ui->toolBar->addAction(ui->actionCut);
    ui->toolBar->addAction(ui->actionCopy);
    ui->toolBar->addAction(ui->actionPaste);

    ui->toolBar->addSeparator();
    ui->toolBar->addAction(ui->actionFind_Replace);

    /* Connecting panel show actions */
    QObject::connect(ui->actionFile_Panel, SIGNAL(triggered()),
                     this, SLOT(showPanel()));
    QObject::connect(ui->actionDisplay_Panel, SIGNAL(triggered()),
                     this, SLOT(showPanel()));
    QObject::connect(ui->actionPreview_Panel, SIGNAL(triggered()),
                     this, SLOT(showPanel()));
    QObject::connect(ui->actionDevice_Configuration, SIGNAL(triggered()),
                     deviceDock, SLOT(show()));
    QObject::connect(ui->actionTimer, SIGNAL(triggered()),
                     timerDock, SLOT(show()));

    /* Connecting the document management actions */
    QObject::connect(ui->actionNew_Document, SIGNAL(triggered()),
                     this, SLOT(newTab()));
    QObject::connect(ui->actionNew_Project, SIGNAL(triggered()),
                     this, SLOT(newProject()));

    QObject::connect(ui->actionClose_Document, SIGNAL(triggered()),
                     this, SLOT(closeCurrent()));
    QObject::connect(ui->actionClose_Project, SIGNAL(triggered()),
                     this, SLOT(closeProject()));

    QObject::connect(ui->actionSave_Document, SIGNAL(triggered()),
                     this, SLOT(saveCurrent()));
    QObject::connect(ui->actionSave_Document_As, SIGNAL(triggered()),
                     this, SLOT(saveCurrentAs()));
    QObject::connect(ui->actionExport_Project, SIGNAL(triggered()),
                     this, SLOT(exportProject()));

    QObject::connect(ui->actionOpen_Document, SIGNAL(triggered()),
                     this, SLOT(openFile()));

    QObject::connect(ui->actionOpen_Project, SIGNAL(triggered()),
                     this, SLOT(openProject()));

    /* Connecting the edit menu */
    QObject::connect(ui->actionUndo, SIGNAL(triggered()),
                     this, SLOT(undo()));
    QObject::connect(ui->actionRedo, SIGNAL(triggered()),
                     this, SLOT(redo()));
    QObject::connect(ui->actionCut, SIGNAL(triggered()),
                     this, SLOT(cut()));
    QObject::connect(ui->actionCopy, SIGNAL(triggered()),
                     this, SLOT(copy()));
    QObject::connect(ui->actionPaste, SIGNAL(triggered()),
                     this, SLOT(paste()));
    QObject::connect(ui->actionFind_Replace, SIGNAL(triggered()),
                     this, SLOT(findReplace()));

    /* Adding the recent docs/projects menus */
    for(int i = 0; i < numRecent; i++)
    {
        recentDocsMenu.append(new QAction(tr("Recent Doc"),
                                          ui->menuRecent_Files));
        recentDocsMenu.last()
                ->setShortcut(QKeySequence(tr("CTRL+")
                                           + QString::number(i + 1)));
        QObject::connect(recentDocsMenu.last(), SIGNAL(triggered()),
                         this, SLOT(openRecentFile()));
        ui->menuRecent_Files->addAction(recentDocsMenu.last());


        recentProjectsMenu.append(new QAction(tr("Recent Project"),
                                              ui->menuRecent_Projects));
        recentProjectsMenu.last()
                ->setShortcut(QKeySequence(tr("CTRL+SHIFT+") +
                                           QString::number(i + 1)));
        QObject::connect(recentProjectsMenu.last(), SIGNAL(triggered()),
                         this, SLOT(openRecentProject()));
        ui->menuRecent_Projects->addAction(recentProjectsMenu.last());
    }
    refreshRecentMenus();
}

void EditorWindow::addTab(TabContent *doc)
{
    ui->editorTabs->addTab(doc, doc->title());

    /* Connecting to title change events */
    QObject::connect(doc, SIGNAL(titleChanged(QString)),
                     this, SLOT(tabTitleChanged(QString)));
    QObject::connect(doc, SIGNAL(lineChanged(int)),
                     this, SLOT(lineChanged(int)));

    /* Connecting to settings change events */
    if(doc->type() == TabContent::Skin)
        dynamic_cast<SkinDocument*>(doc)->connectPrefs(prefs);
}


void EditorWindow::newTab()
{
    SkinDocument* doc = new SkinDocument(parseStatus, project, deviceConfig);
    addTab(doc);
    ui->editorTabs->setCurrentWidget(doc);
}

void EditorWindow::newProject()
{
    NewProjectDialog dialog(this);
    if(dialog.exec() == QDialog::Rejected)
        return;

    /* Assembling the new project if the dialog was accepted */
    NewProjectDialog::NewProjectInfo info = dialog.results();

    QDir path(info.path);
    if(!path.exists())
    {
        QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:"
                             " Project directory does not exist"));
        return;
    }

    if(path.exists(info.name))
    {
        QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:"
                             " Project directory already exists"));
        return;
    }

    if(!path.mkdir(info.name))
    {
        QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:"
                             " Project directory not writeable"));
        return;
    }

    path.cd(info.name);

    /* Making standard directories */
    path.mkdir("fonts");
    path.mkdir("icons");
    path.mkdir("backdrops");

    /* Adding the desired wps documents */
    path.mkdir("wps");
    path.cd("wps");

    if(info.sbs)
        createFile(path.filePath(info.name + ".sbs"), tr("# SBS Document\n"));
    if(info.wps)
        createFile(path.filePath(info.name + ".wps"), tr("# WPS Document\n"));
    if(info.fms)
        createFile(path.filePath(info.name + ".fms"), tr("# FMS Document\n"));
    if(info.rsbs)
        createFile(path.filePath(info.name + ".rsbs"), tr("# RSBS Document\n"));
    if(info.rwps)
        createFile(path.filePath(info.name + ".rwps"), tr("# RWPS Document\n"));
    if(info.rfms)
        createFile(path.filePath(info.name + ".rfms"), tr("# RFMS Document\n"));

    path.mkdir(info.name);

    path.cdUp();

    /* Adding the config file */
    path.mkdir("themes");
    path.cd("themes");

    /* Generating the config file */
    QString config = tr("# Config file for ") + info.name + "\n";
    config.append("#target: " + info.target + "\n\n");
    QString wpsBase = "/.rockbox/wps/";
    if(info.sbs)
        config.append("sbs: " + wpsBase + info.name + ".sbs\n");
    if(info.wps)
        config.append("wps: " + wpsBase + info.name + ".wps\n");
    if(info.fms)
        config.append("fms: " + wpsBase + info.name + ".fms\n");
    if(info.rsbs)
        config.append("rsbs: " + wpsBase + info.name + ".rsbs\n");
    if(info.rwps)
        config.append("rwps: " + wpsBase + info.name + ".rwps\n");
    if(info.rfms)
        config.append("rfms: " + wpsBase + info.name + ".rfms\n");


    createFile(path.filePath(info.name + ".cfg"),
               config);

    /* Opening the new project */
    loadProjectFile(path.filePath(info.name + ".cfg"));
}

void EditorWindow::shiftTab(int index)
{
    TabContent* widget = dynamic_cast<TabContent*>
                         (ui->editorTabs->currentWidget());
    if(index < 0)
    {
        ui->parseTree->setModel(0);
        ui->actionSave_Document->setEnabled(false);
        ui->actionSave_Document_As->setEnabled(false);
        ui->actionClose_Document->setEnabled(false);
        ui->fromTree->setEnabled(false);
        ui->actionUndo->setEnabled(false);
        ui->actionRedo->setEnabled(false);
        ui->actionCut->setEnabled(false);
        ui->actionCopy->setEnabled(false);
        ui->actionPaste->setEnabled(false);
        ui->actionFind_Replace->setEnabled(false);
        viewer->connectSkin(0);
    }
    else if(widget->type() == TabContent::Config)
    {
        ui->actionSave_Document->setEnabled(true);
        ui->actionSave_Document_As->setEnabled(true);
        ui->actionClose_Document->setEnabled(true);
        ui->actionUndo->setEnabled(false);
        ui->actionRedo->setEnabled(false);
        ui->actionCut->setEnabled(false);
        ui->actionCopy->setEnabled(false);
        ui->actionPaste->setEnabled(false);
        ui->actionFind_Replace->setEnabled(false);
        viewer->connectSkin(0);
    }
    else if(widget->type() == TabContent::Skin)
    {
        /* Syncing the tree view and the status bar */
        SkinDocument* doc = dynamic_cast<SkinDocument*>(widget);
        ui->parseTree->setModel(doc->getModel());
        parseStatus->setText(doc->getStatus());

        ui->actionSave_Document->setEnabled(true);
        ui->actionSave_Document_As->setEnabled(true);
        ui->actionClose_Document->setEnabled(true);
        ui->fromTree->setEnabled(true);

        ui->actionUndo->setEnabled(true);
        ui->actionRedo->setEnabled(true);
        ui->actionCut->setEnabled(true);
        ui->actionCopy->setEnabled(true);
        ui->actionPaste->setEnabled(true);
        ui->actionFind_Replace->setEnabled(true);

        sizeColumns();

        /* Syncing the preview */
        viewer->connectSkin(doc);


    }

    /* Hiding all the find/replace dialogs */