Source Code (Use browser search to find items of interest.)

Class Index

kdevelop'CRealFileView (./kdevelop/kdevelop/crealfileview.h:36)

class CRealFileView : public CTreeView, public Component
{
  Q_OBJECT 

public: 
  /** construtor */
  CRealFileView(QWidget*parent=0,const char* name=0); 

  /** destructor */
  ~CRealFileView();

  /** starts the scan */
  void refresh(CProject* project);

protected: // Implementations of virtual methods.

    /** Get the current popupmenu. */
  virtual KPopupMenu *getCurrentPopup();

signals:
  /**
   * This signal is emitted when a file is selected with the left mousebutton 
   * or keyboard. It gives back the selected filename relative to the project 
   * directory. */
  void fileSelected(QString filename);
  /**
   * This signal is emitted when the "Add to Project" entry of the context menu
   * is selected. It gives back the selected filename relative to the project
   * directory. */
  void addFileToProject(QString filename);
  /**
   * This signal is emitted when the "Remove from Project" entry of the 
   * context menu is selected. It gives back the selected filename relative to
   * the project directory. */
  void removeFileFromProject(QString filename);
  /**
   * This signal is emitted when the "File Properties..." entry of the context
   * menu is selected. It gives back the selected filename relative to the
   * project directory. */
  void showFileProperties(QString filename);

  void commitFileToVCS(QString file);
  void updateFileFromVCS(QString file);

  void commitDirToVCS(QString dir);
  void updateDirFromVCS(QString dir);

protected:
  // Component notifications:
  virtual void projectClosed();
  virtual void projectOpened(CProject *prj);
    
protected slots:
  /** emits signal "fileSelected" when it gets the selectionChanged-signal from itself */
  void slotSelectionChanged(QListViewItem* selection);
  void slotAddFileToProject();
  void slotRemoveFileFromProject();
  void slotDeleteFilePhys();
  void slotShowFileProperties();
  void slotAddToRepository();
  void slotRemoveFromRepository();
  void slotUpdate();
  void slotCommit();

private: // Popupmenus
  KPopupMenu *popup;

private: // Private attributes
  QStrList filelist;
  int file_col;
  QListViewItem* pRootItem;
  CProject* project;

private: // Private methods
  /** Adds the files from a certain directory to the view. */
  void addFilesFromDir( const QString& directory, QListViewItem* parent );

  /** scans the project directory and fills the treelist */
  void scanDir(const QString& directory,QListViewItem* parent);
  QString getRelFilename(QListViewItem* pItem);
  QString getFullFilename(QListViewItem* pItem);
  bool isInstalledFile(QString filename);

};

kdevelop'CRealFileView::CRealFileView() (./kdevelop/kdevelop/crealfileview.cpp:50)

CRealFileView::CRealFileView(QWidget*parent,const char* name)
  : CTreeView(parent,name)
{
  // Create the popupmenus.
  popup = 0;

  file_col = 0;
  
  connect(this, 
          SIGNAL(selectionChanged(QListViewItem*)), 
          SLOT(slotSelectionChanged(QListViewItem*)));
}


kdevelop'CRealFileView::~CRealFileView() (./kdevelop/kdevelop/crealfileview.cpp:63)

CRealFileView::~CRealFileView(){
  if (popup)
      delete popup;
}


/*********************************************************************
 *                                                                   *
 *                          PUBLIC METHODS                           *
 *                                                                   *
 ********************************************************************/



kdevelop'CRealFileView::projectClosed() (./kdevelop/kdevelop/crealfileview.cpp:76)

void CRealFileView::projectClosed()
{
    clear();
}



kdevelop'CRealFileView::projectOpened() (./kdevelop/kdevelop/crealfileview.cpp:82)

void CRealFileView::projectOpened(CProject *prj)
{
    refresh(prj);
}


/*------------------------------------------ CRealFileView::refresh()
 * refresh()
 *   Add all files in the project directory.
 *
 * Parameters:
 *   proj          The project specification.
 *
 * Returns:
 *   -
 *-----------------------------------------------------------------*/

kdevelop'CRealFileView::refresh() (./kdevelop/kdevelop/crealfileview.cpp:98)

void CRealFileView::refresh(CProject* prj) 
{
  assert( prj );

  project=prj;

  QString projectdir=project->getProjectDir();
  if(projectdir.right(1)=="/") {
    projectdir.truncate(projectdir.length()-1);
  }

  QDir dir(projectdir);
  if (!dir.exists()) {
    return;
  }

  // Remove all entries.
  treeH->clear();

  // Save all files registered in the project in the filelist variable.
  project->getAllFiles(filelist);

  // Add the root item.
  pRootItem = treeH->addRoot( projectdir, THFOLDER );
  pRootItem->setOpen(true);

  scanDir(projectdir, pRootItem);
}


kdevelop'CRealFileView::addFilesFromDir() (./kdevelop/kdevelop/crealfileview.cpp:127)

