Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4GUI/TGo4DiskFileBrowser.ui.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 /****************************************************************************
00017 ** ui.h extension file, included from the uic-generated form implementation.
00018 **
00019 ** If you wish to add, delete or rename slots use Qt Designer which will
00020 ** update this file, preserving your code. Create an init() slot in place of
00021 ** a constructor, and a destroy() slot in place of a destructor.
00022 *****************************************************************************/
00023 
00024 #include <iostream.h>
00025 
00026 void TGo4DiskFileBrowser::init()
00027 {
00028     // TGo4LockGuard glob;
00029     TGo4GUIRegistry *fxTGo4GUIRegistry;
00030     fxTGo4GUIRegistry = TGo4GUIRegistry::Instance();
00031     fxTGo4DiskFileBrowserSlots = (TGo4DiskFileBrowserSlots *) fxTGo4GUIRegistry->GetSlotClass("TGo4DiskFileBrowserSlots");
00032     if(fxTGo4DiskFileBrowserSlots !=0) {
00033       fxTGo4DiskFileBrowserSlots->SetGUI(this);
00034     }else{
00035       fxTGo4DiskFileBrowserSlots = new TGo4DiskFileBrowserSlots ("TGo4DiskFileBrowserSlots", "Slots Class for Qt GUI", this);
00036     }
00037    fxTGo4DiskFileBrowserStatus = (TGo4DiskFileBrowserStatus *)  fxTGo4DiskFileBrowserSlots->GetStatus();
00038    FileListView->setSorting ( 0, TRUE );
00039    ActiveItem=0;
00040    fxDragItem=0;
00041    fxContextMenu = new QPopupMenu( FileListView );
00042    Q_CHECK_PTR( fxContextMenu );
00043    fiMenuPlotID=fxContextMenu->insertItem(TGo4MainWindow::uic_load_pixmap( "h1_t" ), "Plot",  this, SLOT(PlotLocal()));
00044    fiMenuSuperID=fxContextMenu->insertItem(TGo4MainWindow::uic_load_pixmap( "superimpose.png" ), "Superimpose", this, SLOT(SuperImposeLocal()));
00045    fxContextMenu->insertSeparator();
00046    fiMenuEditID=fxContextMenu->insertItem(TGo4MainWindow::uic_load_pixmap( "control.png" ), "Edit...", this, SLOT(EditSelected()));
00047    fiMenuPropertyID=fxContextMenu->insertItem(TGo4MainWindow::uic_load_pixmap( "info.png" ), "Info...", this, SLOT(ShowProperties()));
00048    fxContextMenu->insertSeparator();
00049    fxContextMenu->insertItem(TGo4MainWindow::uic_load_pixmap( "fileopen" ), "Open local...",  this, SLOT(OpenLocalFile()));
00050    fxContextMenu->insertItem(TGo4MainWindow::uic_load_pixmap( "network.png" ), "Open remote...",  this, SLOT(OpenRemoteFile()));
00051    fiMenuCloseID=fxContextMenu->insertItem(TGo4MainWindow::uic_load_pixmap( "close1.png" ), "Close this file",  this, SLOT(CloseRootFile()));
00052    fxContextMenu->insertItem(TGo4MainWindow::uic_load_pixmap( "fileclose.png" ), "Close all files",  this, SLOT(CloseAllFiles()));
00053  
00054 }
00055 
00056 void TGo4DiskFileBrowser::destroy()
00057 {
00058     // TGo4LockGuard glob;
00059     FileListView->clear();
00060     fxTGo4DiskFileBrowserSlots->SetGUI(0);
00061 }
00062 
00063 
00064 void TGo4DiskFileBrowser::PlotLocal()
00065 {
00066     fxTGo4DiskFileBrowserSlots->PlotLocal();
00067 }
00068 
00069 void TGo4DiskFileBrowser::SuperImposeLocal()
00070 {
00071     fxTGo4DiskFileBrowserSlots->SuperImposeLocal();
00072 }
00073 
00074 
00075 void TGo4DiskFileBrowser::FileListView_doubleClicked( QListViewItem *SelectedItem )
00076 {
00077 // TGo4LockGuard glob;
00078    //cout <<"FileListView_doubleClicked" << endl;
00079    fxDragItem=0; // no drag after doubleclick
00080    if(SelectedItem!=0){
00081       fxTGo4DiskFileBrowserSlots->FileItemDoubleClicked(SelectedItem );
00082    }
00083 }
00084 
00085 
00086 void TGo4DiskFileBrowser::CloseRootFile()
00087 {
00088    CloseFile(dynamic_cast <TGo4QFileItem *> (FileListView->currentItem()));
00089 }
00090 
00091 void TGo4DiskFileBrowser::CloseAllFiles()
00092 {
00093 // first figure out all files in the browser:    
00094 QPtrList <TGo4QFileItem> lst; 
00095 QListViewItemIterator it(FileListView);
00096 for ( ; it.current(); ++it ) {
00097     TGo4QFileItem* fitem=0;
00098     if ( (fitem=dynamic_cast<TGo4QFileItem*>(it.current()))!=0)
00099         lst.append(fitem);           
00100    }    
00101 // then close these files (do not delete items inside FileListView iterator):    
00102 QPtrListIterator <TGo4QFileItem> pit(lst);
00103 while (pit.current()!=0)
00104    {
00105       CloseFile(pit.current());
00106       ++pit;
00107    }
00108 }
00109 
00110 
00111 
00112 void TGo4DiskFileBrowser::CloseFile( TGo4QFileItem * fitem )
00113 {
00114 if(fitem==0) return;
00115 //cout <<"Closing file "<<fitem->text(0) << endl;
00116 fxTGo4DiskFileBrowserStatus->RemoveFromFileListStatus((TNamed *)fitem->GetRootFile());
00117 fitem->Close();
00118 delete fitem;
00119 }
00120 
00121 
00122 
00123 
00124 void TGo4DiskFileBrowser::OpenLocalFile()
00125 {
00126    // TGo4LockGuard glob;
00127     QString fileName;
00128     QString DirPath;
00129     QFileDialog* fd = new QFileDialog( this, "Read Root File", TRUE );
00130     QString fdCaption = "Select a ROOT file to open it in the Go4 Disk Browser";
00131     fd->setCaption(fdCaption);
00132     fd->setMode( QFileDialog::ExistingFiles);
00133     fd->setName( "Open Root File ");
00134     fd->setFilter("C++ Macro (*.C)");
00135     fd->addFilter( "Root files  (*.root)" );
00136     if ( fd->exec() == QDialog::Accepted )
00137     {
00138         DirPath= fd->dirPath();
00139         QStringList list = fd->selectedFiles();
00140         QStringList::Iterator it = list.begin();
00141         while( it != list.end() )
00142             {
00143                 fileName=*it;
00144                 if(fileName.endsWith(".C"))
00145                     {
00146                          fxTGo4DiskFileBrowserSlots->OpenSelectedMacro(fileName, DirPath);;
00147                     }
00148                 else
00149                     {
00150                         fxTGo4DiskFileBrowserSlots->OpenSelectedRootFile(fileName, DirPath);
00151                     }
00152                 ++it;
00153             }// while
00154     }// if
00155     delete fd;
00156 }
00157 QPtrList  <TGo4QItem>* TGo4DiskFileBrowser::GetSelectedItems()
00158 {
00159    // TGo4LockGuard global;
00160    // Create the list
00161 
00162    QPtrList <TGo4QItem> *lst = new QPtrList <TGo4QItem>;
00163 
00164    if(FileListView->isMultiSelection()) {
00165        QListViewItemIterator it(FileListView);
00166       // iterate through all items of the list view
00167        for ( ; it.current(); ++it )
00168          if ( it.current()->isSelected() )
00169            lst->append((TGo4QItem *)it.current() );
00170    }
00171 
00172    return lst;
00173 }
00174 
00175 
00176 
00177 
00178 
00179 QString TGo4DiskFileBrowser::SaveFileDialog(const char* objectname)
00180 {
00181 QString caption="Choose a root file to save object ";
00182 caption.append(objectname);
00183 QString activefilename;
00184 TFile* activefile=fxTGo4DiskFileBrowserStatus->GetActiveFile();
00185 if(activefile)
00186     activefilename=activefile->GetName();
00187 else
00188     activefilename="...";
00189 
00190 
00191 // currently, we are only using the filename and open it again for write...
00192 QString filename = QFileDialog::getSaveFileName(
00193                     activefilename,
00194                     "Root Files (*.root)",
00195                     this,
00196                     "Save Object in file...",
00197                     caption);
00198 
00199 if(!filename.isEmpty() && !filename.contains(".root"))
00200     filename.append(".root");
00201 return filename;
00202 }
00203 
00204 
00205 QString TGo4DiskFileBrowser::LoadFileDialog(const char* objectname)
00206 {
00207 QString caption="Choose a root file to load object ";
00208 caption.append(objectname);
00209 QString activefilename;
00210 TFile* activefile=fxTGo4DiskFileBrowserStatus->GetActiveFile();
00211 if(activefile)
00212     activefilename=activefile->GetName();
00213 else
00214     activefilename="...";
00215 // currently, we are only using the filename and open it again for write...
00216 QString filename = QFileDialog::getOpenFileName(
00217                     activefilename,
00218                     "Root Files (*.root)",
00219                     this,
00220                     "Load Object from file...",
00221                     caption );
00222 if(!filename.isEmpty() && !filename.contains(".root"))
00223     filename.append(".root");
00224 return filename;
00225 }
00226 
00227 
00228 void TGo4DiskFileBrowser::RemoveFileItem( const char * name )
00229 {
00230 TGo4QFileItem * fileitem=dynamic_cast <TGo4QFileItem *> (FileListView->findItem(name,0));
00231 if(fileitem)
00232     {
00233       //cout <<"RemoveFileItem found in list "<<fileitem <<" of name "<<name<<endl;
00234       fxTGo4DiskFileBrowserStatus->RemoveFromFileListStatus((TNamed *)fileitem->GetRootFile());
00235       fileitem->Close();
00236       delete fileitem;
00237     }
00238 
00239 }
00240 
00241 
00242 void TGo4DiskFileBrowser::SetListFocus()
00243 {
00244     FileListView->setFocus();
00245 }
00246 
00247 
00248 void TGo4DiskFileBrowser::FileListView_pressed( QListViewItem * SelectedItem)
00249 {
00250 fxDragItem=SelectedItem;
00251 int timems=QApplication::startDragTime();
00252 //cout <<"FileListView_pressed starts timer with "<<timems << endl;
00253 QTimer::singleShot( timems, this, SLOT(StartListviewDrag()) ); 
00254 }
00255 
00256 
00257 void TGo4DiskFileBrowser::FileListView_contextMenuRequested( QListViewItem * selitem, const QPoint & pt, int )
00258 {
00259 fxDragItem=0;// no drag start after context menu  
00260 //if(selitem==0) return;
00261 bool canplot=(dynamic_cast<TGo4QTHItem*> (selitem)!=0);
00262 bool isfile =(dynamic_cast<TGo4QFileItem*> (selitem)!=0);
00263 bool canedit = ( (dynamic_cast<TGo4QParaItem*> (selitem)!=0)
00264                 || (dynamic_cast<TGo4QConItem*> (selitem)!=0)
00265                 || (dynamic_cast<TGo4QFitterItem*> (selitem)!=0) 
00266                 || (dynamic_cast<TGo4QDynEntryItem*> (selitem)!=0));
00267 
00268 bool hasproperties = ( (dynamic_cast<TGo4QConItem*> (selitem)!=0)
00269                 || (dynamic_cast<TGo4QTH1Item*> (selitem)!=0)
00270                 || (dynamic_cast<TGo4QTH2Item*> (selitem)!=0)
00271                 || (dynamic_cast<TGo4QTH3Item*> (selitem)!=0) );
00272 
00273 fxContextMenu-> setItemEnabled (fiMenuPlotID,  canplot);
00274 fxContextMenu-> setItemEnabled (fiMenuSuperID, canplot);
00275 fxContextMenu-> setItemEnabled (fiMenuCloseID, isfile);
00276 fxContextMenu-> setItemEnabled (fiMenuEditID, canedit);
00277 fxContextMenu-> setItemEnabled (fiMenuPropertyID, hasproperties);
00278 fxContextMenu->exec(pt);
00279 
00280 
00281 
00282 }
00283 
00284 
00285 void TGo4DiskFileBrowser::ShowProperties()
00286 {
00287     fxTGo4DiskFileBrowserSlots->ShowSelectedProperties();
00288 }
00289 
00290 void TGo4DiskFileBrowser::EditSelected()
00291 {
00292     fxTGo4DiskFileBrowserSlots->EditSelected();
00293 }
00294 
00295 
00296 
00297 
00298 void TGo4DiskFileBrowser::FileListView_clicked( QListViewItem *)
00299 {
00300 //cout <<"FileListView_clicked" << endl;
00301 fxDragItem=0; // no drag after mouse release
00302 }
00303 
00304 
00305 void TGo4DiskFileBrowser::StartListviewDrag()
00306 {
00307 if(fxDragItem==0) return;
00308    TGo4QLeafItem *leaf;
00309    //TGo4QDragDrop *THItem; // problem: hierarchy is still wrong
00310                 // because not all draggable things inherit from DragDrop
00311                 //(conditions, parameters, dynlist)
00312                 // ->active file is not set correctly for these?
00313                 // use mechanism for all go4 items JA
00314    TGo4QItem* THItem;
00315     FileListView->setCurrentItem(fxDragItem); // drop will always refer to currently selected item
00316     QDragObject *d = new QTextDrag(fxDragItem->text(0),FileListView); // note: name of textdrag will not be used in drop!
00317       if((leaf= dynamic_cast <TGo4QLeafItem *>(fxDragItem))!=0){
00318            fxTGo4DiskFileBrowserStatus->SetActiveFile(leaf->GetRootFile());
00319            fxTGo4DiskFileBrowserStatus->SetActiveTree(leaf->GetRootTree());
00320            FileListView->clearSelection();
00321            FileListView->setSelected(fxDragItem,true); // only for tree viewer
00322             
00323       //}else if ((THItem=dynamic_cast <TGo4QDragDrop *>(fxDragItem))!=0){
00324       }else if ((THItem=dynamic_cast <TGo4QItem *>(fxDragItem))!=0){
00325 
00326             TFile *ActiveFile =THItem->GetRootFile();
00327          //ActiveFile->cd(); // inside SetActiveFile now
00328          fxTGo4DiskFileBrowserStatus->SetActiveFile(ActiveFile);
00329          TObject *FileObj=ActiveFile->Get((fxDragItem->text(0)).data());
00330            if(FileObj==0){
00331               TKey *ObjKey=THItem->GetFileKey();
00332               if(ObjKey!=0) FileObj=ObjKey->ReadObj();
00333            }
00334           THItem->SetFileObj(FileObj);
00335       }
00336       d->dragCopy();
00337 fxDragItem=0;
00338 }
00339 
00340 
00341 
00342 
00343 
00344 
00345 void TGo4DiskFileBrowser::OpenRemoteFile()
00346 {
00347 TGo4OpenRemoteDialog* fd = new TGo4OpenRemoteDialog( this, "Open Remote root file", TRUE );
00348 if ( fd->exec() == QDialog::Accepted )
00349     {
00350         QString urlpath;
00351         QString openname;
00352         QString dummy;
00353         QString ftype=fd->GetFileType();
00354         QString host=fd->GetServer();
00355         QString fname=fd->GetFileName();
00356         if(ftype.contains("root:"))
00357             urlpath="root://"+host+"/";
00358         else if (ftype.contains("rfio:"))
00359             {
00360                 if(!host.isEmpty())
00361                     urlpath="rfio:"+host+":/";
00362                 else
00363                     urlpath="rfio:/";
00364             }        
00365         else if (ftype.contains("http:"))
00366             {
00367                 if(!host.isEmpty()) 
00368                     urlpath="http://"+host+"/";        
00369                 else
00370                     urlpath="http://";
00371             }
00372         else
00373             urlpath="";
00374         
00375         if(!fname.isEmpty() && !fname.contains(".root"))
00376             fname.append(".root");
00377         openname=urlpath+fname;
00378         cout <<"Open Remote file "<<openname << endl;
00379         fxTGo4DiskFileBrowserSlots->OpenSelectedRootFile(openname, dummy);    
00380     }
00381 delete fd;
00382 }
00383 
00384 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:00 2005 for Go4-v2.10-5 by doxygen1.2.15