30#include <tqpushbutton.h> 
   32#include <tqlineedit.h> 
   33#include <tqcombobox.h> 
   36#include <tqwhatsthis.h> 
   40#include <kdialogbase.h> 
   41#include <tdemessagebox.h> 
   43#include "folderutil.h" 
   44#include "newfolderdialog.h" 
   46#include "folderstorage.h" 
   47#include "kmfolderimap.h" 
   48#include "kmfoldercachedimap.h" 
   49#include "kmfoldermgr.h" 
   50#include "kmfolderdir.h" 
   51#include "folderstorage.h" 
   52#include "kmailicalifaceimpl.h" 
   53#include "kmacctimap.h" 
   54#include "kmacctcachedimap.h" 
   58NewFolderDialog::NewFolderDialog( TQWidget* parent, 
KMFolder *folder )
 
   59    : KDialogBase( parent, 
"new_folder_dialog", false, i18n( 
"New Folder" ),
 
   60                   KDialogBase::
Ok|KDialogBase::Cancel,
 
   61                   KDialogBase::
Ok, true ),
 
   63      mContentsComboBox( 0 ),
 
   64      mNamespacesComboBox( 0 ),
 
   67  setWFlags( getWFlags() | WDestructiveClose );
 
   69    setCaption( i18n(
"New Subfolder of %1").arg( mFolder->prettyURL() ) );
 
   71  TQWidget* privateLayoutWidget = 
new TQWidget( 
this, 
"mTopLevelLayout" );
 
   72  privateLayoutWidget->setGeometry( TQRect( 10, 10, 260, 80 ) );
 
   73  setMainWidget( privateLayoutWidget );
 
   74  mTopLevelLayout = 