void CRealFileView::addFilesFromDir( const QString& directory, 
                                     QListViewItem* parent )
{
  QDir theDir( directory );
  QStringList fileList;
  QListViewItem* item;

  // Add all files for this directory
  theDir.setFilter(QDir::Files);
  fileList=theDir.entryList();
  QStringList::Iterator it;
  for( it = fileList.begin(); it != fileList.end(); ++it)
  {
    item = treeH->addItem( (*it), THC_FILE, parent );
    
    // If this is an installed file, we change the icon.
    if( isInstalledFile( getRelFilename( item ) ) )
      item->setPixmap( file_col, *treeH->getIcon( THINSTALLED_FILE ) );
  }
}


kdevelop'CRealFileView::scanDir() (./kdevelop/kdevelop/crealfileview.cpp:148)

void CRealFileView::scanDir(const QString& directory, QListViewItem* parent) 
{
  QString currentPath;
  QListViewItem* lastFolder;
  QStringList dirList;
  QDir dir(directory);

  // Stop recursion if the directory doesn't exist.
  if (!dir.exists()) {
    return;
  }
  
  dir.setSorting(QDir::Name);
  dir.setFilter(QDir::Dirs);
  dirList = dir.entryList();
  
  // Remove '.' and  '..'
  dirList.remove(dirList.begin());
  dirList.remove(dirList.begin());
  
  // Recurse through all directories
  QStringList::Iterator it;
  for( it = dirList.begin(); it != dirList.end(); ++it)
  {
    lastFolder = treeH->addItem( (*it), THFOLDER, parent );
    lastFolder->setOpen( true );
    
    // Recursive call to fetch subdirectories
    currentPath = directory+"//"+(*it);
    scanDir( currentPath, lastFolder );
    
    // Add the files in the recursed directory.
    //    addFilesFromDir( currentPath, lastFolder );
    
    treeH->setLastItem( lastFolder );
  } 
  
  // Add files in THIS directory as well.
  addFilesFromDir( directory, parent );
}

/*----------------------------------- CRealFileView::getCurrentPopup()
 * getCurrentPopup()
 *   Get the current popupmenu.
 *
 * Parameters:
 *   -
 * Returns:
 *   -
 *-----------------------------------------------------------------*/

kdevelop'CRealFileView::getCurrentPopup() (./kdevelop/kdevelop/crealfileview.cpp:198)

KPopupMenu *CRealFileView::getCurrentPopup()
{
  if (popup)
    delete popup;

  switch( treeH->itemType() )
  {
    case THINSTALLED_FILE:
      popup = new KPopupMenu(i18n("File (Registered)"));
      popup->insertItem( i18n("Remove File from Project..."),
                         this, SLOT(slotRemoveFileFromProject()));
      popup->insertItem( *(treeH->getIcon( THDELETE )), i18n("Remove File from Disk..."),
                         this, SLOT(slotDeleteFilePhys()));
      popup->insertSeparator();
      popup->insertItem( i18n("Properties..."),
                         this, SLOT(slotShowFileProperties()));
      break;
    case THC_FILE:
      popup = new KPopupMenu(i18n("File"));
      popup->insertItem( i18n("Add File to Project..."),
                         this, SLOT(slotAddFileToProject()));
      popup->insertItem( *(treeH->getIcon( THDELETE )), i18n("Remove File from Disk..."),
                         this, SLOT(slotDeleteFilePhys()));
      break;
    case THFOLDER:
      if (project->getVersionControl())
          {
              popup = new KPopupMenu(i18n("Folder"));
              popup->insertItem( i18n("Update"),
                                 this, SLOT(slotUpdate()) );
              popup->insertItem( i18n("Commit"),
                                 this, SLOT(slotCommit()) );
              popup->insertItem( i18n("Add to Repository"),
                                 this, SLOT(slotAddToRepository()) );
              popup->insertItem( i18n("Remove from Repository (and Disk)"),
                                 this, SLOT(slotRemoveFromRepository()) );
              break;
          }
    default:
      popup = 0;
  }

  VersionControl *vc = project->getVersionControl();
  if ( (treeH->itemType() == THINSTALLED_FILE || treeH->itemType() == THC_FILE)
       && vc)
      {
          VersionControl::State reg =
              vc->registeredState(getFullFilename(currentItem()));
          int id;
          popup->insertSeparator();
          id = popup->insertItem( i18n("Update"),
                                  this, SLOT(slotUpdate()) );
          popup->setItemEnabled(id, reg & VersionControl::canBeCommited);
          id = popup->insertItem( i18n("Commit"),
                                  this, SLOT(slotCommit()) );
          popup->setItemEnabled(id, reg & VersionControl::canBeCommited);
          id = popup->insertItem( i18n("Add to Repository"),
                                  this, SLOT(slotAddToRepository()) );
          popup->setItemEnabled(id, reg & VersionControl::canBeAdded);
          id = popup->insertItem( i18n("Remove from Repository (and disk)"),
                                  this, SLOT(slotRemoveFromRepository()) );
          popup->setItemEnabled(id, !(reg & VersionControl::canBeAdded));
      }
              
  return popup;
}


kdevelop'CRealFileView::getRelFilename() (./kdevelop/kdevelop/crealfileview.cpp:265)

QString CRealFileView::getRelFilename(QListViewItem* pItem) {

  QString filename = pItem->text(file_col);
  if (pItem != pRootItem) {
    pItem=pItem->parent();
  }
  while (pItem != pRootItem) {
    filename = QString(pItem->text(file_col)) + "/" + filename;
    pItem = pItem->parent();
  }
  return filename;
}


kdevelop'CRealFileView::getFullFilename() (./kdevelop/kdevelop/crealfileview.cpp:278)

QString CRealFileView::getFullFilename(QListViewItem* pItem) {

  QString filename = pItem->text(file_col);
  while (pItem != pRootItem) {
    pItem = pItem->parent();
    filename = QString(pItem->text(file_col)) + "/" + filename;
  }
  return filename;
}


kdevelop'CRealFileView::isInstalledFile() (./kdevelop/kdevelop/crealfileview.cpp:288)

bool CRealFileView::isInstalledFile(QString filename) 
{
  return ( filelist.contains(filename) > 0 );
}

/*********************************************************************
 *                                                                   *
 *                              SLOTS                                *
 *                                                                   *
 ********************************************************************/


kdevelop'CRealFileView::slotSelectionChanged() (./kdevelop/kdevelop/crealfileview.cpp:299)

void CRealFileView::slotSelectionChanged(QListViewItem* selection) 
{
  THType itemType=treeH->itemType();

  // this patch is needed, if we change back the root icon to THPROJECT
  // it doesn't disturb the current settings, i did this to sync the branches
  //  W. Tasin
  if( itemType!=THFOLDER && itemType!=THPROJECT &&
	(mouseBtn == LeftButton || mouseBtn == MidButton))
    emit fileSelected(getFullFilename(selection));
}


kdevelop'CRealFileView::slotAddFileToProject() (./kdevelop/kdevelop/crealfileview.cpp:311)

void CRealFileView::slotAddFileToProject() {

  QString filename=getFullFilename(currentItem());
  QString msg = i18n("Do you want to add the file\n%1\nto the project ?").arg(filename);
  if (KMessageBox::questionYesNo(0, msg) == KMessageBox::No)
    return;

  currentItem()->setPixmap( file_col, *treeH->getIcon( THINSTALLED_FILE ) );
  emit addFileToProject(filename);
}


kdevelop'CRealFileView::slotRemoveFileFromProject() (./kdevelop/kdevelop/crealfileview.cpp:322)

void CRealFileView::slotRemoveFileFromProject() {

  QString filename=getRelFilename(currentItem());
  QString msg = i18n("Do you really want to remove the file\n%1\nfrom project?\n\t\tIt will remain on disk.").arg(filename);
  if (KMessageBox::warningYesNo(0, msg) == KMessageBox::No)
    return;

  emit removeFileFromProject(filename);
}


kdevelop'CRealFileView::slotDeleteFilePhys() (./kdevelop/kdevelop/crealfileview.cpp:332)

void CRealFileView::slotDeleteFilePhys() {

  QString filename=getRelFilename(currentItem());
  QString msg = i18n("Do you really want to delete the file\n%1\nfrom the disk?\nThere is no way to restore it!").arg(filename);
  if (KMessageBox::warningYesNo(0, msg) == KMessageBox::No)
    return;

  QFile::remove(getFullFilename(currentItem()));

  if (isInstalledFile(filename)) 
    emit removeFileFromProject(filename);

  refresh(project);
}


kdevelop'CRealFileView::slotShowFileProperties() (./kdevelop/kdevelop/crealfileview.cpp:347)

void CRealFileView::slotShowFileProperties() {
  emit showFileProperties(getRelFilename(currentItem()));
}



kdevelop'CRealFileView::slotAddToRepository() (./kdevelop/kdevelop/crealfileview.cpp:352)

void CRealFileView::slotAddToRepository()
{
    project->getVersionControl()->add(getFullFilename(currentItem()));
}



kdevelop'CRealFileView::slotRemoveFromRepository() (./kdevelop/kdevelop/crealfileview.cpp:358)

void CRealFileView::slotRemoveFromRepository()
{
    project->getVersionControl()->remove(getFullFilename(currentItem()));
    refresh(project);
}
 


kdevelop'CRealFileView::slotUpdate() (./kdevelop/kdevelop/crealfileview.cpp:365)

void CRealFileView::slotUpdate()
{
    QString file_dir_name = getFullFilename(currentItem());
    QFileInfo file_info(file_dir_name);
    if (file_info.isFile()){ 
	emit updateFileFromVCS(file_dir_name);
    }
    if(file_info.isDir()){
      emit updateDirFromVCS(file_dir_name);
    }
}



kdevelop'CRealFileView::slotCommit() (./kdevelop/kdevelop/crealfileview.cpp:378)

void CRealFileView::slotCommit()
{
    QString file_dir_name = getFullFilename(currentItem());
    QFileInfo file_info(file_dir_name);
    if (file_info.isFile()){ 
	emit commitFileToVCS(file_dir_name);
    }
    if(file_info.isDir()){
      emit commitDirToVCS(file_dir_name);
    }
}