new TQVBoxLayout( privateLayoutWidget, 0, spacingHint(),
 
   77  mNameHBox = 
new TQHBoxLayout( 0, 0, 6, 
"mNameHBox");
 
   79  mNameLabel = 
new TQLabel( privateLayoutWidget, 
"mNameLabel" );
 
   80  mNameLabel->setText( i18n( 
"&Name:" ) );
 
   81  mNameHBox->addWidget( mNameLabel );
 
   83  mNameLineEdit = 
new TQLineEdit( privateLayoutWidget, 
"mNameLineEdit" );
 
   84  mNameLabel->setBuddy( mNameLineEdit );
 
   85  TQWhatsThis::add( mNameLineEdit, i18n( 
"Enter a name for the new folder." ) );
 
   86  mNameLineEdit->setFocus();
 
   87  mNameHBox->addWidget( mNameLineEdit );
 
   88  mTopLevelLayout->addLayout( mNameHBox );
 
   89  connect( mNameLineEdit, TQ_SIGNAL( textChanged ( 
const TQString & ) ), 
this, TQ_SLOT( slotFolderNameChanged( 
const TQString & ) ) );
 
   92      ( mFolder->folderType() != KMFolderTypeImap &&
 
   93        mFolder->folderType() != KMFolderTypeCachedImap ) ) {
 
   94    mFormatHBox = 
new TQHBoxLayout( 0, 0, 6, 
"mFormatHBox");
 
   95    mMailboxFormatLabel = 
new TQLabel( privateLayoutWidget, 
"mMailboxFormatLabel" );
 
   96    mMailboxFormatLabel->setText( i18n( 
"Mailbox &format:" ) );
 
   97    mFormatHBox->addWidget( mMailboxFormatLabel );
 
   99    mFormatComboBox = 
new TQComboBox( 
false, privateLayoutWidget, 
"mFormatComboBox" );
 
  100    mMailboxFormatLabel->setBuddy( mFormatComboBox );
 
  101    TQWhatsThis::add( mFormatComboBox, i18n( 
"Select whether you want to store the messages in this folder as one file per  message (maildir) or as one big file (mbox). KMail uses maildir by default and this only needs to be changed in rare circumstances. If you are unsure, leave this option as-is." ) );
 
  103    mFormatComboBox->insertItem(
"mbox", 0);
 
  104    mFormatComboBox->insertItem(
"maildir", 1);
 
  108      TDEConfig *config = KMKernel::config();
 
  109      TDEConfigGroupSaver saver(config, 
"General");
 
  110      int type = config->readNumEntry(
"default-mailbox-format", 1);
 
  111      if ( type < 0 || type > 1 ) type = 1;
 
  112      mFormatComboBox->setCurrentItem( type );
 
  114    mFormatHBox->addWidget( mFormatComboBox );
 
  115    mTopLevelLayout->addLayout( mFormatHBox );
 
  119  if ( kmkernel->iCalIface().isEnabled() &&
 
  120       mFolder && mFolder->folderType() != KMFolderTypeImap ) {
 
  121    mContentsHBox = 
new TQHBoxLayout( 0, 0, 6, 
"mContentsHBox");
 
  123    mContentsLabel = 
new TQLabel( privateLayoutWidget, 
"mContentsLabel" );
 
  124    mContentsLabel->setText( i18n( 
"Folder &contains:" ) );
 
  125    mContentsHBox->addWidget( mContentsLabel );
 
  127    mContentsComboBox = 
new TQComboBox( 
false, privateLayoutWidget, 
"mContentsComboBox" );
 
  128    mContentsLabel->setBuddy( mContentsComboBox );
 
  129    TQWhatsThis::add( mContentsComboBox, i18n( 
"Select whether you want the new folder to be used for mail storage of for storage of groupware items such as tasks or notes. The default is mail. If you are unsure, leave this option as-is." ) );
 
  130    mContentsComboBox->insertItem( i18n( 
"Mail" ) );
 
  131    mContentsComboBox->insertItem( i18n( 
"Calendar" ) );
 
  132    mContentsComboBox->insertItem( i18n( 
"Contacts" ) );
 
  133    mContentsComboBox->insertItem( i18n( 
"Notes" ) );
 
  134    mContentsComboBox->insertItem( i18n( 
"Tasks" ) );
 
  135    mContentsComboBox->insertItem( i18n( 
"Journal" ) );
 
  137      mContentsComboBox->setCurrentItem( mFolder->storage()->contentsType() );
 
  138    mContentsHBox->addWidget( mContentsComboBox );
 
  139    mTopLevelLayout->addLayout( mContentsHBox );
 
  143      ( mFolder->folderType() == KMFolderTypeImap ||
 
  144        mFolder->folderType() == KMFolderTypeCachedImap ) ) {
 
  145    bool rootFolder = 
false;
 
  146    TQStringList namespaces;
 
  147    if ( mFolder->folderType() == KMFolderTypeImap ) {
 
  148      ImapAccountBase* ai = 
static_cast<KMFolderImap*
>(mFolder->storage())->account();
 
  149      if ( mFolder->storage() == ai->rootFolder() ) {
 
  151        namespaces = ai->namespaces()[ImapAccountBase::PersonalNS];
 
  154    if ( mFolder->folderType() == KMFolderTypeCachedImap ) {
 
  155      ImapAccountBase* ai = 
static_cast<KMFolderCachedImap*
>(mFolder->storage())->account();
 
  156      if ( ai && mFolder->storage() == ai->rootFolder() ) {
 
  158        namespaces = ai->namespaces()[ImapAccountBase::PersonalNS];
 
  161    if ( rootFolder && namespaces.count() > 1 ) {
 
  162      mNamespacesHBox = 
new TQHBoxLayout( 0, 0, 6, 
"mNamespaceHBox");
 
  164      mNamespacesLabel = 
new TQLabel( privateLayoutWidget, 
"mNamespacesLabel" );
 
  165      mNamespacesLabel->setText( i18n( 
"Namespace for &folder:" ) );
 
  166      mNamespacesHBox->addWidget( mNamespacesLabel );
 
  168      mNamespacesComboBox = 
new TQComboBox( 
false, privateLayoutWidget, 
"mNamespacesComboBox" );
 
  169      mNamespacesLabel->setBuddy( mNamespacesComboBox );
 
  170      TQWhatsThis::add( mNamespacesComboBox, i18n( 
"Select the personal namespace the folder should be created in." ) );
 
  171      mNamespacesComboBox->insertStringList( namespaces );
 
  172      mNamespacesHBox->addWidget( mNamespacesComboBox );
 
  173      mTopLevelLayout->addLayout( mNamespacesHBox );
 
  175      mNamespacesComboBox = 0;
 
  179  resize( TQSize(282, 108).expandedTo(minimumSizeHint()) );
 
  180  clearWState( WState_Polished );
 
  181  slotFolderNameChanged( mNameLineEdit->text());
 
  184void NewFolderDialog::slotFolderNameChanged( 
const TQString & _text)
 
  186  enableButtonOK( !_text.isEmpty() );
 
  189void NewFolderDialog::slotOk()
 
  191  const TQString fldName = mNameLineEdit->text();
 
  192  if ( fldName.isEmpty() ) {
 
  193     KMessageBox::error( 
this, i18n(
"Please specify a name for the new folder."),
 
  194        i18n( 
"No Name Specified" ) );
 
  199  if ( mFolder && !mFolder->isValidName( fldName, msg ) ) {
 
  200    KMessageBox::error( 
this, msg );
 
  205  KMFolderDir * selectedFolderDir = &(kmkernel->folderMgr()->dir());
 
  208    selectedFolderDir = mFolder->createChildFolder();
 
  213          && ( selectedFolderDir == mFolder->parent() )
 
  214          && ( mFolder->storage()->name() == fldName ) ) ) )
 
  216    const TQString message = i18n( 
"<qt>Failed to create folder <b>%1</b>, folder already exists.</qt>" ).arg(fldName);
 
  217    KMessageBox::error( 
this, message );
 
  222  const TQString message = i18n( 
"<qt>Failed to create folder <b>%1</b>." 
  223            "</qt> " ).arg(fldName);
 
  225  TQString namespaceName;
 
  226  if ( mNamespacesComboBox ) {
 
  227    namespaceName = mNamespacesComboBox->currentText();
 
  230  KMFolderType folderType = KMFolderTypeUnknown;
 
  231  if ( mFormatComboBox && mFormatComboBox->currentItem() == 1 )
 
  232    folderType = KMFolderTypeMaildir;
 
  233  else if ( mFormatComboBox )
 
  234    folderType = KMFolderTypeMbox;
 
  236  KMFolder *newFolder = KMail::FolderUtil::createSubFolder( mFolder, selectedFolderDir, fldName,
 
  237                                                            namespaceName, folderType );
 
  239    KMessageBox::error( 
this, message );
 
  244  if ( kmkernel->iCalIface().isEnabled() && mContentsComboBox ) {
 
  245    KMail::FolderContentsType type =
 
  246      static_cast<KMail::FolderContentsType
>( mContentsComboBox->currentItem() );
 
  250  KDialogBase::slotOk();
 
  253#include "newfolderdialog.moc" 
virtual void setContentsType(KMail::FolderContentsType type, bool quiet=false)
Set the type of contents held in this folder (mail, calendar, etc.)
 
virtual void writeConfig()
Write the config file.
 
KMail list that manages the contents of one directory that may contain folders and/or other directori...
 
virtual KMFolderNode * hasNamedFolder(const TQString &name)
Returns folder with given name or zero if it does not exist.
 
@ Ok
The user rights/ACL have been fetched from the server sucessfully.