tdebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

konq_mainwindow.cc 212KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995
  1. /* This file is part of the KDE project
  2. Copyright (C) 1998, 1999 Simon Hausmann <hausmann@kde.org>
  3. Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
  4. Copyright (C) 2000-2005 David Faure <faure@kde.org>
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; see the file COPYING. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include "konq_mainwindow.h"
  19. #include "konq_guiclients.h"
  20. #include "KonqMainWindowIface.h"
  21. #include "konq_view.h"
  22. #include "konq_run.h"
  23. #include "konq_misc.h"
  24. #include "konq_viewmgr.h"
  25. #include "konq_frame.h"
  26. #include "konq_tabs.h"
  27. #include "konq_events.h"
  28. #include "konq_actions.h"
  29. #include "konq_settingsxt.h"
  30. #include "konq_extensionmanager.h"
  31. #include "delayedinitializer.h"
  32. #include <konq_pixmapprovider.h>
  33. #include <konq_operations.h>
  34. #include <konqbookmarkmanager.h>
  35. #include <kinputdialog.h>
  36. #include <kzip.h>
  37. #include <config.h>
  38. #include <pwd.h>
  39. // we define STRICT_ANSI to get rid of some warnings in glibc
  40. #ifndef __STRICT_ANSI__
  41. #define __STRICT_ANSI__
  42. #define _WE_DEFINED_IT_
  43. #endif
  44. #include <netdb.h>
  45. #ifdef _WE_DEFINED_IT_
  46. #undef __STRICT_ANSI__
  47. #undef _WE_DEFINED_IT_
  48. #endif
  49. #include <assert.h>
  50. #include <stdlib.h>
  51. #include <time.h>
  52. #include <klargefile.h>
  53. #include <sys/types.h>
  54. #include <sys/stat.h>
  55. #include <time.h>
  56. #include <unistd.h>
  57. #include <tqfile.h>
  58. #include <tqclipboard.h>
  59. #include <tqmetaobject.h>
  60. #include <tqvbox.h>
  61. #include <tqlayout.h>
  62. #include <tqfileinfo.h>
  63. #include <tqwhatsthis.h>
  64. #include <dcopclient.h>
  65. #include <tdeaboutdata.h>
  66. #include <kbookmarkbar.h>
  67. #include <kbookmarkmenu.h>
  68. #include <kcmultidialog.h>
  69. #include <kdebug.h>
  70. #include <kedittoolbar.h>
  71. #include <kkeydialog.h>
  72. #include <tdemenubar.h>
  73. #include <tdemessagebox.h>
  74. #include <knewmenu.h>
  75. #include <konq_defaults.h>
  76. #include <konq_dirpart.h>
  77. #include <konq_popupmenu.h>
  78. #include <konq_settings.h>
  79. #include "konq_main.h"
  80. #include <konq_undo.h>
  81. #include <kprotocolinfo.h>
  82. #include <tdestdaccel.h>
  83. #include <kstdaction.h>
  84. #include <kstandarddirs.h>
  85. #include <tdesycoca.h>
  86. #include <tdetempfile.h>
  87. #include <kurlrequesterdlg.h>
  88. #include <kurlrequester.h>
  89. #include <kuserprofile.h>
  90. #include <twin.h>
  91. #include <tdefiledialog.h>
  92. #include <tdelocale.h>
  93. #include <kiconloader.h>
  94. #include <tdepopupmenu.h>
  95. #include <kprocess.h>
  96. #include <tdeio/scheduler.h>
  97. #include <tdeio/netaccess.h>
  98. #include <tdeaccelmanager.h>
  99. #include <kstringhandler.h>
  100. #include <kuser.h>
  101. #include <netwm.h>
  102. #ifdef KDE_MALLINFO_STDLIB
  103. #include <stdlib.h>
  104. #endif
  105. #ifdef KDE_MALLINFO_MALLOC
  106. #include <malloc.h>
  107. #endif
  108. #include <X11/Xlib.h>
  109. #include <sys/time.h>
  110. #include <X11/Xatom.h>
  111. #include <fixx11h.h>
  112. template class TQPtrList<TQPixmap>;
  113. template class TQPtrList<TDEToggleAction>;
  114. TQPtrList<KonqMainWindow> *KonqMainWindow::s_lstViews = 0;
  115. TDEConfig * KonqMainWindow::s_comboConfig = 0;
  116. TDECompletion * KonqMainWindow::s_pCompletion = 0;
  117. TQFile * KonqMainWindow::s_crashlog_file = 0;
  118. bool KonqMainWindow::s_preloaded = false;
  119. KonqMainWindow* KonqMainWindow::s_preloadedWindow = 0;
  120. int KonqMainWindow::s_initialMemoryUsage = -1;
  121. time_t KonqMainWindow::s_startupTime;
  122. int KonqMainWindow::s_preloadUsageCount;
  123. KonqOpenURLRequest KonqOpenURLRequest::null;
  124. static int current_memory_usage( int* limit = NULL );
  125. #include "konq_mainwindow_p.h"
  126. KonqExtendedBookmarkOwner::KonqExtendedBookmarkOwner(KonqMainWindow *w)
  127. {
  128. m_pKonqMainWindow = w;
  129. }
  130. KonqMainWindow::KonqMainWindow( const KURL &initialURL, bool openInitialURL, const char *name, const TQString& xmluiFile)
  131. : KParts::MainWindow( NoDCOPObject, 0L, name, (WFlags)(WDestructiveClose | WStyle_ContextHelp | TQt::WGroupLeader) )
  132. {
  133. setPreloadedFlag( false );
  134. if ( !s_lstViews )
  135. s_lstViews = new TQPtrList<KonqMainWindow>;
  136. s_lstViews->append( this );
  137. m_urlCompletionStarted = false;
  138. m_currentView = 0L;
  139. m_pChildFrame = 0L;
  140. m_pActiveChild = 0L;
  141. m_pWorkingTab = 0L;
  142. m_initialKonqRun = 0L;
  143. m_pBookmarkMenu = 0L;
  144. m_dcopObject = new KonqMainWindowIface( this );
  145. m_combo = 0L;
  146. m_bURLEnterLock = false;
  147. m_bLocationBarConnected = false;
  148. m_paBookmarkBar = 0L;
  149. m_pURLCompletion = 0L;
  150. m_goBuffer = 0;
  151. m_configureDialog = 0L;
  152. m_bViewModeToggled = false;
  153. m_prevMenuBarVisible = true;
  154. m_pViewManager = new KonqViewManager( this );
  155. m_toggleViewGUIClient = new ToggleViewGUIClient( this );
  156. m_openWithActions.setAutoDelete( true );
  157. m_viewModeActions.setAutoDelete( true );
  158. m_toolBarViewModeActions.setAutoDelete( true );
  159. m_viewModeMenu = 0;
  160. m_paDelete = 0;
  161. m_bookmarkBarActionCollection = 0L;
  162. KonqExtendedBookmarkOwner *extOwner = new KonqExtendedBookmarkOwner( this );
  163. m_pBookmarksOwner = extOwner;
  164. connect( extOwner,
  165. TQT_SIGNAL( signalFillBookmarksList(KExtendedBookmarkOwner::QStringPairList &) ),
  166. extOwner,
  167. TQT_SLOT( slotFillBookmarksList(KExtendedBookmarkOwner::QStringPairList &) ) );
  168. // init history-manager, load history, get completion object
  169. if ( !s_pCompletion ) {
  170. KonqHistoryManager *mgr = new KonqHistoryManager( TQT_TQOBJECT(kapp), "history mgr" );
  171. s_pCompletion = mgr->completionObject();
  172. // setup the completion object before createGUI(), so that the combo
  173. // picks up the correct mode from the HistoryManager (in slotComboPlugged)
  174. int mode = KonqSettings::settingsCompletionMode();
  175. s_pCompletion->setCompletionMode( (TDEGlobalSettings::Completion) mode );
  176. }
  177. connect(KParts::HistoryProvider::self(), TQT_SIGNAL(cleared()), TQT_SLOT(slotClearComboHistory()));
  178. KonqPixmapProvider *prov = KonqPixmapProvider::self();
  179. if ( !s_comboConfig ) {
  180. s_comboConfig = new TDEConfig( "konq_history", false, false );
  181. KonqCombo::setConfig( s_comboConfig );
  182. s_comboConfig->setGroup( "Location Bar" );
  183. prov->load( s_comboConfig, "ComboIconCache" );
  184. }
  185. connect( prov, TQT_SIGNAL( changed() ), TQT_SLOT( slotIconsChanged() ) );
  186. initCombo();
  187. initActions();
  188. setInstance( TDEGlobal::instance() );
  189. connect( KSycoca::self(), TQT_SIGNAL( databaseChanged() ),
  190. this, TQT_SLOT( slotDatabaseChanged() ) );
  191. connect( kapp, TQT_SIGNAL( tdedisplayFontChanged()), TQT_SLOT(slotReconfigure()));
  192. //load the xmlui file specified in the profile or the default konqueror.rc
  193. setXMLFile( xmluiFile );
  194. setStandardToolBarMenuEnabled( true );
  195. createGUI( 0L );
  196. connect(toolBarMenuAction(),TQT_SIGNAL(activated()),this,TQT_SLOT(slotForceSaveMainWindowSettings()) );
  197. if ( !m_toggleViewGUIClient->empty() )
  198. plugActionList( TQString::fromLatin1( "toggleview" ), m_toggleViewGUIClient->actions() );
  199. else
  200. {
  201. delete m_toggleViewGUIClient;
  202. m_toggleViewGUIClient = 0;
  203. }
  204. // Those menus are created by konqueror.rc so their address will never change
  205. TQPopupMenu *popup = static_cast<TQPopupMenu*>(factory()->container("edit",this));
  206. if (popup)
  207. TDEAcceleratorManager::manage(popup);
  208. popup = static_cast<TQPopupMenu*>(factory()->container("tools",this));
  209. if (popup)
  210. TDEAcceleratorManager::manage(popup);
  211. m_bSaveViewPropertiesLocally = KonqSettings::saveViewPropertiesLocally();
  212. m_bHTMLAllowed = KonqSettings::htmlAllowed();
  213. m_ptaUseHTML->setChecked( m_bHTMLAllowed );
  214. m_paSaveViewPropertiesLocally->setChecked( m_bSaveViewPropertiesLocally );
  215. KonqUndoManager::incRef();
  216. connect( KonqUndoManager::self(), TQT_SIGNAL( undoAvailable( bool ) ),
  217. this, TQT_SLOT( slotUndoAvailable( bool ) ) );
  218. m_bNeedApplyKonqMainWindowSettings = true;
  219. if ( !initialURL.isEmpty() )
  220. {
  221. openFilteredURL( initialURL.url() );
  222. }
  223. else if ( openInitialURL )
  224. {
  225. KURL homeURL;
  226. homeURL.setPath( TQDir::homeDirPath() );
  227. openURL( 0L, homeURL );
  228. }
  229. else
  230. // silent
  231. m_bNeedApplyKonqMainWindowSettings = false;
  232. // Read basic main-view settings, and set to autosave
  233. setAutoSaveSettings( "KonqMainWindow", false );
  234. if ( !initialGeometrySet() )
  235. resize( 700, 480 );
  236. //kdDebug(1202) << "KonqMainWindow::KonqMainWindow " << this << " done" << endl;
  237. if( s_initialMemoryUsage == -1 )
  238. {
  239. s_initialMemoryUsage = current_memory_usage();
  240. s_startupTime = time( NULL );
  241. s_preloadUsageCount = 0;
  242. }
  243. }
  244. KonqMainWindow::~KonqMainWindow()
  245. {
  246. kdDebug(1202) << "KonqMainWindow::~KonqMainWindow " << this << endl;
  247. delete m_pViewManager;
  248. if ( s_lstViews )
  249. {
  250. s_lstViews->removeRef( this );
  251. if ( s_lstViews->count() == 0 )
  252. {
  253. delete s_lstViews;
  254. s_lstViews = 0;
  255. }
  256. }
  257. disconnectActionCollection( actionCollection() );
  258. saveToolBarServicesMap();
  259. // createShellGUI( false );
  260. delete m_pBookmarkMenu;
  261. delete m_paBookmarkBar;
  262. delete m_pBookmarksOwner;
  263. delete m_pURLCompletion;
  264. m_viewModeActions.clear();
  265. KonqUndoManager::decRef();
  266. if ( s_lstViews == 0 ) {
  267. delete KonqPixmapProvider::self();
  268. delete s_comboConfig;
  269. s_comboConfig = 0L;
  270. }
  271. delete m_configureDialog;
  272. m_configureDialog = 0L;
  273. delete m_dcopObject;
  274. m_dcopObject = 0L;
  275. delete m_combo;
  276. m_combo = 0L;
  277. delete m_locationLabel;
  278. m_locationLabel = 0L;
  279. kdDebug(1202) << "KonqMainWindow::~KonqMainWindow " << this << " done" << endl;
  280. }
  281. TQWidget * KonqMainWindow::createContainer( TQWidget *parent, int index, const TQDomElement &element, int &id )
  282. {
  283. static TQString nameBookmarkBar = TQString::fromLatin1( "bookmarkToolBar" );
  284. static TQString tagToolBar = TQString::fromLatin1( "ToolBar" );
  285. TQWidget *res = KParts::MainWindow::createContainer( parent, index, element, id );
  286. if ( res && (element.tagName() == tagToolBar) && (element.attribute( "name" ) == nameBookmarkBar) )
  287. {
  288. assert( res->inherits( "TDEToolBar" ) );
  289. if (!kapp->authorizeTDEAction("bookmarks"))
  290. {
  291. delete res;
  292. return 0;
  293. }
  294. if ( !m_bookmarkBarActionCollection )
  295. {
  296. // The actual menu needs a different action collection, so that the bookmarks
  297. // don't appear in kedittoolbar
  298. m_bookmarkBarActionCollection = new TDEActionCollection( this );
  299. m_bookmarkBarActionCollection->setHighlightingEnabled( true );
  300. connectActionCollection( m_bookmarkBarActionCollection );
  301. DelayedInitializer *initializer = new DelayedInitializer( TQEvent::Show, TQT_TQOBJECT(res) );
  302. connect( initializer, TQT_SIGNAL( initialize() ), this, TQT_SLOT(initBookmarkBar()) );
  303. }
  304. }
  305. return res;
  306. }
  307. void KonqMainWindow::initBookmarkBar()
  308. {
  309. TDEToolBar * bar = static_cast<TDEToolBar *>( TQT_TQWIDGET(child( "bookmarkToolBar", "TDEToolBar" )) );
  310. if (!bar) return;
  311. delete m_paBookmarkBar;
  312. m_paBookmarkBar = new KBookmarkBar( KonqBookmarkManager::self(), m_pBookmarksOwner, bar, m_bookmarkBarActionCollection, TQT_TQOBJECT(this) );
  313. connect( m_paBookmarkBar,
  314. TQT_SIGNAL( aboutToShowContextMenu(const KBookmark &, TQPopupMenu*) ),
  315. this, TQT_SLOT( slotFillContextMenu(const KBookmark &, TQPopupMenu*) ));
  316. connect( m_paBookmarkBar,
  317. TQT_SIGNAL( openBookmark(const TQString &, TQt::ButtonState) ),
  318. this, TQT_SLOT( slotOpenBookmarkURL(const TQString &, TQt::ButtonState) ));
  319. // hide if empty
  320. if (bar->count() == 0 )
  321. bar->hide();
  322. }
  323. void KonqMainWindow::removeContainer( TQWidget *container, TQWidget *parent, TQDomElement &element, int id )
  324. {
  325. static TQString nameBookmarkBar = TQString::fromLatin1( "bookmarkToolBar" );
  326. static TQString tagToolBar = TQString::fromLatin1( "ToolBar" );
  327. if ( element.tagName() == tagToolBar && element.attribute( "name" ) == nameBookmarkBar )
  328. {
  329. assert( container->inherits( "TDEToolBar" ) );
  330. if (m_paBookmarkBar)
  331. m_paBookmarkBar->clear();
  332. }
  333. KParts::MainWindow::removeContainer( container, parent, element, id );
  334. }
  335. // Detect a name filter (e.g. *.txt) in the url.
  336. // Note that TDEShortURIFilter does the same, but we have no way of getting it from there
  337. //
  338. // Note: this removes the filter from the URL.
  339. static TQString detectNameFilter( KURL & url )
  340. {
  341. if ( !KProtocolInfo::supportsListing(url) )
  342. return TQString::null;
  343. // Look for wildcard selection
  344. TQString nameFilter;
  345. TQString path = url.path();
  346. int lastSlash = path.findRev( '/' );
  347. if ( lastSlash > -1 )
  348. {
  349. if ( !url.query().isEmpty() && lastSlash == (int)path.length()-1 ) { // In /tmp/?foo, foo isn't a query
  350. path += url.query(); // includes the '?'
  351. url.setQuery( TQString::null );
  352. }
  353. const TQString fileName = path.mid( lastSlash + 1 );
  354. if ( fileName.find( '*' ) != -1 || fileName.find( '[' ) != -1 || fileName.find( '?' ) != -1 )
  355. {
  356. // Check that a file or dir with all the special chars in the filename doesn't exist
  357. if ( url.isLocalFile() ? !TQFile::exists( path ) : !TDEIO::NetAccess::exists( url, false, 0 ) )
  358. {
  359. nameFilter = fileName;
  360. url.setFileName( TQString::null );
  361. kdDebug(1202) << "Found wildcard. nameFilter=" << nameFilter << " New url=" << url << endl;
  362. }
  363. }
  364. }
  365. return nameFilter;
  366. }
  367. void KonqMainWindow::openFilteredURL( const TQString & url, KonqOpenURLRequest & req )
  368. {
  369. // Filter URL to build a correct one
  370. if (m_currentDir.isEmpty() && m_currentView)
  371. m_currentDir = m_currentView->url().path(1);
  372. KURL filteredURL ( KonqMisc::konqFilteredURL( this, url, m_currentDir ) );
  373. kdDebug(1202) << "url " << url << " filtered into " << filteredURL.prettyURL() << endl;
  374. if ( filteredURL.isEmpty() ) // initially empty, or error (e.g. ~unknown_user)
  375. return;
  376. m_currentDir = TQString::null;
  377. openURL( 0L, filteredURL, TQString::null, req );
  378. // #4070: Give focus to view after URL was entered manually
  379. // Note: we do it here if the view mode (i.e. part) wasn't changed
  380. // If it is changed, then it's done in KonqView::changeViewMode
  381. if ( m_currentView && m_currentView->part() )
  382. m_currentView->part()->widget()->setFocus();
  383. }
  384. void KonqMainWindow::openFilteredURL( const TQString & _url, bool inNewTab, bool tempFile )
  385. {
  386. KonqOpenURLRequest req( _url );
  387. req.newTab = inNewTab;
  388. req.newTabInFront = true;
  389. req.tempFile = tempFile;
  390. openFilteredURL( _url, req );
  391. }
  392. void KonqMainWindow::openURL( KonqView *_view, const KURL &_url,
  393. const TQString &_serviceType, KonqOpenURLRequest& req,
  394. bool trustedSource )
  395. {
  396. #ifndef NDEBUG // needed for req.debug()
  397. kdDebug(1202) << "KonqMainWindow::openURL : url = '" << _url << "' "
  398. << "serviceType='" << _serviceType << "' req=" << req.debug()
  399. << " view=" << _view << endl;
  400. #endif
  401. KURL url( _url );
  402. if (url.url().startsWith("$(")) {
  403. // check for environment variables and make necessary translations
  404. TQString aValue = url.url();
  405. int nDollarPos = aValue.find( '$' );
  406. while( nDollarPos != -1 && nDollarPos+1 < static_cast<int>(aValue.length())) {
  407. // there is at least one $
  408. if( (aValue)[nDollarPos+1] == '(' ) {
  409. uint nEndPos = nDollarPos+1;
  410. // the next character is no $
  411. while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!=')') )
  412. nEndPos++;
  413. nEndPos++;
  414. TQString cmd = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
  415. TQString result;
  416. FILE *fs = popen(TQFile::encodeName(cmd).data(), "r");
  417. if (fs)
  418. {
  419. {
  420. TQTextStream ts(fs, IO_ReadOnly);
  421. result = ts.read().stripWhiteSpace();
  422. }
  423. pclose(fs);
  424. }
  425. aValue.replace( nDollarPos, nEndPos-nDollarPos, result );
  426. } else if( (aValue)[nDollarPos+1] != '$' ) {
  427. uint nEndPos = nDollarPos+1;
  428. // the next character is no $
  429. TQString aVarName;
  430. if (aValue[nEndPos]=='{')
  431. {
  432. while ( (nEndPos <= aValue.length()) && (aValue[nEndPos]!='}') )
  433. nEndPos++;
  434. nEndPos++;
  435. aVarName = aValue.mid( nDollarPos+2, nEndPos-nDollarPos-3 );
  436. }
  437. else
  438. {
  439. while ( nEndPos <= aValue.length() && (aValue[nEndPos].isNumber()
  440. || aValue[nEndPos].isLetter() || aValue[nEndPos]=='_' ) )
  441. nEndPos++;
  442. aVarName = aValue.mid( nDollarPos+1, nEndPos-nDollarPos-1 );
  443. }
  444. const char* pEnv = 0;
  445. if (!aVarName.isEmpty())
  446. pEnv = getenv( aVarName.ascii() );
  447. if( pEnv ) {
  448. // !!! Sergey A. Sukiyazov <corwin@micom.don.ru> !!!
  449. // A environment variables may contain values in 8bit
  450. // locale cpecified encoding or in UTF8 encoding.
  451. aValue.replace( nDollarPos, nEndPos-nDollarPos, KStringHandler::from8Bit( pEnv ) );
  452. } else
  453. aValue.remove( nDollarPos, nEndPos-nDollarPos );
  454. } else {
  455. // remove one of the dollar signs
  456. aValue.remove( nDollarPos, 1 );
  457. nDollarPos++;
  458. }
  459. nDollarPos = aValue.find( '$', nDollarPos );
  460. }
  461. url = KURL(aValue);
  462. }
  463. TQString serviceType( _serviceType );
  464. if ( url.url() == "about:blank" )
  465. {
  466. serviceType = "text/html";
  467. }
  468. else if ( !url.isValid() )
  469. {
  470. KMessageBox::error(0, i18n("Malformed URL\n%1").arg(url.url()));
  471. return;
  472. }
  473. else if ( !KProtocolInfo::isKnownProtocol( url ) && url.protocol() != "about" )
  474. {
  475. KMessageBox::error(0, i18n("Protocol not supported\n%1").arg(url.protocol()));
  476. return;
  477. }
  478. TQString nameFilter = detectNameFilter( url );
  479. if ( !nameFilter.isEmpty() )
  480. {
  481. req.nameFilter = nameFilter;
  482. url.setFileName( TQString::null );
  483. }
  484. KonqView *view = _view;
  485. // When clicking a 'follow active' view (e.g. view is the sidebar),
  486. // open the URL in the active view
  487. if ( view && view->isFollowActive() )
  488. view = m_currentView;
  489. if ( !view && !req.newTab )
  490. view = m_currentView; /* Note, this can be 0L, e.g. on startup */
  491. else if ( !view && req.newTab ) {
  492. view = m_pViewManager->addTab(TQString::null,
  493. TQString::null,
  494. false,
  495. req.openAfterCurrentPage);
  496. if (view) {
  497. view->setCaption( _url.host() );
  498. view->setLocationBarURL( _url );
  499. if ( !req.args.frameName.isEmpty() )
  500. view->setViewName( req.args.frameName ); // #44961
  501. if ( req.newTabInFront )
  502. m_pViewManager->showTab( view );
  503. updateViewActions(); //A new tab created -- we may need to enable the "remove tab" button (#56318)
  504. }
  505. else
  506. req.newTab = false;
  507. }
  508. const TQString oldLocationBarURL = m_combo->currentText();
  509. if ( view )
  510. {
  511. if ( view == m_currentView )
  512. {
  513. //will do all the stuff below plus GUI stuff
  514. abortLoading();
  515. }
  516. else
  517. {
  518. view->stop();
  519. // Don't change location bar if not current view
  520. }
  521. }
  522. // Fast mode for local files: do the stat ourselves instead of letting KRun do it.
  523. if ( serviceType.isEmpty() && url.isLocalFile() )
  524. {
  525. TQCString _path( TQFile::encodeName(url.path()));
  526. KDE_struct_stat buff;
  527. if ( KDE_stat( _path.data(), &buff ) != -1 )
  528. serviceType = KMimeType::findByURL( url, buff.st_mode )->name();
  529. }
  530. kdDebug(1202) << "trying openView for " << url << " (serviceType " << serviceType << ")" << endl;
  531. if ( ( !serviceType.isEmpty() && serviceType != "application/octet-stream") ||
  532. url.url().startsWith("about:konqueror") || url.url() == "about:plugins" )
  533. {
  534. KService::Ptr offer = KServiceTypeProfile::preferredService(serviceType, "Application");
  535. // If the associated app is konqueror itself, then make sure we try to embed before bailing out.
  536. if ( isMimeTypeAssociatedWithSelf( serviceType, offer ) )
  537. req.forceAutoEmbed = true;
  538. // Built-in view ?
  539. if ( !openView( serviceType, url, view /* can be 0L */, req ) )
  540. {
  541. //kdDebug(1202) << "KonqMainWindow::openURL : openView returned false" << endl;
  542. // Are we following another view ? Then forget about this URL. Otherwise fire app.
  543. if ( !req.followMode )
  544. {
  545. //kdDebug(1202) << "KonqMainWindow::openURL : we were not following. Fire app." << endl;
  546. // We know the servicetype, let's try its preferred service
  547. if ( isMimeTypeAssociatedWithSelf( serviceType, offer ) ) {
  548. KMessageBox::error( this, i18n("There appears to be a configuration error. You have associated Konqueror with %1, but it cannot handle this file type.").arg(serviceType));
  549. return;
  550. }
  551. if ( !url.isLocalFile() && KonqRun::isTextExecutable( serviceType ) )
  552. serviceType = "text/plain"; // view, don't execute
  553. // Remote URL: save or open ?
  554. TQString protClass = KProtocolInfo::protocolClass(url.protocol());
  555. bool open = url.isLocalFile() || protClass==":local";
  556. if ( !open ) {
  557. KParts::BrowserRun::AskSaveResult res = KonqRun::askSave( url, offer, serviceType );
  558. if ( res == KParts::BrowserRun::Save )
  559. KParts::BrowserRun::simpleSave( url, TQString::null, this );
  560. open = ( res == KParts::BrowserRun::Open );
  561. }
  562. if ( open )
  563. {
  564. KURL::List lst;
  565. lst.append(url);
  566. //kdDebug(1202) << "Got offer " << (offer ? offer->name().latin1() : "0") << endl;
  567. if ( ( trustedSource || KonqRun::allowExecution( serviceType, url ) ) &&
  568. ( KonqRun::isExecutable( serviceType ) || !offer || !KRun::run( *offer, lst ) ) )
  569. {
  570. setLocationBarURL( oldLocationBarURL ); // Revert to previous locationbar URL
  571. (void)new KRun( url, this );
  572. }
  573. }
  574. }
  575. }
  576. }
  577. else // no known serviceType, use KonqRun
  578. {
  579. if ( ( !view || view->url().isEmpty() ) && !req.newTab ) // startup with argument
  580. {
  581. // Show it for now in the location bar, but we'll need to store it in the view
  582. // later on (can't do it yet since either view == 0 or updateHistoryEntry will be called).
  583. kdDebug(1202) << "setLocationBarURL (startup) : url = " << url << endl;
  584. setLocationBarURL( url );
  585. }
  586. kdDebug(1202) << "Creating new konqrun for " << url << " req.typedURL=" << req.typedURL << endl;
  587. KonqRun * run = new KonqRun( this, view /* can be 0L */, url, req, trustedSource );
  588. // Never start in external browser
  589. run->setEnableExternalBrowser(false);
  590. if ( view )
  591. view->setRun( run );
  592. else if ( !req.newTab )
  593. {
  594. // there can be only one :) (when not a new tab)
  595. delete m_initialKonqRun;
  596. m_initialKonqRun = run;
  597. }
  598. if ( view == m_currentView )
  599. startAnimation();
  600. connect( run, TQT_SIGNAL( finished() ), this, TQT_SLOT( slotRunFinished() ) );
  601. }
  602. }
  603. bool KonqMainWindow::openView( TQString serviceType, const KURL &_url, KonqView *childView, KonqOpenURLRequest& req )
  604. {
  605. // Second argument is referring URL
  606. if ( !kapp->authorizeURLAction("open", childView ? childView->url() : KURL(), _url) )
  607. {
  608. TQString msg = TDEIO::buildErrorString(TDEIO::ERR_ACCESS_DENIED, _url.prettyURL());
  609. KMessageBox::queuedMessageBox( this, KMessageBox::Error, msg );
  610. return true; // Nothing else to do.
  611. }
  612. if ( KonqRun::isExecutable( serviceType ) )
  613. return false; // execute, don't open
  614. // Contract: the caller of this method should ensure the view is stopped first.
  615. #ifndef NDEBUG
  616. kdDebug(1202) << "KonqMainWindow::openView " << serviceType << " " << _url << " " << childView << " req:" << req.debug() << endl;
  617. #endif
  618. bool bOthersFollowed = false;
  619. if ( childView )
  620. {
  621. // If we're not already following another view (and if we are not reloading)
  622. if ( !req.followMode && !req.args.reload && !m_pViewManager->isLoadingProfile() )
  623. {
  624. // When clicking a 'follow active' view (e.g. childView is the sidebar),
  625. // open the URL in the active view
  626. // (it won't do anything itself, since it's locked to its location)
  627. if ( childView->isFollowActive() && childView != m_currentView )
  628. {
  629. abortLoading();
  630. setLocationBarURL( _url );
  631. KonqOpenURLRequest newreq;
  632. newreq.followMode = true;
  633. newreq.args = req.args;
  634. bOthersFollowed = openView( serviceType, _url, m_currentView, newreq );
  635. }
  636. // "link views" feature, and "sidebar follows active view" feature
  637. bOthersFollowed = makeViewsFollow(_url, req.args, serviceType, childView) || bOthersFollowed;
  638. }
  639. if ( childView->isLockedLocation() && !req.args.reload /* allow to reload a locked view*/ )
  640. return bOthersFollowed;
  641. }
  642. TQString indexFile;
  643. KURL url( _url );
  644. // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
  645. // zip:/<path>/ when clicking on a zip file, etc.
  646. // The name of the protocol to redirect to, is read from the mimetype's .desktop file
  647. if ( url.isLocalFile() )
  648. {
  649. KServiceType::Ptr ptr = KServiceType::serviceType( serviceType );
  650. if ( ptr )
  651. {
  652. const TQString protocol = ptr->property("X-TDE-LocalProtocol").toString();
  653. if ( !protocol.isEmpty() && KonqFMSettings::settings()->shouldEmbed( serviceType ) )
  654. {
  655. url.setProtocol( protocol );
  656. if ( serviceType == "application/x-webarchive" )
  657. {
  658. url.setPath( url.path() + "/index.html" );
  659. serviceType = "text/html";
  660. }
  661. else
  662. {
  663. url.setPath( url.path() + '/' );
  664. serviceType = "inode/directory";
  665. }
  666. }
  667. }
  668. }
  669. ///////////
  670. // In case we open an index.html, we want the location bar
  671. // to still display the original URL (so that 'up' uses that URL,
  672. // and since that's what the user entered).
  673. // changeViewMode will take care of setting and storing that url.
  674. TQString originalURL = url.pathOrURL();
  675. if ( !req.nameFilter.isEmpty() ) // keep filter in location bar
  676. {
  677. if (!originalURL.endsWith("/"))
  678. originalURL += '/';
  679. originalURL += req.nameFilter;
  680. }
  681. TQString serviceName; // default: none provided
  682. if ( url.url().startsWith("about:konqueror") || url.url() == "about:plugins" )
  683. {
  684. serviceType = "KonqAboutPage"; // not KParts/ReadOnlyPart, it fills the Location menu ! :)
  685. serviceName = "konq_aboutpage";
  686. originalURL = req.typedURL.isEmpty() ? TQString::null : url.url();
  687. // empty if from profile, about:konqueror if the user typed it (not req.typedURL, it could be "about:")
  688. }
  689. else if ( url.url() == "about:blank" && req.typedURL.isEmpty() )
  690. {
  691. originalURL = TQString::null;
  692. }
  693. // Look for which view mode to use, if a directory - not if view locked
  694. if ( ( !childView || (!childView->isLockedViewMode()) )
  695. && serviceType == "inode/directory" )
  696. { // Phew !
  697. // Set view mode if necessary (current view doesn't support directories)
  698. if ( !childView || !childView->supportsServiceType( serviceType ) )
  699. serviceName = KonqSettings::mainViewViewMode();
  700. if ( url.isLocalFile() ) // local, we can do better (.directory)
  701. {
  702. // Read it in the .directory file, default to m_bHTMLAllowed
  703. KURL urlDotDir( url );
  704. urlDotDir.addPath(".directory");
  705. bool HTMLAllowed = m_bHTMLAllowed;
  706. TQFile f( urlDotDir.path() );
  707. if ( f.open(IO_ReadOnly) )
  708. {
  709. f.close();
  710. KSimpleConfig config( urlDotDir.path(), true );
  711. config.setGroup( "URL properties" );
  712. HTMLAllowed = config.readBoolEntry( "HTMLAllowed", m_bHTMLAllowed );
  713. serviceName = config.readEntry( "ViewMode", serviceName );
  714. kdDebug(1202) << "serviceName=" << serviceName << endl;
  715. }
  716. if ( HTMLAllowed &&
  717. ( ( indexFile = findIndexFile( url.path() ) ) != TQString::null ) )
  718. {
  719. serviceType = "text/html";
  720. url = KURL();
  721. url.setPath( indexFile );
  722. serviceName = TQString::null; // cancel what we just set, this is not a dir finally
  723. }
  724. // Reflect this setting in the menu
  725. m_ptaUseHTML->setChecked( HTMLAllowed );
  726. }
  727. }
  728. bool ok = true;
  729. if ( !childView )
  730. {
  731. if (req.newTab)
  732. {
  733. KonqFrameTabs* tabContainer = 0L;
  734. int index = 0;
  735. if ( m_pViewManager->docContainer() && m_pViewManager->docContainer()->frameType() == "Tabs")
  736. {
  737. tabContainer = static_cast<KonqFrameTabs*>(m_pViewManager->docContainer());
  738. index = tabContainer->currentPageIndex();
  739. }
  740. childView = m_pViewManager->addTab( serviceType, serviceName, false, req.openAfterCurrentPage );
  741. if (req.newTabInFront && childView)
  742. {
  743. if ( !tabContainer )
  744. tabContainer = static_cast<KonqFrameTabs*>(m_pViewManager->docContainer());
  745. if ( req.openAfterCurrentPage )
  746. tabContainer->setCurrentPage( index + 1 );
  747. else
  748. tabContainer->setCurrentPage( tabContainer->count()-1 );
  749. }
  750. }
  751. else
  752. {
  753. // Create a new view
  754. // Initialize always uses force auto-embed even if user setting is "separate viewer",
  755. // since this window has no view yet - we don't want to keep an empty mainwindow.
  756. // This can happen with e.g. application/pdf from a target="_blank" link, or window.open.
  757. childView = m_pViewManager->Initialize( serviceType, serviceName );
  758. if ( childView )
  759. {
  760. enableAllActions( true );
  761. m_currentView = childView;
  762. }
  763. }
  764. if ( !childView )
  765. return false; // It didn't work out.
  766. childView->setViewName( m_initialFrameName.isEmpty() ? req.args.frameName : m_initialFrameName );
  767. m_initialFrameName = TQString::null;
  768. }
  769. else // We know the child view
  770. {
  771. if ( !childView->isLockedViewMode() )
  772. {
  773. bool forceAutoEmbed = req.forceAutoEmbed || req.newTab || req.userRequestedReload;
  774. if ( !req.typedURL.isEmpty() ) // the user _typed_ the URL, he wants it in Konq.
  775. forceAutoEmbed = true;
  776. if ( url.protocol() == "about" )
  777. forceAutoEmbed = true;
  778. // Related to KonqFactory::createView
  779. if ( !forceAutoEmbed && !KonqFMSettings::settings()->shouldEmbed( serviceType ) )
  780. {
  781. kdDebug(1202) << "openView: KonqFMSettings says: don't embed this servicetype" << endl;
  782. ok = false;
  783. }
  784. // If the protocol doesn't support writing (e.g. HTTP) then we might want to save instead of just embedding.
  785. // So (if embedding would succeed, hence the checks above) we ask the user
  786. // Otherwise the user will get asked 'open or save' in openURL anyway.
  787. if ( ok && !forceAutoEmbed && !KProtocolInfo::supportsWriting( url ) ) {
  788. TQString suggestedFilename;
  789. KonqRun* run = childView->run();
  790. int attachment = 0;
  791. if (run) {
  792. suggestedFilename = run->suggestedFilename();
  793. attachment = (run->serverSuggestsSave()) ? KParts::BrowserRun::AttachmentDisposition : KParts::BrowserRun::InlineDisposition;
  794. }
  795. KParts::BrowserRun::AskSaveResult res = KParts::BrowserRun::askEmbedOrSave(
  796. url, serviceType, suggestedFilename, attachment );
  797. if ( res == KParts::BrowserRun::Open )
  798. forceAutoEmbed = true;
  799. else if ( res == KParts::BrowserRun::Cancel )
  800. return true; // handled, don't do anything else
  801. else { // Save
  802. KParts::BrowserRun::simpleSave( url, suggestedFilename, this );
  803. return true; // handled
  804. }
  805. }
  806. if ( ok )
  807. ok = childView->changeViewMode( serviceType, serviceName, forceAutoEmbed );
  808. }
  809. }
  810. if (ok)
  811. {
  812. //kdDebug(1202) << "req.nameFilter= " << req.nameFilter << endl;
  813. //kdDebug(1202) << "req.typedURL= " << req.typedURL << endl;
  814. //kdDebug(1202) << "Browser extension? " << (childView->browserExtension() ? "YES" : "NO") << endl;
  815. //kdDebug(1202) << "Referrer: " << req.args.metaData()["referrer"] << endl;
  816. childView->setTypedURL( req.typedURL );
  817. if ( childView->browserExtension() )
  818. childView->browserExtension()->setURLArgs( req.args );
  819. if ( childView->part()->inherits("KonqDirPart") )
  820. static_cast<KonqDirPart *>(childView->part())->setFilesToSelect( req.filesToSelect );
  821. if ( !url.isEmpty() )
  822. childView->openURL( url, originalURL, req.nameFilter, req.tempFile );
  823. }
  824. kdDebug(1202) << "KonqMainWindow::openView ok=" << ok << " bOthersFollowed=" << bOthersFollowed << " returning "
  825. << (ok || bOthersFollowed)
  826. << endl;
  827. return ok || bOthersFollowed;
  828. }
  829. void KonqMainWindow::slotOpenURLRequest( const KURL &url, const KParts::URLArgs &args )
  830. {
  831. kdDebug(1202) << "KonqMainWindow::slotOpenURLRequest frameName=" << args.frameName << endl;
  832. KParts::ReadOnlyPart *callingPart = static_cast<KParts::ReadOnlyPart *>( TQT_TQOBJECT_CONST(sender())->parent() );
  833. TQString frameName = args.frameName;
  834. if ( !frameName.isEmpty() )
  835. {
  836. static TQString _top = TQString::fromLatin1( "_top" );
  837. static TQString _self = TQString::fromLatin1( "_self" );
  838. static TQString _parent = TQString::fromLatin1( "_parent" );
  839. static TQString _blank = TQString::fromLatin1( "_blank" );
  840. if ( frameName.lower() == _blank )
  841. {
  842. slotCreateNewWindow( url, args );
  843. return;
  844. }
  845. if ( frameName.lower() != _top &&
  846. frameName.lower() != _self &&
  847. frameName.lower() != _parent )
  848. {
  849. KParts::BrowserHostExtension *hostExtension = 0;
  850. KonqView *view = childView( callingPart, frameName, &hostExtension, 0 );
  851. if ( !view )
  852. {
  853. KonqMainWindow *mainWindow = 0;
  854. view = findChildView( callingPart, frameName, &mainWindow, &hostExtension, 0 );
  855. if ( !view || !mainWindow )
  856. {
  857. slotCreateNewWindow( url, args );
  858. return;
  859. }
  860. if ( hostExtension )
  861. hostExtension->openURLInFrame( url, args );
  862. else
  863. mainWindow->openURL( view, url, args );
  864. return;
  865. }
  866. if ( hostExtension )
  867. hostExtension->openURLInFrame( url, args );
  868. else
  869. openURL( view, url, args );
  870. return;
  871. }
  872. }
  873. KonqView *view = childView( callingPart );
  874. openURL( view, url, args );
  875. }
  876. //Called by slotOpenURLRequest
  877. void KonqMainWindow::openURL( KonqView *childView, const KURL &url, const KParts::URLArgs &args )
  878. {
  879. kdDebug(1202) << "KonqMainWindow::openURL (from slotOpenURLRequest) url=" << url.prettyURL() << endl;
  880. KonqOpenURLRequest req;
  881. req.args = args;
  882. // Clicking on a link that points to the page itself (e.g. anchor)
  883. if ( !args.doPost() && !args.reload &&
  884. childView && urlcmp( url.url(), childView->url().url(), true, true ) )
  885. {
  886. TQString serviceType = args.serviceType;
  887. if ( serviceType.isEmpty() )
  888. serviceType = childView->serviceType();
  889. childView->stop();
  890. req.forceAutoEmbed = true;
  891. req.openAfterCurrentPage = KonqSettings::openAfterCurrentPage();
  892. openView( serviceType, url, childView, req );
  893. return;
  894. }
  895. openURL( childView, url, args.serviceType, req, args.trustedSource );
  896. }
  897. TQObject *KonqMainWindow::lastFrame( KonqView *view )
  898. {
  899. TQObject *nextFrame, *viewFrame;
  900. nextFrame = TQT_TQOBJECT(view->frame());
  901. viewFrame = 0;
  902. while ( nextFrame != 0 && ! nextFrame->inherits( TQWIDGETSTACK_OBJECT_NAME_STRING ) ) {
  903. viewFrame = nextFrame;
  904. nextFrame = nextFrame->parent();
  905. }
  906. return nextFrame ? viewFrame : 0L;
  907. }
  908. // Linked-views feature, plus "sidebar follows URL opened in the active view" feature
  909. bool KonqMainWindow::makeViewsFollow( const KURL & url, const KParts::URLArgs &args,
  910. const TQString & serviceType, KonqView * senderView )
  911. {
  912. if ( !senderView->isLinkedView() && senderView != m_currentView )
  913. return false; // none of those features apply -> return
  914. bool res = false;
  915. //kdDebug(1202) << "makeViewsFollow " << senderView->className() << " url=" << url << " serviceType=" << serviceType << endl;
  916. KonqOpenURLRequest req;
  917. req.followMode = true;
  918. req.args = args;
  919. // We can't iterate over the map here, and openURL for each, because the map can get modified
  920. // (e.g. by part changes). Better copy the views into a list.
  921. TQPtrList<KonqView> listViews;
  922. MapViews::ConstIterator it = m_mapViews.begin();
  923. MapViews::ConstIterator end = m_mapViews.end();
  924. for (; it != end; ++it )
  925. listViews.append( it.data() );
  926. TQObject *senderFrame = lastFrame( senderView );
  927. for ( KonqView * view = listViews.first() ; view ; view = listViews.next())
  928. {
  929. bool followed = false;
  930. // Views that should follow this URL as both views are linked
  931. if ( (view != senderView) && view->isLinkedView() && senderView->isLinkedView() )
  932. {
  933. TQObject *viewFrame = lastFrame( view );
  934. // Only views in the same tab of the sender will follow
  935. if ( senderFrame && viewFrame && viewFrame != senderFrame )
  936. continue;
  937. kdDebug(1202) << "makeViewsFollow: Sending openURL to view " << view->part()->className() << " url=" << url << endl;
  938. // XXX duplicate code from ::openURL
  939. if ( view == m_currentView )
  940. {
  941. abortLoading();
  942. setLocationBarURL( url );
  943. }
  944. else
  945. view->stop();
  946. followed = openView( serviceType, url, view, req );
  947. }
  948. else
  949. {
  950. // Make the sidebar follow the URLs opened in the active view
  951. if ((view!=senderView) && view->isFollowActive() && senderView == m_currentView)
  952. {
  953. followed = openView(serviceType, url, view, req);
  954. }
  955. }
  956. // Ignore return value if the view followed but doesn't really
  957. // show the file contents. We still want to see that
  958. // file, e.g. in a separate viewer.
  959. // This happens in views locked to a directory mode,
  960. // like sidebar and konsolepart (#52161).
  961. bool ignore = view->isLockedViewMode() && view->supportsServiceType("inode/directory");
  962. //kdDebug(1202) << "View " << view->service()->name()
  963. // << " supports dirs: " << view->supportsServiceType( "inode/directory" )
  964. // << " is locked-view-mode:" << view->isLockedViewMode()
  965. // << " ignore=" << ignore << endl;
  966. if ( !ignore )
  967. res = followed || res;
  968. }
  969. return res;
  970. }
  971. void KonqMainWindow::abortLoading()
  972. {
  973. //kdDebug(1202) << "KonqMainWindow::abortLoading()" << endl;
  974. if ( m_currentView )
  975. {
  976. m_currentView->stop(); // will take care of the statusbar
  977. stopAnimation();
  978. }
  979. }
  980. void KonqMainWindow::slotCreateNewWindow( const KURL &url, const KParts::URLArgs &args )
  981. {
  982. kdDebug(1202) << "KonqMainWindow::slotCreateNewWindow url=" << url.prettyURL() << endl;
  983. if ( args.newTab() || ( KonqSettings::mmbOpensTab() &&
  984. (const_cast<KParts::URLArgs*>(&args)->metaData()["forcenewwindow"]).isEmpty()) ) {
  985. KonqOpenURLRequest req;
  986. req.newTab = true;
  987. req.newTabInFront = KonqSettings::newTabsInFront();
  988. req.openAfterCurrentPage = KonqSettings::openAfterCurrentPage();
  989. if (TDEApplication::keyboardMouseState() & TQt::ShiftButton)
  990. req.newTabInFront = !req.newTabInFront;
  991. req.args = args;
  992. openURL( 0L, url, TQString::null, req );
  993. }
  994. else
  995. {
  996. KonqMisc::createNewWindow( url, args );
  997. }
  998. }
  999. // This is mostly for the JS window.open call
  1000. void KonqMainWindow::slotCreateNewWindow( const KURL &url, const KParts::URLArgs &args,
  1001. const KParts::WindowArgs &windowArgs, KParts::ReadOnlyPart *&part )
  1002. {
  1003. kdDebug(1202) << "KonqMainWindow::slotCreateNewWindow(4 args) url=" << url.prettyURL()
  1004. << " args.serviceType=" << args.serviceType
  1005. << " args.frameName=" << args.frameName << endl;
  1006. part = 0; // Make sure to be initialized in case of failure...
  1007. KonqMainWindow *mainWindow = 0L;
  1008. if ( !args.frameName.isEmpty() && args.frameName.lower() != "_blank" )
  1009. {
  1010. KParts::BrowserHostExtension *hostExtension = 0;
  1011. KParts::ReadOnlyPart *ro_part = 0L;
  1012. KParts::BrowserExtension *be = ::tqqt_cast<KParts::BrowserExtension *>(sender());
  1013. if (be)
  1014. ro_part = ::tqqt_cast<KParts::ReadOnlyPart *>(be->parent());
  1015. if ( findChildView( ro_part, args.frameName, &mainWindow, &hostExtension, &part ) )
  1016. {
  1017. // Found a view. If url isn't empty, we should open it - but this never happens currently
  1018. // findChildView put the resulting part in 'part', so we can just return now
  1019. //kdDebug() << " frame=" << args.frameName << " -> found part=" << part << " " << part->name() << endl;
  1020. return;
  1021. }
  1022. }
  1023. if ( KonqSettings::popupsWithinTabs() || ( KonqSettings::mmbOpensTab() && windowArgs.lowerWindow ) ) {
  1024. bool aftercurrentpage = KonqSettings::openAfterCurrentPage();
  1025. bool newtabsinfront = KonqSettings::newTabsInFront();
  1026. if ( windowArgs.lowerWindow )
  1027. newtabsinfront =! newtabsinfront;
  1028. KonqView* newView = m_pViewManager->addTab(TQString::null, TQString::null, false, aftercurrentpage);
  1029. if (newView == 0L) return;
  1030. if (newtabsinfront)
  1031. m_pViewManager->showTab( newView );
  1032. openURL( newView, url.isEmpty() ? KURL("about:blank") : url, TQString::null);
  1033. newView->setViewName( args.frameName );
  1034. part=newView->part();
  1035. return;
  1036. }
  1037. mainWindow = new KonqMainWindow( KURL(), false );
  1038. mainWindow->setInitialFrameName( args.frameName );
  1039. mainWindow->resetAutoSaveSettings(); // Don't autosave
  1040. KonqOpenURLRequest req;
  1041. req.args = args;
  1042. if ( args.serviceType.isEmpty() )
  1043. mainWindow->openURL( 0L, url, TQString::null, req );
  1044. else if ( !mainWindow->openView( args.serviceType, url, 0L, req ) )
  1045. {
  1046. // we have problems. abort.
  1047. delete mainWindow;
  1048. part = 0;
  1049. return;
  1050. }
  1051. KonqView * view = 0L;
  1052. // cannot use activePart/currentView, because the activation through the partmanager
  1053. // is delayed by a singleshot timer (see KonqViewManager::setActivePart)
  1054. if ( mainWindow->viewMap().count() )
  1055. {
  1056. MapViews::ConstIterator it = mainWindow->viewMap().begin();
  1057. view = it.data();
  1058. part = it.key();
  1059. }
  1060. // activate the view _now_ in order to make the menuBar() hide call work
  1061. if ( part ) {
  1062. mainWindow->viewManager()->setActivePart( part, true );
  1063. }
  1064. TQString profileName = TQString::fromLatin1( url.isLocalFile() ? "konqueror/profiles/filemanagement" : "konqueror/profiles/webbrowsing" );
  1065. KSimpleConfig cfg( locate( "data", profileName ), true );
  1066. cfg.setGroup( "Profile" );
  1067. if ( windowArgs.x != -1 )
  1068. mainWindow->move( windowArgs.x, mainWindow->y() );
  1069. if ( windowArgs.y != -1 )
  1070. mainWindow->move( mainWindow->x(), windowArgs.y );
  1071. TQSize size = KonqViewManager::readConfigSize( cfg, mainWindow );
  1072. int width;
  1073. if ( windowArgs.width != -1 )
  1074. width = windowArgs.width;
  1075. else
  1076. width = size.isValid() ? size.width() : mainWindow->width();
  1077. int height;
  1078. if ( windowArgs.height != -1 )
  1079. height = windowArgs.height;
  1080. else
  1081. height = size.isValid() ? size.height() : mainWindow->height();
  1082. mainWindow->resize( width, height );
  1083. // process the window args
  1084. if ( !windowArgs.menuBarVisible )
  1085. {
  1086. mainWindow->menuBar()->hide();
  1087. mainWindow->m_paShowMenuBar->setChecked( false );
  1088. }
  1089. if ( !windowArgs.toolBarsVisible )
  1090. {
  1091. for ( TQPtrListIterator<TDEToolBar> it( mainWindow->toolBarIterator() ); it.current(); ++it )
  1092. {
  1093. (*it)->hide();
  1094. }
  1095. }
  1096. if ( view ) {
  1097. if ( !windowArgs.scrollBarsVisible )
  1098. view->disableScrolling();
  1099. if ( !windowArgs.statusBarVisible )
  1100. view->frame()->statusbar()->hide();
  1101. }
  1102. if ( !windowArgs.resizable )
  1103. // ### this doesn't seem to work :-(
  1104. mainWindow->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
  1105. // Trying to show the window initially behind the current window is a bit tricky,
  1106. // as this involves the window manager, which may see things differently.
  1107. // Many WMs raise and activate new windows, which means without WM support this won't work very
  1108. // well. If the WM has support for _NET_WM_USER_TIME, it will be just set to 0 (=don't focus on show),
  1109. // and the WM should take care of it itself.
  1110. bool wm_usertime_support = false;
  1111. Time saved_last_input_time = GET_QT_X_USER_TIME();
  1112. if ( windowArgs.lowerWindow )
  1113. {
  1114. NETRootInfo wm_info( tqt_xdisplay(), NET::Supported );
  1115. wm_usertime_support = wm_info.isSupported( NET::WM2UserTime );
  1116. if( wm_usertime_support )
  1117. {
  1118. // *sigh*, and I thought nobody would need TQWidget::dontFocusOnShow().
  1119. // Avoid Qt's support for user time by setting it to 0, and
  1120. // set the property ourselves.
  1121. SET_QT_X_USER_TIME(0);
  1122. KWin::setUserTime( mainWindow->winId(), 0 );
  1123. }
  1124. // Put below the current window before showing, in case that actually works with the WM.
  1125. // First do complete lower(), then stackUnder(), because the latter may not work with many WMs.
  1126. mainWindow->lower();
  1127. mainWindow->stackUnder( this );
  1128. }
  1129. mainWindow->show();
  1130. if ( windowArgs.lowerWindow )
  1131. {
  1132. SET_QT_X_USER_TIME(saved_last_input_time);
  1133. if( !wm_usertime_support )
  1134. { // No WM support. Let's try ugly tricks.
  1135. mainWindow->lower();
  1136. mainWindow->stackUnder( this );
  1137. if( this->isActiveWindow())
  1138. this->setActiveWindow();
  1139. }
  1140. }
  1141. if ( windowArgs.fullscreen )
  1142. mainWindow->action( "fullscreen" )->activate();
  1143. }
  1144. void KonqMainWindow::slotNewWindow()
  1145. {
  1146. // Use profile from current window, if set
  1147. TQString profile = m_pViewManager->currentProfile();
  1148. if ( profile.isEmpty() )
  1149. {
  1150. if ( m_currentView && m_currentView->url().protocol().startsWith( "http" ) )
  1151. profile = TQString::fromLatin1("webbrowsing");
  1152. else
  1153. profile = TQString::fromLatin1("filemanagement");
  1154. }
  1155. KonqMisc::createBrowserWindowFromProfile(
  1156. locate( "data", TQString::fromLatin1("konqueror/profiles/")+profile ),
  1157. profile );
  1158. }
  1159. void KonqMainWindow::slotDuplicateWindow()
  1160. {
  1161. KTempFile tempFile;
  1162. tempFile.setAutoDelete( true );
  1163. TDEConfig config( tempFile.name() );
  1164. config.setGroup( "View Profile" );
  1165. m_pViewManager->saveViewProfile( config, true, true );
  1166. KonqMainWindow *mainWindow = new KonqMainWindow( KURL(), false, 0, xmlFile());
  1167. mainWindow->viewManager()->loadViewProfile( config, m_pViewManager->currentProfile() );
  1168. if (mainWindow->currentView())
  1169. {
  1170. mainWindow->copyHistory( childFrame() );
  1171. }
  1172. mainWindow->activateChild();
  1173. mainWindow->show();
  1174. #ifndef NDEBUG
  1175. mainWindow->viewManager()->printFullHierarchy( this );
  1176. #endif
  1177. }
  1178. void KonqMainWindow::slotSendURL()
  1179. {
  1180. KURL::List lst = currentURLs();
  1181. TQString body;
  1182. TQString fileNameList;
  1183. for ( KURL::List::Iterator it = lst.begin() ; it != lst.end() ; ++it )
  1184. {
  1185. if ( !body.isEmpty() ) body += '\n';
  1186. body += (*it).prettyURL();
  1187. if ( !fileNameList.isEmpty() ) fileNameList += ", ";
  1188. fileNameList += (*it).fileName();
  1189. }
  1190. TQString subject;
  1191. if ( m_currentView && !m_currentView->part()->inherits("KonqDirPart") )
  1192. subject = m_currentView->caption();
  1193. else
  1194. subject = fileNameList;
  1195. kapp->invokeMailer(TQString::null,TQString::null,TQString::null,
  1196. subject, body);
  1197. }
  1198. void KonqMainWindow::slotSendFile()
  1199. {
  1200. KURL::List lst = currentURLs();
  1201. TQStringList urls;
  1202. TQString fileNameList;
  1203. for ( KURL::List::Iterator it = lst.begin() ; it != lst.end() ; ++it )
  1204. {
  1205. if ( !fileNameList.isEmpty() ) fileNameList += ", ";
  1206. if ( (*it).isLocalFile() && TQFileInfo((*it).path()).isDir() )
  1207. {
  1208. // Create a temp dir, so that we can put the ZIP file in it with a proper name
  1209. KTempFile zipFile;
  1210. TQString zipFileName = zipFile.name();
  1211. zipFile.unlink();
  1212. TQDir().mkdir(zipFileName,true);
  1213. zipFileName = zipFileName+"/"+(*it).fileName()+".zip";
  1214. KZip zip( zipFileName );
  1215. if ( !zip.open( IO_WriteOnly ) )
  1216. continue; // TODO error message
  1217. zip.addLocalDirectory( (*it).path(), TQString::null );
  1218. zip.close();
  1219. fileNameList += (*it).fileName()+".zip";
  1220. urls.append( zipFileName );
  1221. }
  1222. else
  1223. {
  1224. fileNameList += (*it).fileName();
  1225. urls.append( (*it).url() );
  1226. }
  1227. }
  1228. TQString subject;
  1229. if ( m_currentView && !m_currentView->part()->inherits("KonqDirPart") )
  1230. subject = m_currentView->caption();
  1231. else
  1232. subject = fileNameList;
  1233. kapp->invokeMailer(TQString::null, TQString::null, TQString::null, subject,
  1234. TQString::null, //body
  1235. TQString::null,
  1236. urls); // attachments
  1237. }
  1238. void KonqMainWindow::slotOpenTerminal()
  1239. {
  1240. TQString term = KonqSettings::terminalApplication();
  1241. TQString dir ( TQDir::homeDirPath() );
  1242. //Try to get the directory of the current view
  1243. if ( m_currentView )
  1244. {
  1245. KURL u( m_currentView->url() );
  1246. // If the given directory is not local, it can still be the URL of an
  1247. // ioslave using UDS_LOCAL_PATH which to be converted first.
  1248. u = TDEIO::NetAccess::mostLocalURL(u, this);
  1249. //If the URL is local after the above conversion, set the directory.
  1250. if ( u.isLocalFile() )
  1251. {
  1252. TQString mime = m_currentView->serviceType();
  1253. if ( KMimeType::mimeType(mime)->is("inode/directory") )
  1254. dir = u.path();
  1255. else
  1256. dir = u.directory();
  1257. }
  1258. }
  1259. TDEProcess cmd;
  1260. cmd.setWorkingDirectory(dir);
  1261. // Compensate for terminal having arguments.
  1262. TQStringList args = TQStringList::split(' ', term);
  1263. for ( TQStringList::iterator it = args.begin(); it != args.end(); ++it )
  1264. cmd << *it;
  1265. kdDebug(1202) << "slotOpenTerminal: directory " << dir
  1266. << ", terminal:" << term << endl;
  1267. cmd.start(TDEProcess::DontCare);
  1268. }
  1269. void KonqMainWindow::slotOpenLocation()
  1270. {
  1271. // Don't pre-fill the url, as it is auto-selected and thus overwrites the
  1272. // X clipboard, making it impossible to paste in the url you really wanted.
  1273. // Another example of why the X clipboard sux
  1274. KURLRequesterDlg dlg( TQString::null, this, 0, true);
  1275. dlg.setCaption( i18n("Open Location") );
  1276. // Set current directory for relative paths.
  1277. // Testcase: konqueror www.kde.org; Ctrl+O; file in $HOME; would open http://$file
  1278. TQString currentDir;
  1279. if (m_currentView && m_currentView->url().isLocalFile())
  1280. currentDir = m_currentView->url().path(1);
  1281. dlg.urlRequester()->completionObject()->setDir( currentDir );
  1282. dlg.urlRequester()->setMode( KFile::File | KFile::Directory | KFile::ExistingOnly );
  1283. dlg.exec();
  1284. const KURL& url = dlg.selectedURL();
  1285. if (!url.isEmpty())
  1286. openFilteredURL( url.url().stripWhiteSpace() );
  1287. }
  1288. void KonqMainWindow::slotToolFind()
  1289. {
  1290. kdDebug(1202) << "KonqMainWindow::slotToolFind sender:" << TQT_TQOBJECT_CONST(sender())->className() << endl;
  1291. if ( m_currentView && m_currentView->part()->inherits("KonqDirPart") )
  1292. {
  1293. KonqDirPart* dirPart = static_cast<KonqDirPart *>(m_currentView->part());
  1294. if (!m_paFindFiles->isChecked())
  1295. {
  1296. dirPart->slotFindClosed();
  1297. return;
  1298. }
  1299. KonqViewFactory factory = KonqFactory::createView( "Konqueror/FindPart" );
  1300. if ( factory.isNull() )
  1301. {
  1302. KMessageBox::error( this, i18n("Cannot create the find part, check your installation.") );
  1303. m_paFindFiles->setChecked(false);
  1304. return;
  1305. }
  1306. KParts::ReadOnlyPart* findPart = factory.create( m_currentView->frame(), "findPartWidget", dirPart, "findPart" );
  1307. dirPart->setFindPart( findPart );
  1308. m_currentView->frame()->insertTopWidget( findPart->widget() );
  1309. findPart->widget()->show();
  1310. findPart->widget()->setFocus();
  1311. connect( dirPart, TQT_SIGNAL( findClosed(KonqDirPart *) ),
  1312. this, TQT_SLOT( slotFindClosed(KonqDirPart *) ) );
  1313. }
  1314. else if ( TQT_TQOBJECT_CONST(sender())->inherits( "TDEAction" ) ) // don't go there if called by the singleShot below
  1315. {
  1316. KURL url;
  1317. if ( m_currentView && m_currentView->url().isLocalFile() )
  1318. url = m_currentView->locationBarURL();
  1319. else
  1320. url.setPath( TQDir::homeDirPath() );
  1321. KonqMainWindow * mw = KonqMisc::createBrowserWindowFromProfile(
  1322. locate( "data", TQString::fromLatin1("konqueror/profiles/filemanagement") ),
  1323. "filemanagement", url, KParts::URLArgs(), true /* forbid "use html"*/ );
  1324. mw->m_paFindFiles->setChecked(true);
  1325. // Delay it after the openURL call (hacky!)
  1326. TQTimer::singleShot( 1, mw, TQT_SLOT(slotToolFind()));
  1327. m_paFindFiles->setChecked(false);
  1328. }
  1329. }
  1330. void KonqMainWindow::slotFindOpen( KonqDirPart * dirPart )
  1331. {
  1332. kdDebug(1202) << "KonqMainWindow::slotFindOpen " << dirPart << endl;
  1333. Q_ASSERT( m_currentView );
  1334. Q_ASSERT( m_currentView->part() == dirPart );
  1335. slotToolFind(); // lazy me
  1336. }
  1337. void KonqMainWindow::slotFindClosed( KonqDirPart * dirPart )
  1338. {
  1339. kdDebug(1202) << "KonqMainWindow::slotFindClosed " << dirPart << endl;
  1340. KonqView * dirView = m_mapViews.find( dirPart ).data();
  1341. Q_ASSERT(dirView);
  1342. kdDebug(1202) << "dirView=" << dirView << endl;
  1343. if ( dirView && dirView == m_currentView )
  1344. m_paFindFiles->setEnabled( true );
  1345. m_paFindFiles->setChecked(false);
  1346. }
  1347. void KonqMainWindow::slotIconsChanged()
  1348. {
  1349. //kdDebug(1202) << "KonqMainWindow::slotIconsChanged" << endl;
  1350. m_combo->updatePixmaps();
  1351. m_pViewManager->updatePixmaps();
  1352. setIcon( KonqPixmapProvider::self()->pixmapFor( m_combo->currentText() ));
  1353. }
  1354. void KonqMainWindow::slotOpenWith()
  1355. {
  1356. KURL::List lst;
  1357. lst.append( m_currentView->url() );
  1358. TQString serviceName = TQT_TQOBJECT_CONST(sender())->name();
  1359. TDETrader::OfferList offers = m_currentView->appServiceOffers();
  1360. TDETrader::OfferList::ConstIterator it = offers.begin();
  1361. TDETrader::OfferList::ConstIterator end = offers.end();
  1362. for (; it != end; ++it )
  1363. if ( (*it)->desktopEntryName() == serviceName )
  1364. {
  1365. KRun::run( **it, lst );
  1366. return;
  1367. }
  1368. }
  1369. void KonqMainWindow::slotViewModeToggle( bool toggle )
  1370. {
  1371. if ( !toggle )
  1372. return;
  1373. TQString modeName = TQT_TQOBJECT_CONST(sender())->name();
  1374. if ( m_currentView->service()->desktopEntryName() == modeName )
  1375. return;
  1376. m_bViewModeToggled = true;
  1377. m_currentView->stop();
  1378. m_currentView->lockHistory();
  1379. // Save those, because changeViewMode will lose them
  1380. KURL url = m_currentView->url();
  1381. TQString locationBarURL = m_currentView->locationBarURL();
  1382. TQStringList filesToSelect;
  1383. if( m_currentView->part()->inherits( "KonqDirPart" ) ) {
  1384. KFileItemList fileItemsToSelect = static_cast<KonqDirPart*>(m_currentView->part())->selectedFileItems();
  1385. KFileItemListIterator it( fileItemsToSelect );
  1386. while( it.current() ){
  1387. filesToSelect += it.current()->name();
  1388. ++it;
  1389. }
  1390. }
  1391. bool bQuickViewModeChange = false;
  1392. // iterate over all services, update the toolbar service map
  1393. // and check if we can do a quick property-based viewmode change
  1394. const TDETrader::OfferList offers = m_currentView->partServiceOffers();
  1395. TDETrader::OfferList::ConstIterator oIt = offers.begin();
  1396. TDETrader::OfferList::ConstIterator oEnd = offers.end();
  1397. const TQString currentServiceKey = viewModeActionKey( m_currentView->service() );
  1398. for (; oIt != oEnd; ++oIt )
  1399. {
  1400. KService::Ptr service = *oIt;
  1401. if ( service->desktopEntryName() == modeName )
  1402. {
  1403. // we changed the viewmode of either iconview or listview
  1404. // -> update the service in the corresponding map, so that
  1405. // we can set the correct text, icon, etc. properties to the
  1406. // KonqViewModeAction when rebuilding the view-mode actions in
  1407. // updateViewModeActions
  1408. // (I'm saying iconview/listview here, but theoretically it could be
  1409. // any view :)
  1410. const TQString serviceKey = viewModeActionKey( service );
  1411. m_viewModeToolBarServices[ serviceKey ] = service;
  1412. if ( serviceKey == currentServiceKey )
  1413. {
  1414. TQVariant modeProp = service->property( "X-TDE-BrowserView-ModeProperty" );
  1415. TQVariant modePropValue = service->property( "X-TDE-BrowserView-ModePropertyValue" );
  1416. if ( !modeProp.isValid() || !modePropValue.isValid() )
  1417. break;
  1418. m_currentView->part()->setProperty( modeProp.toString().latin1(), modePropValue );
  1419. KService::Ptr oldService = m_currentView->service();
  1420. // we aren't going to re-build the viewmode actions but instead of a
  1421. // quick viewmode change (iconview) -> find the iconview-konqviewmode
  1422. // action and set new text,icon,etc. properties, to show the new
  1423. // current viewmode
  1424. TQPtrListIterator<TDEAction> it( m_toolBarViewModeActions );
  1425. for (; it.current(); ++it )
  1426. if ( TQString::fromLatin1( it.current()->name() ) == oldService->desktopEntryName() )
  1427. {
  1428. assert( it.current()->inherits( "KonqViewModeAction" ) );
  1429. KonqViewModeAction *action = static_cast<KonqViewModeAction *>( it.current() );
  1430. action->setChecked( true );
  1431. TQString servicename = service->genericName();
  1432. if (servicename.isEmpty())
  1433. servicename = service->name();
  1434. action->setText( servicename );
  1435. action->setIcon( service->icon() );
  1436. action->setName( service->desktopEntryName().ascii() );
  1437. break;
  1438. }
  1439. m_currentView->setService( service );
  1440. bQuickViewModeChange = true;
  1441. break;
  1442. }
  1443. }
  1444. }
  1445. if ( !bQuickViewModeChange )
  1446. {
  1447. m_currentView->changeViewMode( m_currentView->serviceType(), modeName );
  1448. KURL locURL = KURL::fromPathOrURL( locationBarURL );
  1449. TQString nameFilter = detectNameFilter( locURL );
  1450. if( m_currentView->part()->inherits( "KonqDirPart" ) )
  1451. static_cast<KonqDirPart*>( m_currentView->part() )->setFilesToSelect( filesToSelect );
  1452. m_currentView->openURL( locURL, locationBarURL, nameFilter );
  1453. }
  1454. // Now save this setting, either locally or globally (for directories only)
  1455. // (We don't have views with viewmodes other than for dirs currently;
  1456. // once we do, we might want to implement per-mimetype global-saving)
  1457. if ( m_bSaveViewPropertiesLocally && m_currentView->supportsServiceType( "inode/directory" ) )
  1458. {
  1459. KURL u ( m_currentView->url() );
  1460. u.addPath(".directory");
  1461. if ( u.isLocalFile() )
  1462. {
  1463. KSimpleConfig config( u.path() ); // if we have no write access, just drop it
  1464. config.setGroup( "URL properties" );
  1465. config.writeEntry( "ViewMode", modeName );
  1466. config.sync();
  1467. }
  1468. } else
  1469. {
  1470. // We save the global view mode only if the view is a built-in view
  1471. if ( m_currentView->isBuiltinView() )
  1472. {
  1473. KonqSettings::setMainViewViewMode( modeName );
  1474. KonqSettings::writeConfig();
  1475. }
  1476. }
  1477. }
  1478. void KonqMainWindow::showHTML( KonqView * _view, bool b, bool _activateView )
  1479. {
  1480. // Save this setting, either locally or globally
  1481. // This has to be done before calling openView since it relies on it
  1482. if ( m_bSaveViewPropertiesLocally )
  1483. {
  1484. KURL u ( b ? _view->url() : KURL( _view->url().directory() ) );
  1485. u.addPath(".directory");
  1486. if ( u.isLocalFile() )
  1487. {
  1488. KSimpleConfig config( u.path() ); // No checks for access
  1489. config.setGroup( "URL properties" );
  1490. config.writeEntry( "HTMLAllowed", b );
  1491. config.sync();
  1492. }
  1493. } else
  1494. {
  1495. KonqSettings::setHtmlAllowed( b );
  1496. KonqSettings::writeConfig();
  1497. if ( _activateView )
  1498. m_bHTMLAllowed = b;
  1499. }
  1500. if ( b && _view->supportsServiceType( "inode/directory" ) )
  1501. {
  1502. _view->lockHistory();
  1503. openView( "inode/directory", _view->url(), _view );
  1504. }
  1505. else if ( !b && _view->supportsServiceType( "text/html" ) )
  1506. {
  1507. KURL u( _view->url() );
  1508. TQString fileName = u.fileName().lower();
  1509. if ( KProtocolInfo::supportsListing( u ) && fileName.startsWith("index.htm") ) {
  1510. _view->lockHistory();
  1511. u.setPath( u.directory() );
  1512. openView( "inode/directory", u, _view );
  1513. }
  1514. }
  1515. }
  1516. void KonqMainWindow::slotShowHTML()
  1517. {
  1518. bool b = !m_currentView->allowHTML();
  1519. m_currentView->stop();
  1520. m_currentView->setAllowHTML( b );
  1521. showHTML( m_currentView, b, true ); //current view
  1522. m_pViewManager->showHTML(b );
  1523. }
  1524. void KonqMainWindow::setShowHTML( bool b )
  1525. {
  1526. m_bHTMLAllowed = b;
  1527. if ( m_currentView )
  1528. m_currentView->setAllowHTML( b );
  1529. m_ptaUseHTML->setChecked( b );
  1530. }
  1531. void KonqMainWindow::slotLockView()
  1532. {
  1533. m_currentView->setLockedLocation( m_paLockView->isChecked() );
  1534. }
  1535. void KonqMainWindow::slotStop()
  1536. {
  1537. abortLoading();
  1538. if ( m_currentView )
  1539. {
  1540. m_currentView->frame()->statusbar()->message( i18n("Canceled.") );
  1541. }
  1542. }
  1543. void KonqMainWindow::slotLinkView()
  1544. {
  1545. // Can't access this action in passive mode anyway
  1546. assert(!m_currentView->isPassiveMode());
  1547. bool mode = !m_currentView->isLinkedView();
  1548. if (linkableViewsCount() == 2)
  1549. {
  1550. // Exactly two linkable views : link both
  1551. KonqMainWindow::MapViews::ConstIterator it = viewMap().begin();
  1552. if( (*it)->isFollowActive() ) // skip sidebar
  1553. ++it;
  1554. (*it)->setLinkedView( mode );
  1555. ++it;
  1556. if( (*it)->isFollowActive() ) // skip sidebar
  1557. ++it;
  1558. (*it)->setLinkedView( mode );
  1559. }
  1560. else // Normal case : just this view
  1561. m_currentView->setLinkedView( mode );
  1562. }
  1563. void KonqMainWindow::slotReload( KonqView* reloadView )
  1564. {
  1565. if ( !reloadView )
  1566. reloadView = m_currentView;
  1567. if ( !reloadView || reloadView->url().isEmpty() )
  1568. return;
  1569. if ( reloadView->part() && (reloadView->part()->metaObject()->findProperty("modified") != -1) ) {
  1570. TQVariant prop = reloadView->part()->property("modified");
  1571. if (prop.isValid() && prop.toBool())
  1572. if ( KMessageBox::warningContinueCancel( this,
  1573. i18n("This page contains changes that have not been submitted.\nReloading the page will discard these changes."),
  1574. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"reload"), "discardchangesreload") != KMessageBox::Continue )
  1575. return;
  1576. }
  1577. KonqOpenURLRequest req( reloadView->typedURL() );
  1578. req.userRequestedReload = true;
  1579. if ( reloadView->prepareReload( req.args ) )
  1580. {
  1581. reloadView->lockHistory();
  1582. // Reuse current servicetype for local files, but not for remote files (it could have changed, e.g. over HTTP)
  1583. TQString serviceType = reloadView->url().isLocalFile() ? reloadView->serviceType() : TQString::null;
  1584. openURL( reloadView, reloadView->url(), serviceType, req );
  1585. }
  1586. }
  1587. void KonqMainWindow::slotReloadStop() {
  1588. if (m_paReloadStop->icon() == "reload") {
  1589. slotReload();
  1590. toggleReloadStopButton(true);
  1591. } else {
  1592. slotStop();
  1593. toggleReloadStopButton(false);
  1594. }
  1595. }
  1596. void KonqMainWindow::toggleReloadStopButton(bool isReload) {
  1597. //m_paStop = new TDEAction( i18n( "&Stop" ), "process-stop", Key_Escape, this, TQT_SLOT( slotStop() ), actionCollection(), "stop" );
  1598. if (isReload) {
  1599. m_paReloadStop->setIcon("process-stop");
  1600. m_paReloadStop->setWhatsThis( i18n( "Stop loading the document<p>"
  1601. "All network transfers will be stopped and Konqueror will display the content "
  1602. "that has been received so far." ) );
  1603. m_paReloadStop->setToolTip( i18n( "Stop loading the document" ) );
  1604. //m_paReloadStop = new TDEAction( i18n( "&Reload" ), "reload", reloadShortcut, this, TQT_SLOT( slotReloadStop() ), actionCollection(), "reload" );
  1605. } else {
  1606. m_paReloadStop->setIcon("reload");
  1607. m_paReloadStop->setWhatsThis( i18n( "Reload the currently displayed document<p>"
  1608. "This may, for example, be needed to refresh webpages that have been "
  1609. "modified since they were loaded, in order to make the changes visible." ) );
  1610. m_paReloadStop->setToolTip( i18n( "Reload the currently displayed document" ) );
  1611. }
  1612. }
  1613. void KonqMainWindow::slotReloadPopup()
  1614. {
  1615. if (m_pWorkingTab)
  1616. slotReload( m_pWorkingTab->activeChildView() );
  1617. }
  1618. void KonqMainWindow::slotHome(TDEAction::ActivationReason, TQt::ButtonState state)
  1619. {
  1620. TQString homeURL = m_pViewManager->profileHomeURL();
  1621. if (homeURL.isEmpty())
  1622. homeURL = KonqFMSettings::settings()->homeURL();
  1623. KonqOpenURLRequest req;
  1624. req.newTab = true;
  1625. req.newTabInFront = KonqSettings::newTabsInFront();
  1626. if (state & TQt::ShiftButton)
  1627. req.newTabInFront = !req.newTabInFront;
  1628. if( state & TQt::ControlButton ) // Ctrl Left/MMB
  1629. openFilteredURL( homeURL, req);
  1630. else if( state & Qt::MidButton )
  1631. {
  1632. if(KonqSettings::mmbOpensTab())
  1633. openFilteredURL( homeURL, req);
  1634. else
  1635. {
  1636. KURL finalURL = KonqMisc::konqFilteredURL( this, homeURL );
  1637. KonqMisc::createNewWindow( finalURL.url() );
  1638. }
  1639. }
  1640. else
  1641. openFilteredURL( homeURL, false );
  1642. }
  1643. void KonqMainWindow::slotHome()
  1644. {
  1645. slotHome(TDEAction::UnknownActivation, Qt::LeftButton);
  1646. }
  1647. void KonqMainWindow::slotGoSystem()
  1648. {
  1649. openURL( 0L, KURL( "system:/" ) );
  1650. }
  1651. void KonqMainWindow::slotGoApplications()
  1652. {
  1653. openURL( 0L, KURL( "programs:/" ) );
  1654. }
  1655. void KonqMainWindow::slotGoMedia()
  1656. {
  1657. openURL( 0L, KURL( "media:/" ) );
  1658. }
  1659. void KonqMainWindow::slotGoNetworkFolders()
  1660. {
  1661. openURL( 0L, KURL( "remote:/" ) );
  1662. }
  1663. void KonqMainWindow::slotGoSettings()
  1664. {
  1665. openURL( 0L, KURL( "settings:/" ) );
  1666. }
  1667. void KonqMainWindow::slotGoDirTree()
  1668. {
  1669. KURL u;
  1670. u.setPath( locateLocal( "data", "konqueror/dirtree/" ) );
  1671. openURL( 0L, u );
  1672. }
  1673. void KonqMainWindow::slotGoTrash()
  1674. {
  1675. openURL( 0L, KURL( "trash:/" ) );
  1676. }
  1677. void KonqMainWindow::slotGoAutostart()
  1678. {
  1679. KURL u;
  1680. u.setPath( TDEGlobalSettings::autostartPath() );
  1681. openURL( 0L, u );
  1682. }
  1683. void KonqMainWindow::slotGoHistory()
  1684. {
  1685. TDEAction *a = m_toggleViewGUIClient->action("konq_sidebartng");
  1686. if (!a) {
  1687. KMessageBox::sorry(0L, i18n("Your sidebar is not functional or unavailable."), i18n("Show History Sidebar"));
  1688. return;
  1689. }
  1690. // Show the sidebar
  1691. if (!static_cast<TDEToggleAction*>(a)->isChecked()) {
  1692. a->activate();
  1693. TQTimer::singleShot( 0, this, TQT_SLOT(slotGoHistory()));
  1694. return;
  1695. }
  1696. // Tell it to show the history plugin
  1697. MapViews::ConstIterator it;
  1698. for (it = viewMap().begin(); it != viewMap().end(); ++it) {
  1699. KonqView *view = it.data();
  1700. if (view) {
  1701. KService::Ptr svc = view->service();
  1702. if (svc->desktopEntryName() == "konq_sidebartng") {
  1703. if (!view->part()->openURL("sidebar:history.desktop"))
  1704. KMessageBox::sorry(0L, i18n("Cannot find running history plugin in your sidebar."), i18n("Show History Sidebar"));
  1705. break;
  1706. }
  1707. }
  1708. }
  1709. }
  1710. TQStringList KonqMainWindow::configModules() const
  1711. {
  1712. return m_configureModules;
  1713. }
  1714. void KonqMainWindow::slotConfigureExtensions()
  1715. {
  1716. KonqExtensionManager extensionManager(0, this, m_currentView ? m_currentView->part() : 0);
  1717. extensionManager.exec();
  1718. }
  1719. void KonqMainWindow::slotConfigure()
  1720. {
  1721. if( !m_configureDialog )
  1722. {
  1723. m_configureDialog = new KCMultiDialog( this, "configureDialog" );
  1724. TQStringList modules = configModules();
  1725. TQStringList::ConstIterator end( modules.end() );
  1726. for( TQStringList::ConstIterator it = modules.begin();
  1727. it != end; ++it )
  1728. {
  1729. if ( kapp->authorizeControlModule( *it ) )
  1730. {
  1731. m_configureDialog->addModule( *it );
  1732. }
  1733. }
  1734. }
  1735. m_configureDialog->show();
  1736. }
  1737. void KonqMainWindow::slotConfigureSpellChecking()
  1738. {
  1739. TDEApplication::startServiceByDesktopName("spellchecking");
  1740. }
  1741. void KonqMainWindow::slotConfigureToolbars()
  1742. {
  1743. if ( autoSaveSettings() )
  1744. saveMainWindowSettings( TDEGlobal::config(), "KonqMainWindow" );
  1745. KEditToolbar dlg(factory());
  1746. connect(&dlg,TQT_SIGNAL(newToolbarConfig()),this,TQT_SLOT(slotNewToolbarConfig()));
  1747. connect(&dlg,TQT_SIGNAL(newToolbarConfig()),this,TQT_SLOT(initBookmarkBar()));
  1748. dlg.exec();
  1749. }
  1750. void KonqMainWindow::slotNewToolbarConfig() // This is called when OK or Apply is clicked
  1751. {
  1752. if ( m_toggleViewGUIClient )
  1753. plugActionList( TQString::fromLatin1( "toggleview" ), m_toggleViewGUIClient->actions() );
  1754. if ( m_currentView && m_currentView->appServiceOffers().count() > 0 )
  1755. plugActionList( "openwith", m_openWithActions );
  1756. plugViewModeActions();
  1757. applyMainWindowSettings( TDEGlobal::config(), "KonqMainWindow" );
  1758. }
  1759. void KonqMainWindow::slotUndoAvailable( bool avail )
  1760. {
  1761. bool enable = false;
  1762. if ( avail && m_currentView && m_currentView->part() )
  1763. {
  1764. // Avoid tqWarning from TQObject::property if it doesn't exist
  1765. if ( m_currentView->part()->metaObject()->findProperty( "supportsUndo" ) != -1 )
  1766. {
  1767. TQVariant prop = m_currentView->part()->property( "supportsUndo" );
  1768. if ( prop.isValid() && prop.toBool() )
  1769. enable = true;
  1770. }
  1771. }
  1772. m_paUndo->setEnabled( enable );
  1773. }
  1774. void KonqMainWindow::slotPartChanged( KonqView *childView, KParts::ReadOnlyPart *oldPart, KParts::ReadOnlyPart *newPart )
  1775. {
  1776. kdDebug(1202) << "KonqMainWindow::slotPartChanged" << endl;
  1777. m_mapViews.remove( oldPart );
  1778. m_mapViews.insert( newPart, childView );
  1779. // Remove the old part, and add the new part to the manager
  1780. // Note: this makes the new part active... so it calls slotPartActivated
  1781. m_pViewManager->replacePart( oldPart, newPart, false );
  1782. // Set active immediately
  1783. m_pViewManager->setActivePart( newPart, true );
  1784. viewsChanged();
  1785. }
  1786. void KonqMainWindow::slotRunFinished()
  1787. {
  1788. kdDebug(1202) << "KonqMainWindow::slotRunFinished()" << endl;
  1789. const KonqRun *run = static_cast<const KonqRun *>( sender() );
  1790. if ( run == m_initialKonqRun )
  1791. m_initialKonqRun = 0L;
  1792. if ( !run->mailtoURL().isEmpty() )
  1793. {
  1794. kapp->invokeMailer( run->mailtoURL() );
  1795. }
  1796. if ( run->hasError() ) { // we had an error
  1797. TQByteArray data;
  1798. TQDataStream s( data, IO_WriteOnly );
  1799. s << run->url().prettyURL() << kapp->dcopClient()->defaultObject();
  1800. kapp->dcopClient()->send( "konqueror*", "KonquerorIface",
  1801. "removeFromCombo(TQString,TQCString)", data);
  1802. }
  1803. KonqView *childView = run->childView();
  1804. // Check if we found a mimetype _and_ we got no error (example: cancel in openwith dialog)
  1805. if ( run->foundMimeType() && !run->hasError() )
  1806. {
  1807. // We do this here and not in the constructor, because
  1808. // we are waiting for the first view to be set up before doing this...
  1809. // Note: this is only used when konqueror is started from command line.....
  1810. if ( m_bNeedApplyKonqMainWindowSettings )
  1811. {
  1812. m_bNeedApplyKonqMainWindowSettings = false; // only once
  1813. applyKonqMainWindowSettings();
  1814. }
  1815. return;
  1816. }
  1817. if ( childView )
  1818. {
  1819. childView->setLoading( false );
  1820. if ( childView == m_currentView )
  1821. {
  1822. stopAnimation();
  1823. // Revert to working URL - unless the URL was typed manually
  1824. kdDebug(1202) << " typed URL = " << run->typedURL() << endl;
  1825. if ( run->typedURL().isEmpty() && childView->history().current() ) // not typed
  1826. childView->setLocationBarURL( childView->history().current()->locationBarURL );
  1827. }
  1828. }
  1829. else // No view, e.g. empty webbrowsing profile
  1830. stopAnimation();
  1831. }
  1832. void KonqMainWindow::applyKonqMainWindowSettings()
  1833. {
  1834. TQStringList toggableViewsShown = KonqSettings::toggableViewsShown();
  1835. TQStringList::ConstIterator togIt = toggableViewsShown.begin();
  1836. TQStringList::ConstIterator togEnd = toggableViewsShown.end();
  1837. for ( ; togIt != togEnd ; ++togIt )
  1838. {
  1839. // Find the action by name
  1840. // TDEAction * act = m_toggleViewGUIClient->actionCollection()->action( (*togIt).latin1() );
  1841. TDEAction *act = m_toggleViewGUIClient->action( *togIt );
  1842. if ( act )
  1843. act->activate();
  1844. else
  1845. kdWarning(1202) << "Unknown toggable view in ToggableViewsShown " << *togIt << endl;
  1846. }
  1847. }
  1848. void KonqMainWindow::slotSetStatusBarText( const TQString & )
  1849. {
  1850. // Reimplemented to disable KParts::MainWindow default behaviour
  1851. // Does nothing here, see konq_frame.cc
  1852. }
  1853. void KonqMainWindow::slotViewCompleted( KonqView * view )
  1854. {
  1855. assert( view );
  1856. // Need to update the current working directory
  1857. // of the completion object every time the user
  1858. // changes the directory!! (DA)
  1859. if( m_pURLCompletion )
  1860. {
  1861. KURL u( view->locationBarURL() );
  1862. if( u.isLocalFile() )
  1863. m_pURLCompletion->setDir( u.path() );
  1864. else
  1865. m_pURLCompletion->setDir( u.url() ); //needs work!! (DA)
  1866. }
  1867. }
  1868. void KonqMainWindow::slotPartActivated( KParts::Part *part )
  1869. {
  1870. kdDebug(1202) << "KonqMainWindow::slotPartActivated " << part << " "
  1871. << ( part && part->instance() && part->instance()->aboutData() ? part->instance()->aboutData()->appName() : "" ) << endl;
  1872. KonqView *newView = 0;
  1873. KonqView *oldView = m_currentView;
  1874. if ( part )
  1875. {
  1876. newView = m_mapViews.find( static_cast<KParts::ReadOnlyPart *>( part ) ).data();
  1877. if ( newView->isPassiveMode() )
  1878. {
  1879. // Passive view. Don't connect anything, don't change m_currentView
  1880. // Another view will become the current view very soon
  1881. kdDebug(1202) << "KonqMainWindow::slotPartActivated: Passive mode - return" << endl;
  1882. return;
  1883. }
  1884. }
  1885. KParts::BrowserExtension *ext = 0;
  1886. if ( oldView )
  1887. {
  1888. ext = oldView->browserExtension();
  1889. if ( ext )
  1890. {
  1891. //kdDebug(1202) << "Disconnecting extension for view " << oldView << endl;
  1892. disconnectExtension( ext );
  1893. }
  1894. if ( oldView->part() )
  1895. {
  1896. TDEActionCollection *coll = oldView->part()->actionCollection();
  1897. if ( coll )
  1898. disconnectActionCollection( coll );
  1899. }
  1900. }
  1901. kdDebug(1202) << "KonqMainWindow::slotPartActivated: New current view " << newView << endl;
  1902. m_currentView = newView;
  1903. if ( !part )
  1904. {
  1905. kdDebug(1202) << "KonqMainWindow::slotPartActivated: No part activated - returning" << endl;
  1906. unplugViewModeActions();
  1907. createGUI( 0L );
  1908. KParts::MainWindow::setCaption( "" );
  1909. KParts::MainWindow::setIcon( kapp->icon());
  1910. return;
  1911. }
  1912. ext = m_currentView->browserExtension();
  1913. if ( ext )
  1914. {
  1915. connectExtension( ext );
  1916. }
  1917. else
  1918. {
  1919. kdDebug(1202) << "KonqMainWindow::slotPartActivated: No Browser Extension for the new part" << endl;
  1920. // Disable all browser-extension actions
  1921. KParts::BrowserExtension::ActionSlotMap * actionSlotMap = KParts::BrowserExtension::actionSlotMapPtr();
  1922. KParts::BrowserExtension::ActionSlotMap::ConstIterator it = actionSlotMap->begin();
  1923. KParts::BrowserExtension::ActionSlotMap::ConstIterator itEnd = actionSlotMap->end();
  1924. for ( ; it != itEnd ; ++it )
  1925. {
  1926. TDEAction * act = actionCollection()->action( static_cast<const char *>(it.key()) );
  1927. Q_ASSERT(act);
  1928. if (act)
  1929. act->setEnabled( false );
  1930. }
  1931. m_paCopyFiles->setEnabled( false );
  1932. m_paMoveFiles->setEnabled( false );
  1933. m_paNewDir->setEnabled( false );
  1934. }
  1935. createGUI( part );
  1936. TDEActionCollection *coll = m_currentView->part()->actionCollection();
  1937. if ( coll )
  1938. connectActionCollection( coll );
  1939. // View-dependent GUI
  1940. KParts::MainWindow::setCaption( m_currentView->caption() );
  1941. m_currentView->frame()->setTitle( m_currentView->caption() , 0L);
  1942. updateOpenWithActions();
  1943. updateLocalPropsActions();
  1944. updateViewActions(); // undo, lock, link and other view-dependent actions
  1945. if ( m_bViewModeToggled )
  1946. {
  1947. // if we just toggled the view mode via the view mode actions, then
  1948. // we don't need to do all the time-taking stuff below (Simon)
  1949. const TQString currentServiceDesktopEntryName = m_currentView->service()->desktopEntryName();
  1950. TQPtrListIterator<TDERadioAction> it( m_viewModeActions );
  1951. for (; it.current(); ++it ) {
  1952. if ( it.current()->name() == currentServiceDesktopEntryName ) {
  1953. it.current()->setChecked( true );
  1954. break;
  1955. }
  1956. }
  1957. const TQString currentServiceLibrary = viewModeActionKey( m_currentView->service() );
  1958. TQPtrListIterator<TDEAction> ittb( m_toolBarViewModeActions );
  1959. for (; ittb.current(); ++ittb ) {
  1960. KService::Ptr serv = KService::serviceByDesktopName( ittb.current()->name() );
  1961. if ( serv && viewModeActionKey( serv ) == currentServiceLibrary ) {
  1962. TDEToggleAction* ta = static_cast<TDEToggleAction*>( ittb.current() );
  1963. ta->setChecked( false );
  1964. TQString servicename = m_currentView->service()->genericName();
  1965. if (servicename.isEmpty())
  1966. servicename = m_currentView->service()->name();
  1967. ta->setText( servicename );
  1968. ta->setIcon( m_currentView->service()->icon() );
  1969. ta->setName( m_currentView->service()->desktopEntryName().ascii() ) ;
  1970. break;
  1971. }
  1972. }
  1973. }
  1974. else
  1975. {
  1976. updateViewModeActions();
  1977. }
  1978. m_bViewModeToggled = false;
  1979. m_pMenuNew->setEnabled( m_currentView->supportsServiceType( "inode/directory" ) );
  1980. m_currentView->frame()->statusbar()->updateActiveStatus();
  1981. if ( oldView && oldView->frame() )
  1982. oldView->frame()->statusbar()->updateActiveStatus();
  1983. //kdDebug(1202) << "KonqMainWindow::slotPartActivated: setting location bar url to "
  1984. // << m_currentView->locationBarURL() << " m_currentView=" << m_currentView << endl;
  1985. m_currentView->setLocationBarURL( m_currentView->locationBarURL() );
  1986. updateToolBarActions();
  1987. m_currentView->setActiveInstance();
  1988. }
  1989. void KonqMainWindow::insertChildView( KonqView *childView )
  1990. {
  1991. kdDebug(1202) << "KonqMainWindow::insertChildView " << childView << endl;
  1992. m_mapViews.insert( childView->part(), childView );
  1993. connect( childView, TQT_SIGNAL( viewCompleted( KonqView * ) ),
  1994. this, TQT_SLOT( slotViewCompleted( KonqView * ) ) );
  1995. if ( !m_pViewManager->isLoadingProfile() ) // see KonqViewManager::loadViewProfile
  1996. viewCountChanged();
  1997. emit viewAdded( childView );
  1998. }
  1999. // Called by KonqViewManager, internal
  2000. void KonqMainWindow::removeChildView( KonqView *childView )
  2001. {
  2002. kdDebug(1202) << "KonqMainWindow::removeChildView childView " << childView << endl;
  2003. disconnect( childView, TQT_SIGNAL( viewCompleted( KonqView * ) ),
  2004. this, TQT_SLOT( slotViewCompleted( KonqView * ) ) );
  2005. #ifndef NDEBUG
  2006. dumpViewList();
  2007. #endif
  2008. MapViews::Iterator it = m_mapViews.begin();
  2009. MapViews::Iterator end = m_mapViews.end();
  2010. // find it in the map - can't use the key since childView->part() might be 0L
  2011. kdDebug(1202) << "Searching map" << endl;
  2012. while ( it != end && it.data() != childView )
  2013. ++it;
  2014. kdDebug(1202) << "Verifying search results" << endl;
  2015. if ( it == m_mapViews.end() )
  2016. {
  2017. kdWarning(1202) << "KonqMainWindow::removeChildView childView " << childView << " not in map !" << endl;
  2018. return;
  2019. }
  2020. kdDebug(1202) << "Removing view " << childView << endl;
  2021. m_mapViews.remove( it );
  2022. kdDebug(1202) << "View " << childView << " removed from map" << endl;
  2023. viewCountChanged();
  2024. emit viewRemoved( childView );
  2025. #ifndef NDEBUG
  2026. dumpViewList();
  2027. #endif
  2028. // KonqViewManager takes care of m_currentView
  2029. }
  2030. void KonqMainWindow::viewCountChanged()
  2031. {
  2032. // This is called when the number of views changes.
  2033. kdDebug(1202) << "KonqMainWindow::viewCountChanged" << endl;
  2034. int lvc = linkableViewsCount();
  2035. m_paLinkView->setEnabled( lvc > 1 );
  2036. // Only one view (or one view + sidebar) -> make it/them unlinked
  2037. if ( lvc == 1 ) {
  2038. MapViews::Iterator it = m_mapViews.begin();
  2039. MapViews::Iterator end = m_mapViews.end();
  2040. for (; it != end; ++it )
  2041. it.data()->setLinkedView( false );
  2042. }
  2043. viewsChanged();
  2044. m_pViewManager->viewCountChanged();
  2045. }
  2046. void KonqMainWindow::viewsChanged()
  2047. {
  2048. // This is called when the number of views changes OR when
  2049. // the type of some view changes.
  2050. // Nothing here anymore, but don't cleanup, some might come back later.
  2051. updateViewActions(); // undo, lock, link and other view-dependent actions
  2052. }
  2053. KonqView * KonqMainWindow::childView( KParts::ReadOnlyPart *view )
  2054. {
  2055. MapViews::ConstIterator it = m_mapViews.find( view );
  2056. if ( it != m_mapViews.end() )
  2057. return it.data();
  2058. else
  2059. return 0L;
  2060. }
  2061. KonqView * KonqMainWindow::childView( KParts::ReadOnlyPart *callingPart, const TQString &name, KParts::BrowserHostExtension **hostExtension, KParts::ReadOnlyPart **part )
  2062. {
  2063. kdDebug() << "KonqMainWindow::childView this=" << this << " looking for " << name << endl;
  2064. MapViews::ConstIterator it = m_mapViews.begin();
  2065. MapViews::ConstIterator end = m_mapViews.end();
  2066. for (; it != end; ++it )
  2067. {
  2068. KonqView* view = it.data();
  2069. TQString viewName = view->viewName();
  2070. kdDebug() << " - viewName=" << viewName << " "
  2071. << "frame names:" << view->frameNames().join( "," ) << endl;
  2072. // First look for a hostextension containing this frame name
  2073. KParts::BrowserHostExtension *ext = KParts::BrowserHostExtension::childObject( view->part() );
  2074. if ( ext )
  2075. {
  2076. ext = ext->findFrameParent(callingPart, name);
  2077. kdDebug() << "BrowserHostExtension found part " << ext << endl;
  2078. if (!ext)
  2079. continue; // Don't use this window
  2080. }
  2081. if ( !viewName.isEmpty() && viewName == name )
  2082. {
  2083. kdDebug() << "found existing view by name: " << view << endl;
  2084. if ( hostExtension )
  2085. *hostExtension = 0;
  2086. if ( part )
  2087. *part = view->part();
  2088. return view;
  2089. }
  2090. // KParts::BrowserHostExtension* ext = KonqView::hostExtension( view->part(), name );
  2091. if ( ext )
  2092. {
  2093. TQPtrList<KParts::ReadOnlyPart> frames = ext->frames();
  2094. TQPtrListIterator<KParts::ReadOnlyPart> frameIt( frames );
  2095. for ( ; frameIt.current() ; ++frameIt )
  2096. {
  2097. if ( frameIt.current()->name() == name )
  2098. {
  2099. kdDebug() << "found a frame of name " << name << " : " << frameIt.current() << endl;
  2100. if ( hostExtension )
  2101. *hostExtension = ext;
  2102. if ( part )
  2103. *part = frameIt.current();
  2104. return view;
  2105. }
  2106. }
  2107. }
  2108. }
  2109. return 0;
  2110. }
  2111. // static
  2112. KonqView * KonqMainWindow::findChildView( KParts::ReadOnlyPart *callingPart, const TQString &name, KonqMainWindow **mainWindow, KParts::BrowserHostExtension **hostExtension, KParts::ReadOnlyPart **part )
  2113. {
  2114. if ( !s_lstViews )
  2115. return 0;
  2116. TQPtrListIterator<KonqMainWindow> it( *s_lstViews );
  2117. for (; it.current(); ++it )
  2118. {
  2119. KonqView *res = it.current()->childView( callingPart, name, hostExtension, part );
  2120. if ( res )
  2121. {
  2122. if ( mainWindow )
  2123. *mainWindow = it.current();
  2124. return res;
  2125. }
  2126. }
  2127. return 0;
  2128. }
  2129. int KonqMainWindow::activeViewsCount() const
  2130. {
  2131. int res = 0;
  2132. MapViews::ConstIterator it = m_mapViews.begin();
  2133. MapViews::ConstIterator end = m_mapViews.end();
  2134. for (; it != end; ++it )
  2135. if ( !it.data()->isPassiveMode() )
  2136. ++res;
  2137. return res;
  2138. }
  2139. int KonqMainWindow::linkableViewsCount() const
  2140. {
  2141. int res = 0;
  2142. MapViews::ConstIterator it = m_mapViews.begin();
  2143. MapViews::ConstIterator end = m_mapViews.end();
  2144. for (; it != end; ++it )
  2145. if ( !it.data()->isFollowActive() )
  2146. ++res;
  2147. return res;
  2148. }
  2149. int KonqMainWindow::mainViewsCount() const
  2150. {
  2151. int res = 0;
  2152. MapViews::ConstIterator it = m_mapViews.begin();
  2153. MapViews::ConstIterator end = m_mapViews.end();
  2154. for (; it != end; ++it )
  2155. if ( !it.data()->isPassiveMode() && !it.data()->isToggleView() )
  2156. {
  2157. //kdDebug(1202) << "KonqMainWindow::mainViewsCount " << res << " " << it.data() << " " << it.data()->part()->widget() << endl;
  2158. ++res;
  2159. }
  2160. return res;
  2161. }
  2162. KParts::ReadOnlyPart * KonqMainWindow::currentPart() const
  2163. {
  2164. /// ### This is currently unused. Check in the final version (!) if still unused.
  2165. if ( m_currentView )
  2166. return m_currentView->part();
  2167. else
  2168. return 0L;
  2169. }
  2170. void KonqMainWindow::customEvent( TQCustomEvent *event )
  2171. {
  2172. KParts::MainWindow::customEvent( event );
  2173. if ( KonqFileSelectionEvent::test( event ) ||
  2174. KonqFileMouseOverEvent::test( event ) )
  2175. {
  2176. // Forward the event to all views
  2177. MapViews::ConstIterator it = m_mapViews.begin();
  2178. MapViews::ConstIterator end = m_mapViews.end();
  2179. for (; it != end; ++it )
  2180. TQApplication::sendEvent( (*it)->part(), event );
  2181. return;
  2182. }
  2183. if ( KParts::OpenURLEvent::test( event ) )
  2184. {
  2185. KParts::OpenURLEvent * ev = static_cast<KParts::OpenURLEvent*>(event);
  2186. KonqView * senderChildView = childView(ev->part());
  2187. // Enable/disable local properties actions if current view
  2188. if ( senderChildView == m_currentView )
  2189. updateLocalPropsActions();
  2190. // Forward the event to all views
  2191. MapViews::ConstIterator it = m_mapViews.begin();
  2192. MapViews::ConstIterator end = m_mapViews.end();
  2193. for (; it != end; ++it )
  2194. {
  2195. // Don't resend to sender
  2196. if (it.key() != ev->part())
  2197. {
  2198. //kdDebug(1202) << "Sending event to view " << it.key()->className() << endl;
  2199. TQApplication::sendEvent( it.key(), event );
  2200. }
  2201. }
  2202. }
  2203. }
  2204. void KonqMainWindow::updateLocalPropsActions()
  2205. {
  2206. bool canWrite = false;
  2207. if ( m_currentView && m_currentView->url().isLocalFile() )
  2208. {
  2209. // Can we write ?
  2210. TQFileInfo info( m_currentView->url().path() );
  2211. canWrite = info.isDir() && info.isWritable();
  2212. }
  2213. m_paSaveViewPropertiesLocally->setEnabled( canWrite );
  2214. m_paRemoveLocalProperties->setEnabled( canWrite );
  2215. }
  2216. void KonqMainWindow::slotURLEntered( const TQString &text, int state )
  2217. {
  2218. if ( m_bURLEnterLock || text.isEmpty() )
  2219. return;
  2220. m_bURLEnterLock = true;
  2221. if (state & ControlButton || state & AltButton)
  2222. {
  2223. m_combo->setURL( m_currentView ? m_currentView->url().prettyURL() : TQString::null );
  2224. openFilteredURL( text.stripWhiteSpace(), true );
  2225. }
  2226. else
  2227. openFilteredURL( text.stripWhiteSpace() );
  2228. m_bURLEnterLock = false;
  2229. }
  2230. void KonqMainWindow::slotFileNewAboutToShow()
  2231. {
  2232. // As requested by KNewMenu :
  2233. m_pMenuNew->slotCheckUpToDate();
  2234. // And set the files that the menu apply on :
  2235. m_pMenuNew->setPopupFiles( KURL( m_currentView->url().url() ) );
  2236. }
  2237. void KonqMainWindow::slotSplitViewHorizontal()
  2238. {
  2239. KonqView * newView = m_pViewManager->splitView( Qt::Horizontal );
  2240. if (newView == 0L) return;
  2241. newView->openURL( m_currentView->url(), m_currentView->locationBarURL() );
  2242. }
  2243. void KonqMainWindow::slotSplitViewVertical()
  2244. {
  2245. KonqView * newView = m_pViewManager->splitView( Qt::Vertical );
  2246. if (newView == 0L) return;
  2247. newView->openURL( m_currentView->url(), m_currentView->locationBarURL() );
  2248. }
  2249. void KonqMainWindow::slotAddTab()
  2250. {
  2251. KonqView* newView = m_pViewManager->addTab(TQString("text/html"), // this is what about:blank will use anyway
  2252. TQString::null,
  2253. false,
  2254. KonqSettings::openAfterCurrentPage());
  2255. if (newView == 0L) return;
  2256. openURL( newView, KURL("about:blank"),TQString::null);
  2257. m_pViewManager->showTab( newView );
  2258. focusLocationBar();
  2259. m_pWorkingTab = 0L;
  2260. }
  2261. void KonqMainWindow::slotDuplicateTab()
  2262. {
  2263. m_pViewManager->duplicateTab( 0, KonqSettings::openAfterCurrentPage() );
  2264. }
  2265. void KonqMainWindow::slotDuplicateTabPopup()
  2266. {
  2267. m_pViewManager->duplicateTab( m_pWorkingTab, KonqSettings::openAfterCurrentPage() );
  2268. }
  2269. void KonqMainWindow::slotBreakOffTab()
  2270. {
  2271. if (m_currentView && m_currentView->part() &&
  2272. (m_currentView->part()->metaObject()->findProperty("modified") != -1) ) {
  2273. TQVariant prop = m_currentView->part()->property("modified");
  2274. if (prop.isValid() && prop.toBool())
  2275. if ( KMessageBox::warningContinueCancel( this,
  2276. i18n("This tab contains changes that have not been submitted.\nDetaching the tab will discard these changes."),
  2277. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"tab_breakoff"), "discardchangesdetach") != KMessageBox::Continue )
  2278. return;
  2279. }
  2280. m_pViewManager->breakOffTab();
  2281. updateViewActions();
  2282. }
  2283. void KonqMainWindow::slotBreakOffTabPopup()
  2284. {
  2285. KonqView* originalView = m_currentView;
  2286. KonqView *view = m_pWorkingTab->activeChildView();
  2287. if (view && view->part() && (view->part()->metaObject()->findProperty("modified") != -1) ) {
  2288. TQVariant prop = view->part()->property("modified");
  2289. if (prop.isValid() && prop.toBool()) {
  2290. m_pViewManager->showTab( view );
  2291. if ( KMessageBox::warningContinueCancel( this,
  2292. i18n("This tab contains changes that have not been submitted.\nDetaching the tab will discard these changes."),
  2293. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"tab_breakoff"), "discardchangesdetach") != KMessageBox::Continue )
  2294. {
  2295. m_pViewManager->showTab( originalView );
  2296. return;
  2297. }
  2298. }
  2299. }
  2300. m_pViewManager->showTab( originalView );
  2301. //Can't do this safely here as the tabbar may disappear and we're
  2302. //hanging off here.
  2303. TQTimer::singleShot(0, this, TQT_SLOT( slotBreakOffTabPopupDelayed() ) );
  2304. }
  2305. void KonqMainWindow::slotBreakOffTabPopupDelayed()
  2306. {
  2307. m_pViewManager->breakOffTab( m_pWorkingTab );
  2308. updateViewActions();
  2309. }
  2310. void KonqMainWindow::slotPopupNewWindow()
  2311. {
  2312. kdDebug(1202) << "KonqMainWindow::slotPopupNewWindow()" << endl;
  2313. KFileItemListIterator it ( popupItems );
  2314. for ( ; it.current(); ++it )
  2315. {
  2316. KonqMisc::createNewWindow( (*it)->url(), popupUrlArgs );
  2317. }
  2318. }
  2319. void KonqMainWindow::slotPopupThisWindow()
  2320. {
  2321. kdDebug(1202) << "KonqMainWindow::slotPopupThisWindow()" << endl;
  2322. openURL( 0L, popupItems.getFirst()->url() );
  2323. }
  2324. void KonqMainWindow::slotPopupNewTabAtFront()
  2325. {
  2326. TDEConfig *config = TDEGlobal::config();
  2327. TDEConfigGroupSaver cs( config, TQString::fromLatin1("FMSettings") );
  2328. bool openAfterCurrentPage = config->readBoolEntry( "OpenAfterCurrentPage", false );
  2329. popupNewTab(true, openAfterCurrentPage);
  2330. }
  2331. void KonqMainWindow::slotPopupNewTab()
  2332. {
  2333. bool openAfterCurrentPage = KonqSettings::openAfterCurrentPage();
  2334. bool newTabsInFront = KonqSettings::newTabsInFront();
  2335. if (TDEApplication::keyboardMouseState() & TQt::ShiftButton)
  2336. newTabsInFront = !newTabsInFront;
  2337. popupNewTab(newTabsInFront, openAfterCurrentPage);
  2338. }
  2339. void KonqMainWindow::slotPopupNewTabRight()
  2340. {
  2341. bool newTabsInFront = KonqSettings::newTabsInFront();
  2342. if (TDEApplication::keyboardMouseState() & ShiftButton)
  2343. newTabsInFront = !newTabsInFront;
  2344. popupNewTab(newTabsInFront, false);
  2345. }
  2346. void KonqMainWindow::popupNewTab(bool infront, bool openAfterCurrentPage)
  2347. {
  2348. kdDebug(1202) << "KonqMainWindow::popupNewTab()" << endl;
  2349. KFileItemListIterator it ( popupItems );
  2350. KonqOpenURLRequest req;
  2351. req.newTab = true;
  2352. req.newTabInFront = false;
  2353. req.openAfterCurrentPage = openAfterCurrentPage;
  2354. req.args = popupUrlArgs;
  2355. for ( ; it.current(); ++it )
  2356. {
  2357. if ( infront && it.atLast() )
  2358. {
  2359. req.newTabInFront = true;
  2360. }
  2361. openURL( 0L, (*it)->url(), TQString::null, req );
  2362. }
  2363. }
  2364. void KonqMainWindow::openMultiURL( KURL::List url )
  2365. {
  2366. KURL::List::ConstIterator it = url.begin();
  2367. KURL::List::ConstIterator end = url.end();
  2368. for (; it != end; ++it )
  2369. {
  2370. KonqView* newView = m_pViewManager->addTab();
  2371. Q_ASSERT( newView );
  2372. if (newView == 0L) continue;
  2373. openURL( newView, *it,TQString::null);
  2374. m_pViewManager->showTab( newView );
  2375. focusLocationBar();
  2376. m_pWorkingTab = 0L;
  2377. }
  2378. }
  2379. void KonqMainWindow::slotRemoveView()
  2380. {
  2381. if (m_currentView && m_currentView->part() &&
  2382. (m_currentView->part()->metaObject()->findProperty("modified") != -1) ) {
  2383. TQVariant prop = m_currentView->part()->property("modified");
  2384. if (prop.isValid() && prop.toBool())
  2385. if ( KMessageBox::warningContinueCancel( this,
  2386. i18n("This view contains changes that have not been submitted.\nClosing the view will discard these changes."),
  2387. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"view_remove"), "discardchangesclose") != KMessageBox::Continue )
  2388. return;
  2389. }
  2390. // takes care of choosing the new active view
  2391. m_pViewManager->removeView( m_currentView );
  2392. }
  2393. void KonqMainWindow::slotRemoveTab()
  2394. {
  2395. if (m_currentView && m_currentView->part() &&
  2396. (m_currentView->part()->metaObject()->findProperty("modified") != -1) ) {
  2397. TQVariant prop = m_currentView->part()->property("modified");
  2398. if (prop.isValid() && prop.toBool())
  2399. if ( KMessageBox::warningContinueCancel( this,
  2400. i18n("This tab contains changes that have not been submitted.\nClosing the tab will discard these changes."),
  2401. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"tab_remove"), "discardchangesclose") != KMessageBox::Continue )
  2402. return;
  2403. }
  2404. m_pViewManager->removeTab();
  2405. }
  2406. void KonqMainWindow::slotRemoveTabPopup()
  2407. {
  2408. KonqView *originalView = m_currentView;
  2409. KonqView *view = m_pWorkingTab->activeChildView();
  2410. if (view && view->part() && (view->part()->metaObject()->findProperty("modified") != -1) ) {
  2411. TQVariant prop = view->part()->property("modified");
  2412. if (prop.isValid() && prop.toBool()) {
  2413. m_pViewManager->showTab( view );
  2414. if ( KMessageBox::warningContinueCancel( this,
  2415. i18n("This tab contains changes that have not been submitted.\nClosing the tab will discard these changes."),
  2416. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"tab_remove"), "discardchangesclose") != KMessageBox::Continue )
  2417. {
  2418. m_pViewManager->showTab( originalView );
  2419. return;
  2420. }
  2421. }
  2422. m_pViewManager->showTab( originalView );
  2423. }
  2424. //Can't do immediately - may kill the tabbar, and we're in an event path down from it
  2425. TQTimer::singleShot( 0, this, TQT_SLOT( slotRemoveTabPopupDelayed() ) );
  2426. }
  2427. void KonqMainWindow::slotRemoveTabPopupDelayed()
  2428. {
  2429. m_pViewManager->removeTab( m_pWorkingTab );
  2430. }
  2431. void KonqMainWindow::slotRemoveOtherTabsPopup()
  2432. {
  2433. if ( KMessageBox::warningContinueCancel( this,
  2434. i18n("Do you really want to close all other tabs?"),
  2435. i18n("Close Other Tabs Confirmation"), KGuiItem(i18n("Close &Other Tabs"),"tab_remove_other"),
  2436. "CloseOtherTabConfirm") != KMessageBox::Continue )
  2437. return;
  2438. KonqView *originalView = m_currentView;
  2439. MapViews::ConstIterator it = m_mapViews.begin();
  2440. MapViews::ConstIterator end = m_mapViews.end();
  2441. for (; it != end; ++it ) {
  2442. KonqView *view = it.data();
  2443. if ( view != originalView && view && view->part() && (view->part()->metaObject()->findProperty("modified") != -1) ) {
  2444. TQVariant prop = view->part()->property("modified");
  2445. if (prop.isValid() && prop.toBool()) {
  2446. m_pViewManager->showTab( view );
  2447. if ( KMessageBox::warningContinueCancel( this,
  2448. i18n("This tab contains changes that have not been submitted.\nClosing other tabs will discard these changes."),
  2449. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"tab_remove"), "discardchangescloseother") != KMessageBox::Continue )
  2450. {
  2451. m_pViewManager->showTab( originalView );
  2452. return;
  2453. }
  2454. }
  2455. }
  2456. }
  2457. m_pViewManager->showTab( originalView );
  2458. //Can't do immediately - kills the tabbar, and we're in an event path down from it
  2459. TQTimer::singleShot( 0, this, TQT_SLOT( slotRemoveOtherTabsPopupDelayed() ) );
  2460. }
  2461. void KonqMainWindow::slotRemoveOtherTabsPopupDelayed()
  2462. {
  2463. m_pViewManager->removeOtherTabs( m_pWorkingTab );
  2464. updateViewActions();
  2465. }
  2466. void KonqMainWindow::slotReloadAllTabs()
  2467. {
  2468. KonqView *originalView = m_currentView;
  2469. MapViews::ConstIterator it = m_mapViews.begin();
  2470. MapViews::ConstIterator end = m_mapViews.end();
  2471. for (; it != end; ++it ) {
  2472. KonqView *view = it.data();
  2473. if (view && view->part() && (view->part()->metaObject()->findProperty("modified") != -1) ) {
  2474. TQVariant prop = view->part()->property("modified");
  2475. if (prop.isValid() && prop.toBool()) {
  2476. m_pViewManager->showTab( view );
  2477. if ( KMessageBox::warningContinueCancel( this,
  2478. i18n("This tab contains changes that have not been submitted.\nReloading all tabs will discard these changes."),
  2479. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"reload"), "discardchangesreload") != KMessageBox::Continue )
  2480. {
  2481. m_pViewManager->showTab( originalView );
  2482. return;
  2483. }
  2484. }
  2485. }
  2486. }
  2487. m_pViewManager->showTab( originalView );
  2488. m_pViewManager->reloadAllTabs();
  2489. updateViewActions();
  2490. }
  2491. void KonqMainWindow::slotActivateNextTab()
  2492. {
  2493. m_pViewManager->activateNextTab();
  2494. }
  2495. void KonqMainWindow::slotActivatePrevTab()
  2496. {
  2497. m_pViewManager->activatePrevTab();
  2498. }
  2499. void KonqMainWindow::slotActivateTab()
  2500. {
  2501. m_pViewManager->activateTab( TQString( TQT_TQOBJECT_CONST(sender())->name() ).right( 2 ).toInt() -1 );
  2502. }
  2503. void KonqMainWindow::slotDumpDebugInfo()
  2504. {
  2505. #ifndef NDEBUG
  2506. dumpViewList();
  2507. m_pViewManager->printFullHierarchy( 0L );
  2508. #endif
  2509. }
  2510. void KonqMainWindow::slotSaveViewPropertiesLocally()
  2511. {
  2512. m_bSaveViewPropertiesLocally = !m_bSaveViewPropertiesLocally;
  2513. // And this is a main-view setting, so save it
  2514. KonqSettings::setSaveViewPropertiesLocally( m_bSaveViewPropertiesLocally );
  2515. KonqSettings::writeConfig();
  2516. // Now tell the views
  2517. MapViews::ConstIterator it = m_mapViews.begin();
  2518. MapViews::ConstIterator end = m_mapViews.end();
  2519. for (; it != end; ++it )
  2520. (*it)->callExtensionBoolMethod( "setSaveViewPropertiesLocally(bool)", m_bSaveViewPropertiesLocally );
  2521. }
  2522. void KonqMainWindow::slotRemoveLocalProperties()
  2523. {
  2524. assert( m_currentView );
  2525. KURL u ( m_currentView->url() );
  2526. u.addPath(".directory");
  2527. if ( u.isLocalFile() )
  2528. {
  2529. TQFile f( u.path() );
  2530. if ( f.open(IO_ReadWrite) )
  2531. {
  2532. f.close();
  2533. KSimpleConfig config( u.path() );
  2534. config.deleteGroup( "URL properties" ); // Bye bye
  2535. config.sync();
  2536. // TODO: Notify the view...
  2537. // Or the hard way: (and hoping it doesn't cache the values!)
  2538. slotReload();
  2539. } else
  2540. {
  2541. Q_ASSERT( TQFile::exists(u.path()) ); // The action shouldn't be enabled, otherwise.
  2542. KMessageBox::sorry( this, i18n("No permissions to write to %1").arg(u.path()) );
  2543. }
  2544. }
  2545. }
  2546. bool KonqMainWindow::askForTarget(const TQString& text, KURL& url)
  2547. {
  2548. const KURL initialUrl = (viewCount()==2) ? otherView(m_currentView)->url() : m_currentView->url();
  2549. TQString label = text.arg( m_currentView->url().pathOrURL() );
  2550. KURLRequesterDlg dlg(initialUrl.pathOrURL(), label, this, "urlrequester", true);
  2551. dlg.setCaption(i18n("Enter Target"));
  2552. dlg.urlRequester()->setMode( KFile::File | KFile::ExistingOnly | KFile::Directory );
  2553. if (dlg.exec())
  2554. {
  2555. url = dlg.selectedURL();
  2556. if ( url.isValid() )
  2557. return true;
  2558. else
  2559. {
  2560. KMessageBox::error( this, i18n("<qt><b>%1</b> is not valid</qt>").arg(url.url()));
  2561. return false;
  2562. }
  2563. }
  2564. return false;
  2565. }
  2566. void KonqMainWindow::slotRequesterClicked( KURLRequester *req )
  2567. {
  2568. req->fileDialog()->setMode(KFile::Directory|KFile::ExistingOnly);
  2569. }
  2570. void KonqMainWindow::slotCopyFiles()
  2571. {
  2572. //kdDebug(1202) << "KonqMainWindow::slotCopyFiles()" << endl;
  2573. KURL dest;
  2574. if (!askForTarget(i18n("Copy selected files from %1 to:"),dest))
  2575. return;
  2576. KonqOperations::copy(this,KonqOperations::COPY,currentURLs(),dest);
  2577. }
  2578. void KonqMainWindow::slotMoveFiles()
  2579. {
  2580. //kdDebug(1202) << "KonqMainWindow::slotMoveFiles()" << endl;
  2581. KURL dest;
  2582. if (!askForTarget(i18n("Move selected files from %1 to:"),dest))
  2583. return;
  2584. KonqOperations::copy(this,KonqOperations::MOVE,currentURLs(),dest);
  2585. }
  2586. void KonqMainWindow::slotNewDir()
  2587. {
  2588. Q_ASSERT( m_currentView );
  2589. if ( m_currentView )
  2590. KonqOperations::newDir(this, m_currentView->url());
  2591. }
  2592. KURL::List KonqMainWindow::currentURLs() const
  2593. {
  2594. KURL::List urls;
  2595. if ( m_currentView )
  2596. {
  2597. urls.append( m_currentView->url() );
  2598. if ( m_currentView->part()->inherits("KonqDirPart") )
  2599. {
  2600. KFileItemList tmpList= static_cast<KonqDirPart *>(m_currentView->part())->selectedFileItems();
  2601. KFileItem *item=tmpList.first();
  2602. if (item) // Return list of selected items only if we have a selection
  2603. {
  2604. urls.clear();
  2605. for (; item!=0; item=tmpList.next())
  2606. urls.append(item->url());
  2607. }
  2608. }
  2609. }
  2610. return urls;
  2611. }
  2612. // Only valid if there are one or two views
  2613. KonqView * KonqMainWindow::otherView( KonqView * view ) const
  2614. {
  2615. assert( viewCount() <= 2 );
  2616. MapViews::ConstIterator it = m_mapViews.begin();
  2617. if ( (*it) == view )
  2618. ++it;
  2619. if ( it != m_mapViews.end() )
  2620. return (*it);
  2621. return 0L;
  2622. }
  2623. void KonqMainWindow::slotSaveViewProfile()
  2624. {
  2625. #if 0
  2626. if ( m_pViewManager->currentProfile().isEmpty() )
  2627. {
  2628. // The action should be disabled...........
  2629. kdWarning(1202) << "No known profile. Use the Save Profile dialog box" << endl;
  2630. } else {
  2631. m_pViewManager->saveViewProfile( m_pViewManager->currentProfile(),
  2632. m_pViewManager->currentProfileText(),
  2633. false /* URLs */, true /* size */ );
  2634. }
  2635. #endif
  2636. m_pViewManager->showProfileDlg( m_pViewManager->currentProfile() );
  2637. }
  2638. void KonqMainWindow::slotUpAboutToShow()
  2639. {
  2640. TQPopupMenu *popup = m_paUp->popupMenu();
  2641. popup->clear();
  2642. uint i = 0;
  2643. // Use the location bar URL, because in case we display a index.html
  2644. // we want to go up from the dir, not from the index.html
  2645. KURL u( m_currentView->locationBarURL() );
  2646. u = u.upURL();
  2647. while ( u.hasPath() )
  2648. {
  2649. popup->insertItem( KonqPixmapProvider::self()->pixmapFor( u.url() ),
  2650. u.pathOrURL() );
  2651. if ( u.path() == "/" )
  2652. break;
  2653. if ( ++i > 10 )
  2654. break;
  2655. u = u.upURL();
  2656. }
  2657. }
  2658. void KonqMainWindow::slotUp(TDEAction::ActivationReason, TQt::ButtonState state)
  2659. {
  2660. m_goState = state;
  2661. TQTimer::singleShot( 0, this, TQT_SLOT( slotUpDelayed() ) );
  2662. }
  2663. void KonqMainWindow::slotUp()
  2664. {
  2665. m_goState = Qt::LeftButton;
  2666. TQTimer::singleShot( 0, this, TQT_SLOT( slotUpDelayed() ) );
  2667. }
  2668. void KonqMainWindow::slotUpDelayed()
  2669. {
  2670. KonqOpenURLRequest req;
  2671. req.newTab = true;
  2672. req.openAfterCurrentPage = KonqSettings::openAfterCurrentPage();
  2673. req.newTabInFront = KonqSettings::newTabsInFront();
  2674. if (m_goState & TQt::ShiftButton)
  2675. req.newTabInFront = !req.newTabInFront;
  2676. const TQString& url = m_currentView->upURL().url();
  2677. if(m_goState & TQt::ControlButton)
  2678. openFilteredURL(url, req );
  2679. else if(m_goState & Qt::MidButton)
  2680. {
  2681. if(KonqSettings::mmbOpensTab())
  2682. openFilteredURL( url, req);
  2683. else
  2684. KonqMisc::createNewWindow( url );
  2685. }
  2686. else
  2687. openFilteredURL( url, false );
  2688. m_goState = Qt::LeftButton;
  2689. }
  2690. void KonqMainWindow::slotUpActivated( int id )
  2691. {
  2692. KURL u( m_currentView->locationBarURL() );
  2693. kdDebug(1202) << "slotUpActivated. Start URL is " << u << endl;
  2694. for ( int i = 0 ; i < m_paUp->popupMenu()->indexOf( id ) + 1 ; i ++ )
  2695. u = u.upURL();
  2696. openURL( 0L, u );
  2697. }
  2698. void KonqMainWindow::slotGoMenuAboutToShow()
  2699. {
  2700. kdDebug(1202) << "KonqMainWindow::slotGoMenuAboutToShow" << endl;
  2701. if ( m_paHistory && m_currentView ) // (maybe this is before initialisation)
  2702. m_paHistory->fillGoMenu( m_currentView->history() );
  2703. }
  2704. void KonqMainWindow::slotGoHistoryActivated( int steps )
  2705. {
  2706. slotGoHistoryActivated( steps, Qt::LeftButton );
  2707. }
  2708. void KonqMainWindow::slotGoHistoryActivated( int steps, TQt::ButtonState state )
  2709. {
  2710. kdDebug() <<"slotGoHistoryActivated( "<<steps<<", "<<state<<" )"<<endl;
  2711. if (!m_goBuffer)
  2712. {
  2713. // Only start 1 timer.
  2714. m_goBuffer = steps;
  2715. m_goState = state;
  2716. TQTimer::singleShot( 0, this, TQT_SLOT(slotGoHistoryDelayed()));
  2717. }
  2718. }
  2719. void KonqMainWindow::slotGoHistoryDelayed()
  2720. {
  2721. if (!m_currentView) return;
  2722. bool openAfterCurrentPage = KonqSettings::openAfterCurrentPage();
  2723. bool mmbOpensTab = KonqSettings::mmbOpensTab();
  2724. bool inFront = KonqSettings::newTabsInFront();
  2725. if(m_goState & TQt::ShiftButton)
  2726. inFront = !inFront;
  2727. if(m_goState & TQt::ControlButton)
  2728. {
  2729. KonqView * newView = m_pViewManager->addTabFromHistory( m_goBuffer, openAfterCurrentPage );
  2730. if (newView && inFront)
  2731. m_pViewManager->showTab( newView );
  2732. }
  2733. else if(m_goState & Qt::MidButton)
  2734. {
  2735. if(mmbOpensTab)
  2736. {
  2737. KonqView * newView = m_pViewManager->addTabFromHistory( m_goBuffer, openAfterCurrentPage );
  2738. if (newView && inFront)
  2739. m_pViewManager->showTab( newView );
  2740. }
  2741. else
  2742. KonqMisc::newWindowFromHistory(this->currentView(), m_goBuffer);
  2743. }
  2744. else
  2745. {
  2746. m_currentView->go( m_goBuffer );
  2747. makeViewsFollow(m_currentView->url(), KParts::URLArgs(),m_currentView->serviceType(),m_currentView);
  2748. }
  2749. m_goBuffer = 0;
  2750. m_goState = Qt::LeftButton;
  2751. }
  2752. void KonqMainWindow::slotBackAboutToShow()
  2753. {
  2754. m_paBack->popupMenu()->clear();
  2755. if ( m_currentView )
  2756. KonqBidiHistoryAction::fillHistoryPopup( m_currentView->history(), m_paBack->popupMenu(), true, false );
  2757. }
  2758. void KonqMainWindow::slotBack()
  2759. {
  2760. slotGoHistoryActivated(-1);
  2761. }
  2762. void KonqMainWindow::slotBack(TDEAction::ActivationReason, TQt::ButtonState state)
  2763. {
  2764. slotGoHistoryActivated( -1, state );
  2765. }
  2766. void KonqMainWindow::slotBackActivated( int id )
  2767. {
  2768. slotGoHistoryActivated( -(m_paBack->popupMenu()->indexOf( id ) + 1), m_paBack->popupMenu()->state());
  2769. }
  2770. void KonqMainWindow::slotForwardAboutToShow()
  2771. {
  2772. m_paForward->popupMenu()->clear();
  2773. if ( m_currentView )
  2774. KonqBidiHistoryAction::fillHistoryPopup( m_currentView->history(), m_paForward->popupMenu(), false, true );
  2775. }
  2776. void KonqMainWindow::slotForward()
  2777. {
  2778. slotGoHistoryActivated( 1 );
  2779. }
  2780. void KonqMainWindow::slotForward(TDEAction::ActivationReason, TQt::ButtonState state)
  2781. {
  2782. slotGoHistoryActivated( 1, state );
  2783. }
  2784. void KonqMainWindow::slotForwardActivated( int id )
  2785. {
  2786. slotGoHistoryActivated( m_paForward->popupMenu()->indexOf( id ) + 1, m_paForward->popupMenu()->state() );
  2787. }
  2788. void KonqMainWindow::initCombo()
  2789. {
  2790. m_combo = new KonqCombo( 0L, "history combo");
  2791. m_combo->init( s_pCompletion );
  2792. connect( m_combo, TQT_SIGNAL(activated(const TQString&,int)),
  2793. this, TQT_SLOT(slotURLEntered(const TQString&,int)) );
  2794. connect( m_combo, TQT_SIGNAL(showPageSecurity()),
  2795. this, TQT_SLOT(showPageSecurity()) );
  2796. m_pURLCompletion = new KURLCompletion();
  2797. m_pURLCompletion->setCompletionMode( s_pCompletion->completionMode() );
  2798. // This only turns completion off. ~ is still there in the result
  2799. // We do want completion of user names, right?
  2800. //m_pURLCompletion->setReplaceHome( false ); // Leave ~ alone! Will be taken care of by filters!!
  2801. connect( m_combo, TQT_SIGNAL(completionModeChanged(TDEGlobalSettings::Completion)),
  2802. TQT_SLOT( slotCompletionModeChanged( TDEGlobalSettings::Completion )));
  2803. connect( m_combo, TQT_SIGNAL( completion( const TQString& )),
  2804. TQT_SLOT( slotMakeCompletion( const TQString& )));
  2805. connect( m_combo, TQT_SIGNAL( substringCompletion( const TQString& )),
  2806. TQT_SLOT( slotSubstringcompletion( const TQString& )));
  2807. connect( m_combo, TQT_SIGNAL( textRotation( TDECompletionBase::KeyBindingType) ),
  2808. TQT_SLOT( slotRotation( TDECompletionBase::KeyBindingType )));
  2809. connect( m_combo, TQT_SIGNAL( cleared() ),
  2810. TQT_SLOT ( slotClearHistory() ) );
  2811. connect( m_pURLCompletion, TQT_SIGNAL( match(const TQString&) ),
  2812. TQT_SLOT( slotMatch(const TQString&) ));
  2813. m_combo->lineEdit()->installEventFilter(this);
  2814. static bool bookmarkCompletionInitialized = false;
  2815. if ( !bookmarkCompletionInitialized )
  2816. {
  2817. bookmarkCompletionInitialized = true;
  2818. DelayedInitializer *initializer = new DelayedInitializer( TQEvent::KeyPress, TQT_TQOBJECT(m_combo->lineEdit()) );
  2819. connect( initializer, TQT_SIGNAL( initialize() ), this, TQT_SLOT( bookmarksIntoCompletion() ) );
  2820. }
  2821. }
  2822. void KonqMainWindow::bookmarksIntoCompletion()
  2823. {
  2824. // add all bookmarks to the completion list for easy access
  2825. bookmarksIntoCompletion( KonqBookmarkManager::self()->root() );
  2826. }
  2827. // the user changed the completion mode in the combo
  2828. void KonqMainWindow::slotCompletionModeChanged( TDEGlobalSettings::Completion m )
  2829. {
  2830. s_pCompletion->setCompletionMode( m );
  2831. KonqSettings::setSettingsCompletionMode( (int)m_combo->completionMode() );
  2832. KonqSettings::writeConfig();
  2833. // tell the other windows too (only this instance currently)
  2834. KonqMainWindow *window = s_lstViews->first();
  2835. while ( window ) {
  2836. if ( window->m_combo ) {
  2837. window->m_combo->setCompletionMode( m );
  2838. window->m_pURLCompletion->setCompletionMode( m );
  2839. }
  2840. window = s_lstViews->next();
  2841. }
  2842. }
  2843. // at first, try to find a completion in the current view, then use the global
  2844. // completion (history)
  2845. void KonqMainWindow::slotMakeCompletion( const TQString& text )
  2846. {
  2847. if( m_pURLCompletion )
  2848. {
  2849. m_urlCompletionStarted = true; // flag for slotMatch()
  2850. // kdDebug(1202) << "Local Completion object found!" << endl;
  2851. TQString completion = m_pURLCompletion->makeCompletion( text );
  2852. m_currentDir = TQString::null;
  2853. if ( completion.isNull() && !m_pURLCompletion->isRunning() )
  2854. {
  2855. // No match() signal will come from m_pURLCompletion
  2856. // ask the global one
  2857. // tell the static completion object about the current completion mode
  2858. completion = s_pCompletion->makeCompletion( text );
  2859. // some special handling necessary for CompletionPopup
  2860. if ( m_combo->completionMode() == TDEGlobalSettings::CompletionPopup ||
  2861. m_combo->completionMode() == TDEGlobalSettings::CompletionPopupAuto )
  2862. m_combo->setCompletedItems( historyPopupCompletionItems( text ) );
  2863. else if ( !completion.isNull() )
  2864. m_combo->setCompletedText( completion );
  2865. }
  2866. else
  2867. {
  2868. // To be continued in slotMatch()...
  2869. if( !m_pURLCompletion->dir().isEmpty() )
  2870. m_currentDir = m_pURLCompletion->dir();
  2871. }
  2872. }
  2873. // kdDebug(1202) << "Current dir: " << m_currentDir << " Current text: " << text << endl;
  2874. }
  2875. void KonqMainWindow::slotSubstringcompletion( const TQString& text )
  2876. {
  2877. bool filesFirst = currentURL().startsWith( "/" ) ||
  2878. currentURL().startsWith( "file:/" );
  2879. TQStringList items;
  2880. if ( filesFirst && m_pURLCompletion )
  2881. items = m_pURLCompletion->substringCompletion( text );
  2882. items += s_pCompletion->substringCompletion( text );
  2883. if ( !filesFirst && m_pURLCompletion )
  2884. items += m_pURLCompletion->substringCompletion( text );
  2885. m_combo->setCompletedItems( items );
  2886. }
  2887. void KonqMainWindow::slotRotation( TDECompletionBase::KeyBindingType type )
  2888. {
  2889. // Tell slotMatch() to do nothing
  2890. m_urlCompletionStarted = false;
  2891. bool prev = (type == TDECompletionBase::PrevCompletionMatch);
  2892. if ( prev || type == TDECompletionBase::NextCompletionMatch ) {
  2893. TQString completion = prev ? m_pURLCompletion->previousMatch() :
  2894. m_pURLCompletion->nextMatch();
  2895. if( completion.isNull() ) { // try the history TDECompletion object
  2896. completion = prev ? s_pCompletion->previousMatch() :
  2897. s_pCompletion->nextMatch();
  2898. }
  2899. if ( completion.isEmpty() || completion == m_combo->currentText() )
  2900. return;
  2901. m_combo->setCompletedText( completion );
  2902. }
  2903. }
  2904. // Handle match() from m_pURLCompletion
  2905. void KonqMainWindow::slotMatch( const TQString &match )
  2906. {
  2907. if ( match.isEmpty() ) // this case is handled directly
  2908. return;
  2909. // Check flag to avoid match() raised by rotation
  2910. if ( m_urlCompletionStarted ) {
  2911. m_urlCompletionStarted = false;
  2912. // some special handling necessary for CompletionPopup
  2913. if ( m_combo->completionMode() == TDEGlobalSettings::CompletionPopup ||
  2914. m_combo->completionMode() == TDEGlobalSettings::CompletionPopupAuto ) {
  2915. TQStringList items = m_pURLCompletion->allMatches();
  2916. items += historyPopupCompletionItems( m_combo->currentText() );
  2917. // items.sort(); // should we?
  2918. m_combo->setCompletedItems( items );
  2919. }
  2920. else if ( !match.isNull() )
  2921. m_combo->setCompletedText( match );
  2922. }
  2923. }
  2924. void KonqMainWindow::slotCtrlTabPressed()
  2925. {
  2926. KonqView * view = m_pViewManager->chooseNextView( m_currentView );
  2927. if ( view )
  2928. m_pViewManager->setActivePart( view->part() );
  2929. }
  2930. void KonqMainWindow::slotClearHistory()
  2931. {
  2932. KonqHistoryManager::kself()->emitClear();
  2933. }
  2934. void KonqMainWindow::slotClearComboHistory()
  2935. {
  2936. if (m_combo && m_combo->count())
  2937. m_combo->clearHistory();
  2938. }
  2939. bool KonqMainWindow::eventFilter(TQObject*obj,TQEvent *ev)
  2940. {
  2941. if ( ( ev->type()==TQEvent::FocusIn || ev->type()==TQEvent::FocusOut ) &&
  2942. m_combo && TQT_BASE_OBJECT(m_combo->lineEdit()) == TQT_BASE_OBJECT(obj) )
  2943. {
  2944. //kdDebug(1202) << "KonqMainWindow::eventFilter " << obj << " " << obj->className() << " " << obj->name() << endl;
  2945. TQFocusEvent * focusEv = TQT_TQFOCUSEVENT(ev);
  2946. if (focusEv->reason() == TQFocusEvent::Popup)
  2947. {
  2948. return KParts::MainWindow::eventFilter( obj, ev );
  2949. }
  2950. KParts::BrowserExtension * ext = 0;
  2951. if ( m_currentView )
  2952. ext = m_currentView->browserExtension();
  2953. TQStrList slotNames;
  2954. if (ext)
  2955. slotNames = ext->metaObject()->slotNames();
  2956. //for ( char * s = slotNames.first() ; s ; s = slotNames.next() )
  2957. //{
  2958. // kdDebug(1202) << "slotNames=" << s << endl;
  2959. //}
  2960. if (ev->type()==TQEvent::FocusIn)
  2961. {
  2962. //kdDebug(1202) << "ComboBox got the focus..." << endl;
  2963. if (m_bLocationBarConnected)
  2964. {
  2965. //kdDebug(1202) << "Was already connected..." << endl;
  2966. return KParts::MainWindow::eventFilter( obj, ev );
  2967. }
  2968. m_bLocationBarConnected = true;
  2969. // Workaround for Qt issue: usually, TQLineEdit reacts on Ctrl-D,
  2970. // but the duplicate_window action also has Ctrl-D as accel and
  2971. // prevents the lineedit from getting this event. IMHO the accel
  2972. // should be disabled in favor of the focus-widget.
  2973. TDEAction *duplicate = actionCollection()->action("duplicate_window");
  2974. if ( duplicate->shortcut() == TQKeySequence(CTRL+Key_D) )
  2975. duplicate->setEnabled( false );
  2976. if (slotNames.contains("cut()"))
  2977. disconnect( m_paCut, TQT_SIGNAL( activated() ), ext, TQT_SLOT( cut() ) );
  2978. if (slotNames.contains("copy()"))
  2979. disconnect( m_paCopy, TQT_SIGNAL( activated() ), ext, TQT_SLOT( copy() ) );
  2980. if (slotNames.contains("paste()"))
  2981. disconnect( m_paPaste, TQT_SIGNAL( activated() ), ext, TQT_SLOT( paste() ) );
  2982. if (slotNames.contains("del()"))
  2983. disconnect( m_paDelete, TQT_SIGNAL( activated() ), ext, TQT_SLOT( del() ) );
  2984. disconnect( m_paTrash, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ),
  2985. this, TQT_SLOT( slotTrashActivated( TDEAction::ActivationReason, TQt::ButtonState ) ) );
  2986. connect( m_paCut, TQT_SIGNAL( activated() ), m_combo->lineEdit(), TQT_SLOT( cut() ) );
  2987. connect( m_paCopy, TQT_SIGNAL( activated() ), m_combo->lineEdit(), TQT_SLOT( copy() ) );
  2988. connect( m_paPaste, TQT_SIGNAL( activated() ), m_combo->lineEdit(), TQT_SLOT( paste() ) );
  2989. connect( TQApplication::clipboard(), TQT_SIGNAL(dataChanged()), this, TQT_SLOT(slotClipboardDataChanged()) );
  2990. connect( m_combo->lineEdit(), TQT_SIGNAL(textChanged(const TQString &)), this, TQT_SLOT(slotCheckComboSelection()) );
  2991. connect( m_combo->lineEdit(), TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotCheckComboSelection()) );
  2992. m_paTrash->setEnabled(false);
  2993. m_paDelete->setEnabled(false);
  2994. slotClipboardDataChanged();
  2995. }
  2996. else if ( ev->type()==TQEvent::FocusOut)
  2997. {
  2998. //kdDebug(1202) << "ComboBox lost focus..." << endl;
  2999. if (!m_bLocationBarConnected)
  3000. {
  3001. //kdDebug(1202) << "Was already disconnected..." << endl;
  3002. return KParts::MainWindow::eventFilter( obj, ev );
  3003. }
  3004. m_bLocationBarConnected = false;
  3005. // see above in FocusIn for explanation
  3006. // we use new_window as reference, as it's always in the same state
  3007. // as duplicate_window
  3008. TDEAction *duplicate = actionCollection()->action("duplicate_window");
  3009. if ( duplicate->shortcut() == TQKeySequence(CTRL+Key_D) )
  3010. duplicate->setEnabled( actionCollection()->action("new_window")->isEnabled() );
  3011. if (slotNames.contains("cut()"))
  3012. connect( m_paCut, TQT_SIGNAL( activated() ), ext, TQT_SLOT( cut() ) );
  3013. if (slotNames.contains("copy()"))
  3014. connect( m_paCopy, TQT_SIGNAL( activated() ), ext, TQT_SLOT( copy() ) );
  3015. if (slotNames.contains("paste()"))
  3016. connect( m_paPaste, TQT_SIGNAL( activated() ), ext, TQT_SLOT( paste() ) );
  3017. if (slotNames.contains("del()"))
  3018. connect( m_paDelete, TQT_SIGNAL( activated() ), ext, TQT_SLOT( del() ) );
  3019. connect( m_paTrash, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ),
  3020. this, TQT_SLOT( slotTrashActivated( TDEAction::ActivationReason, TQt::ButtonState ) ) );
  3021. disconnect( m_paCut, TQT_SIGNAL( activated() ), m_combo->lineEdit(), TQT_SLOT( cut() ) );
  3022. disconnect( m_paCopy, TQT_SIGNAL( activated() ), m_combo->lineEdit(), TQT_SLOT( copy() ) );
  3023. disconnect( m_paPaste, TQT_SIGNAL( activated() ), m_combo->lineEdit(), TQT_SLOT( paste() ) );
  3024. disconnect( TQApplication::clipboard(), TQT_SIGNAL(dataChanged()), this, TQT_SLOT(slotClipboardDataChanged()) );
  3025. disconnect( m_combo->lineEdit(), TQT_SIGNAL(textChanged(const TQString &)), this, TQT_SLOT(slotCheckComboSelection()) );
  3026. disconnect( m_combo->lineEdit(), TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotCheckComboSelection()) );
  3027. if ( ext )
  3028. {
  3029. m_paCut->setEnabled( ext->isActionEnabled( "cut" ) );
  3030. m_paCopy->setEnabled( ext->isActionEnabled( "copy" ) );
  3031. m_paPaste->setEnabled( ext->isActionEnabled( "paste" ) );
  3032. m_paDelete->setEnabled( ext->isActionEnabled( "delete" ) );
  3033. m_paTrash->setEnabled( ext->isActionEnabled( "trash" ) );
  3034. }
  3035. else
  3036. {
  3037. m_paCut->setEnabled( false );
  3038. m_paCopy->setEnabled( false );
  3039. m_paPaste->setEnabled( false );
  3040. m_paDelete->setEnabled( false );
  3041. m_paTrash->setEnabled( false );
  3042. }
  3043. }
  3044. }
  3045. return KParts::MainWindow::eventFilter( obj, ev );
  3046. }
  3047. void KonqMainWindow::slotClipboardDataChanged()
  3048. {
  3049. //kdDebug(1202) << "KonqMainWindow::slotClipboardDataChanged()" << endl;
  3050. TQMimeSource *data = TQApplication::clipboard()->data();
  3051. m_paPaste->setEnabled( data->provides( "text/plain" ) );
  3052. slotCheckComboSelection();
  3053. }
  3054. void KonqMainWindow::slotCheckComboSelection()
  3055. {
  3056. //kdDebug(1202) << "m_combo->lineEdit()->hasMarkedText() : " << hasSelection << endl;
  3057. bool hasSelection = m_combo->lineEdit()->hasSelectedText();
  3058. m_paCopy->setEnabled( hasSelection );
  3059. m_paCut->setEnabled( hasSelection );
  3060. }
  3061. void KonqMainWindow::slotClearLocationBar( TDEAction::ActivationReason, TQt::ButtonState state )
  3062. {
  3063. kdDebug(1202) << "slotClearLocationBar" << endl;
  3064. slotStop();
  3065. m_combo->clearTemporary();
  3066. focusLocationBar();
  3067. if ( state & Qt::MidButton )
  3068. m_combo->setURL( TQApplication::clipboard()->text( TQClipboard::Selection ) );
  3069. }
  3070. void KonqMainWindow::slotForceSaveMainWindowSettings()
  3071. {
  3072. // kdDebug(1202)<<"slotForceSaveMainWindowSettings()"<<endl;
  3073. if ( autoSaveSettings() ) // don't do it on e.g. JS window.open windows with no toolbars!
  3074. {
  3075. saveMainWindowSettings( TDEGlobal::config(), "KonqMainWindow" );
  3076. TDEGlobal::config()->sync();
  3077. }
  3078. }
  3079. void KonqMainWindow::slotShowMenuBar()
  3080. {
  3081. if (menuBar()->isVisible())
  3082. menuBar()->hide();
  3083. else
  3084. menuBar()->show();
  3085. slotForceSaveMainWindowSettings();
  3086. }
  3087. void KonqMainWindow::slotUpdateFullScreen( bool set )
  3088. {
  3089. if( set )
  3090. {
  3091. showFullScreen();
  3092. // Create toolbar button for exiting from full-screen mode
  3093. // ...but only if there isn't one already...
  3094. bool haveFullScreenButton = false;
  3095. //Walk over the toolbars and check whether there is a show fullscreen button in any of them
  3096. TQPtrListIterator<TDEToolBar> barIt = toolBarIterator();
  3097. for (; barIt.current(); ++barIt )
  3098. {
  3099. //Are we plugged here, in a visible toolbar?
  3100. if (barIt.current()->isVisible() &&
  3101. action( "fullscreen" )->isPlugged(barIt.current()))
  3102. {
  3103. haveFullScreenButton = true;
  3104. break;
  3105. }
  3106. }
  3107. if (!haveFullScreenButton)
  3108. {
  3109. TQPtrList<TDEAction> lst;
  3110. lst.append( m_ptaFullScreen );
  3111. plugActionList( "fullscreen", lst );
  3112. }
  3113. m_prevMenuBarVisible = menuBar()->isVisible();
  3114. menuBar()->hide();
  3115. m_paShowMenuBar->setChecked( false );
  3116. // Qt bug, the flags are lost. They know about it.
  3117. // happens only with the hackish non-_NET_WM_STATE_FULLSCREEN way
  3118. setWFlags( WDestructiveClose );
  3119. // Qt bug (see below)
  3120. setAcceptDrops( FALSE );
  3121. topData()->dnd = 0;
  3122. setAcceptDrops( TRUE );
  3123. }
  3124. else
  3125. {
  3126. #if TQT_VERSION >= 0x030300
  3127. setWindowState( windowState() & ~WindowFullScreen );
  3128. #else
  3129. if( isMaximized())
  3130. {
  3131. showNormal();
  3132. showMaximized(); // showNormal() would reset maximize state
  3133. }
  3134. else
  3135. showNormal();
  3136. #endif
  3137. unplugActionList( "fullscreen" );
  3138. if (m_prevMenuBarVisible)
  3139. {
  3140. menuBar()->show();
  3141. m_paShowMenuBar->setChecked( true );
  3142. }
  3143. // Qt bug, the flags aren't restored. They know about it.
  3144. setWFlags( WType_TopLevel | WDestructiveClose );
  3145. // Other Qt bug
  3146. setAcceptDrops( FALSE );
  3147. topData()->dnd = 0;
  3148. setAcceptDrops( TRUE );
  3149. }
  3150. }
  3151. void KonqMainWindow::setLocationBarURL( const KURL &url )
  3152. {
  3153. setLocationBarURL( url.pathOrURL() );
  3154. }
  3155. void KonqMainWindow::setLocationBarURL( const TQString &url )
  3156. {
  3157. kdDebug(1202) << "KonqMainWindow::setLocationBarURL: url = " << url << endl;
  3158. m_combo->setURL( url );
  3159. setIcon( KonqPixmapProvider::self()->pixmapFor( url ) );
  3160. }
  3161. void KonqMainWindow::setPageSecurity( PageSecurity pageSecurity )
  3162. {
  3163. m_combo->setPageSecurity( pageSecurity );
  3164. }
  3165. void KonqMainWindow::showPageSecurity()
  3166. {
  3167. if ( m_currentView && m_currentView->part() ) {
  3168. TDEAction *act = m_currentView->part()->action( "security" );
  3169. if ( act )
  3170. act->activate();
  3171. }
  3172. }
  3173. // called via DCOP from KonquerorIface
  3174. void KonqMainWindow::comboAction( int action, const TQString& url, const TQCString& objId )
  3175. {
  3176. if (!s_lstViews) // this happens in "konqueror --silent"
  3177. return;
  3178. KonqCombo *combo = 0L;
  3179. KonqMainWindow *window = s_lstViews->first();
  3180. while ( window ) {
  3181. if ( window->m_combo ) {
  3182. combo = window->m_combo;
  3183. switch ( action ) {
  3184. case ComboAdd:
  3185. combo->insertPermanent( url );
  3186. break;
  3187. case ComboClear:
  3188. combo->clearHistory();
  3189. break;
  3190. case ComboRemove:
  3191. combo->removeURL( url );
  3192. break;
  3193. default:
  3194. break;
  3195. }
  3196. }
  3197. window = s_lstViews->next();
  3198. }
  3199. // only one instance should save...
  3200. if ( combo && objId == kapp->dcopClient()->defaultObject() )
  3201. combo->saveItems();
  3202. }
  3203. TQString KonqMainWindow::locationBarURL() const
  3204. {
  3205. return m_combo->currentText();
  3206. }
  3207. void KonqMainWindow::focusLocationBar()
  3208. {
  3209. if ( m_combo->isVisible() || !isVisible() )
  3210. m_combo->setFocus();
  3211. }
  3212. void KonqMainWindow::startAnimation()
  3213. {
  3214. //kdDebug(1202) << "KonqMainWindow::startAnimation" << endl;
  3215. m_paAnimatedLogo->start();
  3216. m_paStop->setEnabled( true );
  3217. toggleReloadStopButton( true );
  3218. }
  3219. void KonqMainWindow::stopAnimation()
  3220. {
  3221. //kdDebug(1202) << "KonqMainWindow::stopAnimation" << endl;
  3222. m_paAnimatedLogo->stop();
  3223. m_paStop->setEnabled( false );
  3224. toggleReloadStopButton( false );
  3225. }
  3226. void KonqMainWindow::setUpEnabled( const KURL &url )
  3227. {
  3228. //kdDebug(1202) << "KonqMainWindow::setUpEnabled(" << url << ")" << endl;
  3229. //kdDebug(1202) << "hasPath=" << url.hasPath() << endl;
  3230. bool bHasUpURL = false;
  3231. bHasUpURL = ( ( url.hasPath() && url.path() != "/" && ( url.path()[0]=='/' ) )
  3232. || !url.query().isEmpty() /*e.g. lists.kde.org*/ );
  3233. if ( !bHasUpURL )
  3234. bHasUpURL = url.hasSubURL();
  3235. m_paUp->setEnabled( bHasUpURL );
  3236. }
  3237. void KonqMainWindow::initActions()
  3238. {
  3239. actionCollection()->setHighlightingEnabled( true );
  3240. connectActionCollection( actionCollection() );
  3241. // Note about this method : don't call setEnabled() on any of the actions.
  3242. // They are all disabled then re-enabled with enableAllActions
  3243. // If any one needs to be initially disabled, put that code in enableAllActions
  3244. // File menu
  3245. m_pMenuNew = new KNewMenu ( actionCollection(), this, "new_menu" );
  3246. TQObject::connect( m_pMenuNew->popupMenu(), TQT_SIGNAL(aboutToShow()),
  3247. this, TQT_SLOT(slotFileNewAboutToShow()) );
  3248. (void) new TDEAction( i18n( "&Edit File Type..." ), 0, actionCollection(), "editMimeType" );
  3249. (void) new TDEAction( i18n( "Properties" ), ALT+Key_Return, actionCollection(), "properties" );
  3250. (void) new TDEAction( i18n( "New &Window" ), "window-new", TDEStdAccel::shortcut(TDEStdAccel::New), TQT_TQOBJECT(this), TQT_SLOT( slotNewWindow() ), actionCollection(), "new_window" );
  3251. (void) new TDEAction( i18n( "&Duplicate Window" ), "window_duplicate", CTRL+Key_D, TQT_TQOBJECT(this), TQT_SLOT( slotDuplicateWindow() ), actionCollection(), "duplicate_window" );
  3252. (void) new TDEAction( i18n( "Send &Link Address..." ), "mail_generic", 0, TQT_TQOBJECT(this), TQT_SLOT( slotSendURL() ), actionCollection(), "sendURL" );
  3253. (void) new TDEAction( i18n( "S&end File..." ), "mail_generic", 0, TQT_TQOBJECT(this), TQT_SLOT( slotSendFile() ), actionCollection(), "sendPage" );
  3254. if (kapp->authorize("shell_access"))
  3255. {
  3256. (void) new TDEAction( i18n( "Open &Terminal" ), "openterm", Key_F4, TQT_TQOBJECT(this), TQT_SLOT( slotOpenTerminal() ), actionCollection(), "open_terminal" );
  3257. }
  3258. (void) new TDEAction( i18n( "&Open Location..." ), "document-open", TDEStdAccel::shortcut(TDEStdAccel::Open), TQT_TQOBJECT(this), TQT_SLOT( slotOpenLocation() ), actionCollection(), "open_location" );
  3259. m_paFindFiles = new TDEToggleAction( i18n( "&Find File..." ), "filefind", TDEStdAccel::shortcut(TDEStdAccel::Find), TQT_TQOBJECT(this), TQT_SLOT( slotToolFind() ), actionCollection(), "findfile" );
  3260. m_paPrint = KStdAction::print( 0, 0, actionCollection(), "print" );
  3261. (void) KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT( close() ), actionCollection(), "quit" );
  3262. m_ptaUseHTML = new TDEToggleAction( i18n( "&Use index.html" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotShowHTML() ), actionCollection(), "usehtml" );
  3263. m_paLockView = new TDEToggleAction( i18n( "Lock to Current Location"), 0, TQT_TQOBJECT(this), TQT_SLOT( slotLockView() ), actionCollection(), "lock" );
  3264. m_paLinkView = new TDEToggleAction( i18n( "Lin&k View"), 0, TQT_TQOBJECT(this), TQT_SLOT( slotLinkView() ), actionCollection(), "link" );
  3265. // Go menu
  3266. m_paUp = new TDEToolBarPopupAction( i18n( "&Up" ), "go-up", TDEStdAccel::shortcut(TDEStdAccel::Up), actionCollection(), "up" );
  3267. connect( m_paUp, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState) ), TQT_TQOBJECT(this),
  3268. TQT_SLOT( slotUp(TDEAction::ActivationReason, TQt::ButtonState) ) );
  3269. connect( m_paUp->popupMenu(), TQT_SIGNAL( aboutToShow() ), TQT_TQOBJECT(this), TQT_SLOT( slotUpAboutToShow() ) );
  3270. connect( m_paUp->popupMenu(), TQT_SIGNAL( activated( int ) ), TQT_TQOBJECT(this), TQT_SLOT( slotUpActivated( int ) ) );
  3271. TQPair< KGuiItem, KGuiItem > backForward = KStdGuiItem::backAndForward();
  3272. m_paBack = new TDEToolBarPopupAction( backForward.first, TDEStdAccel::shortcut(TDEStdAccel::Back), 0, "", actionCollection(), "back" );
  3273. connect( m_paBack, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState) ), TQT_TQOBJECT(this),
  3274. TQT_SLOT( slotBack(TDEAction::ActivationReason, TQt::ButtonState) ) );
  3275. connect( m_paBack->popupMenu(), TQT_SIGNAL( aboutToShow() ), TQT_TQOBJECT(this), TQT_SLOT( slotBackAboutToShow() ) );
  3276. connect( m_paBack->popupMenu(), TQT_SIGNAL( activated( int ) ), TQT_TQOBJECT(this), TQT_SLOT( slotBackActivated( int ) ) );
  3277. m_paForward = new TDEToolBarPopupAction( backForward.second, TDEStdAccel::shortcut(TDEStdAccel::Forward), 0, "", actionCollection(), "forward" );
  3278. connect( m_paForward, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState) ), TQT_TQOBJECT(this),
  3279. TQT_SLOT( slotForward(TDEAction::ActivationReason, TQt::ButtonState) ) );
  3280. connect( m_paForward->popupMenu(), TQT_SIGNAL( aboutToShow() ), TQT_TQOBJECT(this), TQT_SLOT( slotForwardAboutToShow() ) );
  3281. connect( m_paForward->popupMenu(), TQT_SIGNAL( activated( int ) ), TQT_TQOBJECT(this), TQT_SLOT( slotForwardActivated( int ) ) );
  3282. m_paHistory = new KonqBidiHistoryAction( i18n("History"), actionCollection(), "history" );
  3283. connect( m_paHistory, TQT_SIGNAL( menuAboutToShow() ), TQT_TQOBJECT(this), TQT_SLOT( slotGoMenuAboutToShow() ) );
  3284. connect( m_paHistory, TQT_SIGNAL( activated( int ) ), TQT_TQOBJECT(this), TQT_SLOT( slotGoHistoryActivated( int ) ) );
  3285. m_paHome = new TDEAction( i18n( "Home" ), "go-home", TDEStdAccel::shortcut(TDEStdAccel::Home), actionCollection(), "home" );
  3286. connect( m_paHome, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState) ), TQT_TQOBJECT(this),
  3287. TQT_SLOT( slotHome(TDEAction::ActivationReason, TQt::ButtonState) ) );
  3288. (void) new TDEAction( i18n( "S&ystem" ), "computer", 0, TQT_TQOBJECT(this), TQT_SLOT( slotGoSystem() ), actionCollection(), "go_system" );
  3289. (void) new TDEAction( i18n( "App&lications" ), "kmenu", 0, TQT_TQOBJECT(this), TQT_SLOT( slotGoApplications() ), actionCollection(), "go_applications" );
  3290. (void) new TDEAction( i18n( "&Storage Media" ), "computer", 0, TQT_TQOBJECT(this), TQT_SLOT( slotGoMedia() ), actionCollection(), "go_media" );
  3291. (void) new TDEAction( i18n( "&Network Folders" ), "network", 0, TQT_TQOBJECT(this), TQT_SLOT( slotGoNetworkFolders() ), actionCollection(), "go_network_folders" );
  3292. (void) new TDEAction( i18n( "Sett&ings" ), "kcontrol", 0, TQT_TQOBJECT(this), TQT_SLOT( slotGoSettings() ), actionCollection(), "go_settings" );
  3293. //(void) new TDEAction( i18n( "Sidebar Configuration" ), 0, this, TQT_SLOT( slotGoDirTree() ), actionCollection(), "go_dirtree" );
  3294. (void) new TDEAction( i18n( "Trash" ), "trashcan_full", 0, TQT_TQOBJECT(this), TQT_SLOT( slotGoTrash() ), actionCollection(), "go_trash" );
  3295. (void) new TDEAction( i18n( "Autostart" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotGoAutostart() ), actionCollection(), "go_autostart" );
  3296. KonqMostOftenURLSAction *mostOften = new KonqMostOftenURLSAction( i18n("Most Often Visited"), actionCollection(), "go_most_often" );
  3297. connect( mostOften, TQT_SIGNAL( activated( const KURL& )),
  3298. TQT_SLOT( slotOpenURL( const KURL& )));
  3299. (void) new TDEAction( i18n( "History" ), "history", 0, TQT_TQOBJECT(this), TQT_SLOT( slotGoHistory() ), actionCollection(), "go_history" );
  3300. // Settings menu
  3301. m_paSaveViewProfile = new TDEAction( i18n( "&Save View Profile..." ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotSaveViewProfile() ), actionCollection(), "saveviewprofile" );
  3302. m_paSaveViewPropertiesLocally = new TDEToggleAction( i18n( "Save View Changes per &Folder" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotSaveViewPropertiesLocally() ), actionCollection(), "saveViewPropertiesLocally" );
  3303. // "Remove" ? "Reset" ? The former is more correct, the latter is more kcontrol-like...
  3304. m_paRemoveLocalProperties = new TDEAction( i18n( "Remove Folder Properties" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotRemoveLocalProperties() ), actionCollection(), "removeLocalProperties" );
  3305. m_configureModules << "kde-filebehavior.desktop" << "kde-fileappearance.desktop" <<
  3306. "kde-filepreviews.desktop" << "tde-filetypes.desktop" <<
  3307. "tde-tdehtml_behavior.desktop" << "tde-tdehtml_userinterface.desktop" <<
  3308. "tde-tdehtml_java_js.desktop" << "tde-tdehtml_filter.desktop" <<
  3309. "tde-tdehtml_fonts.desktop" << "tde-ebrowsing.desktop" <<
  3310. "tde-kcmhistory.desktop" << "tde-cookies.desktop" <<
  3311. "tde-cache.desktop" << "tde-proxy.desktop" << "tde-kcmcss.desktop" <<
  3312. "tde-kcmcgi.desktop" << "tde-crypto.desktop" << "tde-useragent.desktop" <<
  3313. "tde-tdehtml_plugins.desktop" << "kde-kcmkonqyperformance.desktop";
  3314. if (!kapp->authorizeControlModules(configModules()).isEmpty())
  3315. KStdAction::preferences (TQT_TQOBJECT(this), TQT_SLOT (slotConfigure()), actionCollection() );
  3316. KStdAction::keyBindings( guiFactory(), TQT_SLOT( configureShortcuts() ), actionCollection() );
  3317. KStdAction::configureToolbars( TQT_TQOBJECT(this), TQT_SLOT( slotConfigureToolbars() ), actionCollection() );
  3318. m_paConfigureExtensions = new TDEAction( i18n("Configure Extensions..."), 0, TQT_TQOBJECT(this), TQT_SLOT( slotConfigureExtensions()), actionCollection(), "options_configure_extensions");
  3319. m_paConfigureSpellChecking = new TDEAction( i18n("Configure Spell Checking..."), "tools-check-spelling", 0,TQT_TQOBJECT(this), TQT_SLOT( slotConfigureSpellChecking()), actionCollection(), "configurespellcheck");
  3320. // Window menu
  3321. m_paSplitViewHor = new TDEAction( i18n( "Split View &Left/Right" ), "view_left_right", CTRL+SHIFT+Key_L, TQT_TQOBJECT(this), TQT_SLOT( slotSplitViewHorizontal() ), actionCollection(), "splitviewh" );
  3322. m_paSplitViewVer = new TDEAction( i18n( "Split View &Top/Bottom" ), "view_top_bottom", CTRL+SHIFT+Key_T, TQT_TQOBJECT(this), TQT_SLOT( slotSplitViewVertical() ), actionCollection(), "splitviewv" );
  3323. m_paAddTab = new TDEAction( i18n( "&New Tab" ), "tab_new", "CTRL+SHIFT+N;CTRL+T", TQT_TQOBJECT(this), TQT_SLOT( slotAddTab() ), actionCollection(), "newtab" );
  3324. m_paDuplicateTab = new TDEAction( i18n( "&Duplicate Current Tab" ), "tab_duplicate", CTRL+SHIFT+Key_D, TQT_TQOBJECT(this), TQT_SLOT( slotDuplicateTab() ), actionCollection(), "duplicatecurrenttab" );
  3325. m_paBreakOffTab = new TDEAction( i18n( "Detach Current Tab" ), "tab_breakoff", CTRL+SHIFT+Key_B, TQT_TQOBJECT(this), TQT_SLOT( slotBreakOffTab() ), actionCollection(), "breakoffcurrenttab" );
  3326. m_paRemoveView = new TDEAction( i18n( "&Close Active View" ),"view_remove", CTRL+SHIFT+Key_R, TQT_TQOBJECT(this), TQT_SLOT( slotRemoveView() ), actionCollection(), "removeview" );
  3327. m_paRemoveTab = new TDEAction( i18n( "Close Current Tab" ), "tab_remove", CTRL+Key_W, TQT_TQOBJECT(this), TQT_SLOT( slotRemoveTab() ), actionCollection(), "removecurrenttab" );
  3328. m_paRemoveOtherTabs = new TDEAction( i18n( "Close &Other Tabs" ), "tab_remove_other", 0, TQT_TQOBJECT(this), TQT_SLOT( slotRemoveOtherTabsPopup() ), actionCollection(), "removeothertabs" );
  3329. m_paActivateNextTab = new TDEAction( i18n( "Activate Next Tab" ), "tab_next", TQApplication::reverseLayout() ? TDEStdAccel::tabPrev() : TDEStdAccel::tabNext(), TQT_TQOBJECT(this), TQT_SLOT( slotActivateNextTab() ), actionCollection(), "activatenexttab" );
  3330. m_paActivatePrevTab = new TDEAction( i18n( "Activate Previous Tab" ), "tab_previous", TQApplication::reverseLayout() ? TDEStdAccel::tabNext() : TDEStdAccel::tabPrev(), TQT_TQOBJECT(this), TQT_SLOT( slotActivatePrevTab() ), actionCollection(), "activateprevtab" );
  3331. TQCString actionname;
  3332. for (int i=1;i<13;i++) {
  3333. actionname.sprintf("activate_tab_%02d", i);
  3334. new TDEAction(i18n("Activate Tab %1").arg(i), 0, TQT_TQOBJECT(this), TQT_SLOT(slotActivateTab()), actionCollection(), actionname);
  3335. }
  3336. m_paMoveTabLeft = new TDEAction( i18n("Move Tab Left"), 0 , CTRL+SHIFT+Key_Left,TQT_TQOBJECT(this), TQT_SLOT( slotMoveTabLeft()),actionCollection(),"tab_move_left");
  3337. m_paMoveTabRight = new TDEAction( i18n("Move Tab Right"), 0 , CTRL+SHIFT+Key_Right,TQT_TQOBJECT(this), TQT_SLOT( slotMoveTabRight()),actionCollection(),"tab_move_right");
  3338. #ifndef NDEBUG
  3339. (void) new TDEAction( i18n( "Dump Debug Info" ), "view_dump_debug_info", 0, TQT_TQOBJECT(this), TQT_SLOT( slotDumpDebugInfo() ), actionCollection(), "dumpdebuginfo" );
  3340. #endif
  3341. m_paSaveRemoveViewProfile = new TDEAction( i18n( "C&onfigure View Profiles..." ), 0, m_pViewManager, TQT_SLOT( slotProfileDlg() ), actionCollection(), "saveremoveviewprofile" );
  3342. m_pamLoadViewProfile = new TDEActionMenu( i18n( "Load &View Profile" ), actionCollection(), "loadviewprofile" );
  3343. m_pViewManager->setProfiles( m_pamLoadViewProfile );
  3344. m_ptaFullScreen = KStdAction::fullScreen( 0, 0, actionCollection(), this );
  3345. TDEShortcut fullScreenShortcut = m_ptaFullScreen->shortcut();
  3346. fullScreenShortcut.append( KKey( Key_F11 ) );
  3347. m_ptaFullScreen->setShortcut( fullScreenShortcut );
  3348. connect( m_ptaFullScreen, TQT_SIGNAL( toggled( bool )), TQT_TQOBJECT(this), TQT_SLOT( slotUpdateFullScreen( bool )));
  3349. TDEShortcut reloadShortcut = TDEStdAccel::shortcut(TDEStdAccel::Reload);
  3350. reloadShortcut.append(KKey(CTRL + Key_R));
  3351. m_paReload = new TDEAction( i18n( "&Reload" ), "reload", reloadShortcut, TQT_TQOBJECT(this), TQT_SLOT( slotReload() ), actionCollection(), "reload" );
  3352. m_paReloadAllTabs = new TDEAction( i18n( "&Reload All Tabs" ), "reload_all_tabs", SHIFT+Key_F5, TQT_TQOBJECT(this), TQT_SLOT( slotReloadAllTabs() ), actionCollection(), "reload_all_tabs" );
  3353. m_paReloadStop = new TDEAction( i18n( "&Reload/Stop" ), "reload", 0, TQT_TQOBJECT(this), TQT_SLOT( slotReloadStop() ), actionCollection(), "reload_stop" );
  3354. m_paUndo = KStdAction::undo( KonqUndoManager::self(), TQT_SLOT( undo() ), actionCollection(), "undo" );
  3355. //m_paUndo->setEnabled( KonqUndoManager::self()->undoAvailable() );
  3356. connect( KonqUndoManager::self(), TQT_SIGNAL( undoTextChanged( const TQString & ) ),
  3357. m_paUndo, TQT_SLOT( setText( const TQString & ) ) );
  3358. // Those are connected to the browserextension directly
  3359. m_paCut = KStdAction::cut( 0, 0, actionCollection(), "cut" );
  3360. TDEShortcut cutShortCut = m_paCut->shortcut();
  3361. cutShortCut.remove( KKey( SHIFT + Key_Delete ) ); // used for deleting files
  3362. m_paCut->setShortcut( cutShortCut );
  3363. m_paCopy = KStdAction::copy( 0, 0, actionCollection(), "copy" );
  3364. m_paPaste = KStdAction::paste( 0, 0, actionCollection(), "paste" );
  3365. m_paStop = new TDEAction( i18n( "&Stop" ), "process-stop", Key_Escape, TQT_TQOBJECT(this), TQT_SLOT( slotStop() ), actionCollection(), "stop" );
  3366. m_paRename = new TDEAction( i18n( "&Rename" ), /*"editrename",*/ Key_F2, actionCollection(), "rename" );
  3367. m_paTrash = new TDEAction( i18n( "&Move to Trash" ), "edittrash", Key_Delete, actionCollection(), "trash" );
  3368. connect( m_paTrash, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ),
  3369. TQT_TQOBJECT(this), TQT_SLOT( slotTrashActivated( TDEAction::ActivationReason, TQt::ButtonState ) ) );
  3370. m_paDelete = new TDEAction( i18n( "&Delete" ), "edit-delete", SHIFT+Key_Delete, actionCollection(), "del" );
  3371. // F5 is the default key binding for Reload.... a la Windows. mc users want F5 for Copy and F6 for move, but I can't make that default.
  3372. m_paCopyFiles = new TDEAction( i18n("Copy &Files..."), "copyfiles", Key_F7, TQT_TQOBJECT(this), TQT_SLOT( slotCopyFiles() ), actionCollection(), "copyfiles" );
  3373. m_paMoveFiles = new TDEAction( i18n("M&ove Files..."), "movefiles", Key_F8, TQT_TQOBJECT(this), TQT_SLOT( slotMoveFiles() ), actionCollection(), "movefiles" );
  3374. // This action doesn't appear in the GUI, it's for the shortcut only. KNewMenu takes care of the GUI stuff.
  3375. m_paNewDir = new TDEAction( i18n("Create Folder..." ), "konq_create_dir", Key_F10, TQT_TQOBJECT(this), TQT_SLOT( slotNewDir() ), actionCollection(), "konq_create_dir" );
  3376. m_paAnimatedLogo = new KonqLogoAction( i18n("Animated Logo"), 0, TQT_TQOBJECT(this), TQT_SLOT( slotDuplicateWindow() ), actionCollection(), "animated_logo" );
  3377. // Location bar
  3378. m_locationLabel = new KonqDraggableLabel( this, i18n("L&ocation: ") );
  3379. (void) new KWidgetAction( m_locationLabel, i18n("L&ocation: "), Key_F6, TQT_TQOBJECT(this), TQT_SLOT( slotLocationLabelActivated() ), actionCollection(), "location_label" );
  3380. m_locationLabel->setBuddy( m_combo );
  3381. KWidgetAction* comboAction = new KWidgetAction( m_combo, i18n( "Location Bar" ), 0,
  3382. 0, 0, actionCollection(), "toolbar_url_combo" );
  3383. comboAction->setShortcutConfigurable( false );
  3384. comboAction->setAutoSized( true );
  3385. TQWhatsThis::add( m_combo, i18n( "Location Bar<p>"
  3386. "Enter a web address or search term." ) );
  3387. TDEAction *clearLocation = new TDEAction( i18n( "Clear Location Bar" ),
  3388. TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase",
  3389. CTRL+Key_L, actionCollection(), "clear_location" );
  3390. connect( clearLocation, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ),
  3391. TQT_SLOT( slotClearLocationBar( TDEAction::ActivationReason, TQt::ButtonState ) ) );
  3392. clearLocation->setWhatsThis( i18n( "Clear Location bar<p>"
  3393. "Clears the content of the location bar." ) );
  3394. // Bookmarks menu
  3395. m_pamBookmarks = new TDEActionMenu( i18n( "&Bookmarks" ), "bookmark", actionCollection(), "bookmarks" );
  3396. m_pamBookmarks->setDelayed( false );
  3397. // The actual menu needs a different action collection, so that the bookmarks
  3398. // don't appear in kedittoolbar
  3399. m_bookmarksActionCollection = new TDEActionCollection( this );
  3400. m_bookmarksActionCollection->setHighlightingEnabled( true );
  3401. connectActionCollection( m_bookmarksActionCollection );
  3402. m_pBookmarkMenu = new KBookmarkMenu( KonqBookmarkManager::self(), m_pBookmarksOwner, m_pamBookmarks->popupMenu(), m_bookmarksActionCollection, true );
  3403. connect( m_pBookmarkMenu,
  3404. TQT_SIGNAL( aboutToShowContextMenu(const KBookmark &, TQPopupMenu*) ),
  3405. this, TQT_SLOT( slotFillContextMenu(const KBookmark &, TQPopupMenu*) ));
  3406. connect( m_pBookmarkMenu,
  3407. TQT_SIGNAL( openBookmark(const TQString &, TQt::ButtonState) ),
  3408. this, TQT_SLOT( slotOpenBookmarkURL(const TQString &, TQt::ButtonState) ));
  3409. TDEAction *addBookmark = actionCollection()->action("add_bookmark");
  3410. if (addBookmark)
  3411. addBookmark->setText(i18n("Bookmark This Location"));
  3412. m_paShowMenuBar = KStdAction::showMenubar( TQT_TQOBJECT(this), TQT_SLOT( slotShowMenuBar() ), actionCollection() );
  3413. (void) new TDEAction( i18n( "Kon&queror Introduction" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotIntro() ), actionCollection(), "konqintro" );
  3414. TDEAction *goUrl = new TDEAction( i18n( "Go" ), "key_enter", 0, TQT_TQOBJECT(this), TQT_SLOT( goURL() ), actionCollection(), "go_url" );
  3415. goUrl->setWhatsThis( i18n( "Go<p>"
  3416. "Goes to the page that has been entered into the location bar." ) );
  3417. enableAllActions( false );
  3418. // help stuff
  3419. m_paUp->setWhatsThis( i18n( "Enter the parent folder<p>"
  3420. "For instance, if the current location is file:/home/%1 clicking this "
  3421. "button will take you to file:/home." ).arg( KUser().loginName() ) );
  3422. m_paUp->setToolTip( i18n( "Enter the parent folder" ) );
  3423. m_paBack->setWhatsThis( i18n( "Move backwards one step in the browsing history<p>" ) );
  3424. m_paBack->setToolTip( i18n( "Move backwards one step in the browsing history" ) );
  3425. m_paForward->setWhatsThis( i18n( "Move forward one step in the browsing history<p>" ) );
  3426. m_paForward->setToolTip( i18n( "Move forward one step in the browsing history" ) );
  3427. m_paHome->setWhatsThis( i18n( "Navigate to your 'Home Location'<p>"
  3428. "You can configure the location this button takes you to in the "
  3429. "<b>Trinity Control Center</b>, under <b>File Manager</b>/<b>Behavior</b>." ) );
  3430. m_paHome->setToolTip( i18n( "Navigate to your 'Home Location'" ) );
  3431. m_paReload->setWhatsThis( i18n( "Reload the currently displayed document<p>"
  3432. "This may, for example, be needed to refresh webpages that have been "
  3433. "modified since they were loaded, in order to make the changes visible." ) );
  3434. m_paReload->setToolTip( i18n( "Reload the currently displayed document" ) );
  3435. m_paReloadAllTabs->setWhatsThis( i18n( "Reload all currently displayed documents in tabs<p>"
  3436. "This may, for example, be needed to refresh webpages that have been "
  3437. "modified since they were loaded, in order to make the changes visible." ) );
  3438. m_paReloadAllTabs->setToolTip( i18n( "Reload all currently displayed document in tabs" ) );
  3439. m_paStop->setWhatsThis( i18n( "Stop loading the document<p>"
  3440. "All network transfers will be stopped and Konqueror will display the content "
  3441. "that has been received so far." ) );
  3442. m_paStop->setToolTip( i18n( "Stop loading the document" ) );
  3443. m_paCut->setWhatsThis( i18n( "Cut the currently selected text or item(s) and move it "
  3444. "to the system clipboard<p> "
  3445. "This makes it available to the <b>Paste</b> command in Konqueror "
  3446. "and other TDE applications." ) );
  3447. m_paCut->setToolTip( i18n( "Move the selected text or item(s) to the clipboard" ) );
  3448. m_paCopy->setWhatsThis( i18n( "Copy the currently selected text or item(s) to the "
  3449. "system clipboard<p>"
  3450. "This makes it available to the <b>Paste</b> command in Konqueror "
  3451. "and other TDE applications." ) );
  3452. m_paCopy->setToolTip( i18n( "Copy the selected text or item(s) to the clipboard" ) );
  3453. m_paPaste->setWhatsThis( i18n( "Paste the previously cut or copied clipboard "
  3454. "contents<p>"
  3455. "This also works for text copied or cut from other TDE applications." ) );
  3456. m_paPaste->setToolTip( i18n( "Paste the clipboard contents" ) );
  3457. m_paPrint->setWhatsThis( i18n( "Print the currently displayed document<p>"
  3458. "You will be presented with a dialog where you can set various "
  3459. "options, such as the number of copies to print and which printer "
  3460. "to use.<p>"
  3461. "This dialog also provides access to special TDE printing "
  3462. "services such as creating a PDF file from the current document." ) );
  3463. m_paPrint->setToolTip( i18n( "Print the current document" ) );
  3464. // Please proof-read those (David)
  3465. m_ptaUseHTML->setToolTip( i18n("If present, open index.html when entering a folder.") );
  3466. m_paLockView->setToolTip( i18n("A locked view cannot change folders. Use in combination with 'link view' to explore many files from one folder") );
  3467. m_paLinkView->setToolTip( i18n("Sets the view as 'linked'. A linked view follows folder changes made in other linked views.") );
  3468. }
  3469. void KonqMainWindow::slotFillContextMenu( const KBookmark &bk, TQPopupMenu * pm )
  3470. {
  3471. kdDebug() << "KonqMainWindow::slotFillContextMenu(bk, pm == " << pm << ")" << endl;
  3472. popupItems.clear();
  3473. popupUrlArgs = KParts::URLArgs();
  3474. //Set tab_new_x to point to the correct icon based on NewTabsInFront
  3475. bool newtabsinfront = KonqSettings::newTabsInFront();
  3476. TQString tab_new_x ;
  3477. if ( newtabsinfront )
  3478. tab_new_x = "tab_new" ;
  3479. else
  3480. tab_new_x = "tab_new_bg" ;
  3481. if ( bk.isGroup() )
  3482. {
  3483. KBookmarkGroup grp = bk.toGroup();
  3484. TQValueList<KURL> list = grp.groupUrlList();
  3485. TQValueList<KURL>::Iterator it = list.begin();
  3486. for (; it != list.end(); ++it )
  3487. popupItems.append( new KFileItem( (*it), TQString::null, KFileItem::Unknown) );
  3488. pm->insertItem( SmallIcon(tab_new_x), i18n( "Open Folder in Tabs" ), this, TQT_SLOT( slotPopupNewTabRight() ) );
  3489. }
  3490. else
  3491. {
  3492. popupItems.append( new KFileItem( bk.url(), TQString::null, KFileItem::Unknown) );
  3493. pm->insertItem( SmallIcon("window-new"), i18n( "Open in New Window" ), this, TQT_SLOT( slotPopupNewWindow() ) );
  3494. pm->insertItem( SmallIcon(tab_new_x), i18n( "Open in New Tab" ), this, TQT_SLOT( slotPopupNewTabRight() ) );
  3495. }
  3496. }
  3497. void KonqMainWindow::slotOpenBookmarkURL( const TQString & url, TQt::ButtonState state)
  3498. {
  3499. kdDebug(1202) << "KonqMainWindow::slotOpenBookmarkURL(" << url << ", " << state << ")" << endl;
  3500. KonqOpenURLRequest req;
  3501. req.newTab = true;
  3502. req.newTabInFront = KonqSettings::newTabsInFront();
  3503. if (state & TQt::ShiftButton)
  3504. req.newTabInFront = !req.newTabInFront;
  3505. if( state & TQt::ControlButton ) // Ctrl Left/MMB
  3506. openFilteredURL( url, req);
  3507. else if( state & Qt::MidButton )
  3508. {
  3509. if(KonqSettings::mmbOpensTab())
  3510. openFilteredURL( url, req);
  3511. else
  3512. {
  3513. KURL finalURL = KonqMisc::konqFilteredURL( this, url );
  3514. KonqMisc::createNewWindow( finalURL.url() );
  3515. }
  3516. }
  3517. else
  3518. openFilteredURL( url, false );
  3519. }
  3520. void KonqMainWindow::slotMoveTabLeft()
  3521. {
  3522. if ( TQApplication::reverseLayout() )
  3523. m_pViewManager->moveTabForward();
  3524. else
  3525. m_pViewManager->moveTabBackward();
  3526. }
  3527. void KonqMainWindow::slotMoveTabRight()
  3528. {
  3529. if ( TQApplication::reverseLayout() )
  3530. m_pViewManager->moveTabBackward();
  3531. else
  3532. m_pViewManager->moveTabForward();
  3533. }
  3534. void KonqMainWindow::updateToolBarActions( bool pendingAction /*=false*/)
  3535. {
  3536. // Enables/disables actions that depend on the current view & url (mostly toolbar)
  3537. // Up, back, forward, the edit extension, stop button, wheel
  3538. setUpEnabled( m_currentView->url() );
  3539. m_paBack->setEnabled( m_currentView->canGoBack() );
  3540. m_paForward->setEnabled( m_currentView->canGoForward() );
  3541. if ( m_currentView->isLoading() )
  3542. {
  3543. startAnimation(); // takes care of m_paStop
  3544. }
  3545. else
  3546. {
  3547. m_paAnimatedLogo->stop();
  3548. m_paStop->setEnabled( pendingAction ); //enable/disable based on any pending actions...
  3549. toggleReloadStopButton( pendingAction );
  3550. }
  3551. if ( m_currentView && m_currentView->url().isLocalFile() &&
  3552. !m_currentView->isLockedViewMode() ) {
  3553. if ( m_currentView->serviceTypes().contains( "inode/directory" ) )
  3554. m_ptaUseHTML->setEnabled( true );
  3555. else if ( m_currentView->serviceTypes().contains( "text/html" ) ) {
  3556. // Currently viewing an index.html file via this feature (i.e. url points to a dir)
  3557. TQString locPath = KURL( m_currentView->locationBarURL() ).path();
  3558. m_ptaUseHTML->setEnabled( TQFileInfo( locPath ).isDir() );
  3559. } else
  3560. m_ptaUseHTML->setEnabled( false );
  3561. }
  3562. else
  3563. {
  3564. m_ptaUseHTML->setEnabled( false );
  3565. }
  3566. }
  3567. void KonqMainWindow::updateViewActions()
  3568. {
  3569. // Update actions that depend on the current view and its mode, or on the number of views etc.
  3570. // Don't do things in this method that depend on m_currentView->url().
  3571. // When going 'back' in history this will be called before opening the url.
  3572. // Use updateToolBarActions instead.
  3573. slotUndoAvailable( KonqUndoManager::self()->undoAvailable() );
  3574. // Can lock a view only if there is a next view
  3575. //m_paLockView->setEnabled( m_pViewManager->chooseNextView(m_currentView) != 0L && );
  3576. //kdDebug(1202) << "KonqMainWindow::updateViewActions m_paLockView enabled ? " << m_paLockView->isEnabled() << endl;
  3577. m_paLockView->setEnabled( viewCount() > 1 );
  3578. m_paLockView->setChecked( m_currentView && m_currentView->isLockedLocation() );
  3579. // Can remove view if we'll still have a main view after that
  3580. m_paRemoveView->setEnabled( mainViewsCount() > 1 ||
  3581. ( m_currentView && m_currentView->isToggleView() ) );
  3582. KonqFrameBase* docContainer = m_pViewManager->docContainer();
  3583. if ( docContainer == 0L && !(currentView() && currentView()->frame()))
  3584. {
  3585. m_paAddTab->setEnabled( false );
  3586. m_paDuplicateTab->setEnabled( false );
  3587. m_paRemoveTab->setEnabled( false );
  3588. m_paRemoveOtherTabs->setEnabled( false );
  3589. m_paBreakOffTab->setEnabled( false );
  3590. m_paActivateNextTab->setEnabled( false );
  3591. m_paActivatePrevTab->setEnabled( false );
  3592. m_paMoveTabLeft->setEnabled( false );
  3593. m_paMoveTabRight->setEnabled( false );
  3594. }
  3595. else
  3596. {
  3597. m_paAddTab->setEnabled( true );
  3598. m_paDuplicateTab->setEnabled( true );
  3599. if ( docContainer && docContainer->frameType() == "Tabs" )
  3600. {
  3601. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(docContainer);
  3602. bool state = (tabContainer->count()>1);
  3603. m_paRemoveTab->setEnabled( state );
  3604. m_paRemoveOtherTabs->setEnabled( state );
  3605. m_paBreakOffTab->setEnabled( state );
  3606. m_paActivateNextTab->setEnabled( state );
  3607. m_paActivatePrevTab->setEnabled( state );
  3608. TQPtrList<KonqFrameBase>* childFrameList = tabContainer->childFrameList();
  3609. m_paMoveTabLeft->setEnabled( currentView() ? currentView()->frame()!=
  3610. (TQApplication::reverseLayout() ? childFrameList->last() : childFrameList->first()) : false );
  3611. m_paMoveTabRight->setEnabled( currentView() ? currentView()->frame()!=
  3612. (TQApplication::reverseLayout() ? childFrameList->first() : childFrameList->last()) : false );
  3613. }
  3614. else
  3615. {
  3616. m_paRemoveTab->setEnabled( false );
  3617. m_paRemoveOtherTabs->setEnabled( false );
  3618. m_paBreakOffTab->setEnabled( false );
  3619. m_paActivateNextTab->setEnabled( false );
  3620. m_paActivatePrevTab->setEnabled( false );
  3621. m_paMoveTabLeft->setEnabled( false );
  3622. m_paMoveTabRight->setEnabled( false );
  3623. }
  3624. }
  3625. // Can split a view if it's not a toggle view (because a toggle view can be here only once)
  3626. bool isNotToggle = m_currentView && !m_currentView->isToggleView();
  3627. m_paSplitViewHor->setEnabled( isNotToggle );
  3628. m_paSplitViewVer->setEnabled( isNotToggle );
  3629. m_paLinkView->setChecked( m_currentView && m_currentView->isLinkedView() );
  3630. if ( m_currentView && m_currentView->part() &&
  3631. m_currentView->part()->inherits("KonqDirPart") )
  3632. {
  3633. KonqDirPart * dirPart = static_cast<KonqDirPart *>(m_currentView->part());
  3634. m_paFindFiles->setEnabled( dirPart->findPart() == 0 );
  3635. TQPtrList<TDEAction> lst;
  3636. if (!m_paCopyFiles->isPlugged())
  3637. lst.append( m_paCopyFiles );
  3638. if (!m_paMoveFiles->isPlugged())
  3639. lst.append( m_paMoveFiles );
  3640. m_paCopyFiles->setEnabled( false );
  3641. m_paMoveFiles->setEnabled( false );
  3642. if (!lst.isEmpty())
  3643. plugActionList( "operations", lst );
  3644. }
  3645. else
  3646. {
  3647. m_paFindFiles->setEnabled( false );
  3648. unplugActionList( "operations" );
  3649. }
  3650. }
  3651. TQString KonqMainWindow::findIndexFile( const TQString &dir )
  3652. {
  3653. TQDir d( dir );
  3654. TQString f = d.filePath( "index.html", false );
  3655. if ( TQFile::exists( f ) )
  3656. return f;
  3657. f = d.filePath( "index.htm", false );
  3658. if ( TQFile::exists( f ) )
  3659. return f;
  3660. f = d.filePath( "index.HTML", false );
  3661. if ( TQFile::exists( f ) )
  3662. return f;
  3663. return TQString::null;
  3664. }
  3665. void KonqMainWindow::connectExtension( KParts::BrowserExtension *ext )
  3666. {
  3667. //kdDebug(1202) << "Connecting extension " << ext << endl;
  3668. KParts::BrowserExtension::ActionSlotMap * actionSlotMap = KParts::BrowserExtension::actionSlotMapPtr();
  3669. KParts::BrowserExtension::ActionSlotMap::ConstIterator it = actionSlotMap->begin();
  3670. KParts::BrowserExtension::ActionSlotMap::ConstIterator itEnd = actionSlotMap->end();
  3671. TQStrList slotNames = ext->metaObject()->slotNames();
  3672. for ( ; it != itEnd ; ++it )
  3673. {
  3674. TDEAction * act = actionCollection()->action( static_cast<const char *>(it.key()) );
  3675. //kdDebug(1202) << it.key() << endl;
  3676. if ( act )
  3677. {
  3678. // Does the extension have a slot with the name of this action ?
  3679. if ( slotNames.contains( it.key()+"()" ) )
  3680. {
  3681. if ( it.key() != "trash" )
  3682. connect( act, TQT_SIGNAL( activated() ), ext, it.data() /* TQT_SLOT(slot name) */ );
  3683. act->setEnabled( ext->isActionEnabled( it.key() ) );
  3684. const TQString text = ext->actionText( it.key() );
  3685. if ( !text.isEmpty() )
  3686. act->setText( text );
  3687. // TODO how to re-set the original action text, when switching to a part that didn't call setAction?
  3688. // Can't test with Paste...
  3689. } else
  3690. act->setEnabled(false);
  3691. } else kdError(1202) << "Error in BrowserExtension::actionSlotMap(), unknown action : " << it.key() << endl;
  3692. }
  3693. }
  3694. void KonqMainWindow::disconnectExtension( KParts::BrowserExtension *ext )
  3695. {
  3696. //kdDebug(1202) << "Disconnecting extension " << ext << endl;
  3697. KParts::BrowserExtension::ActionSlotMap * actionSlotMap = KParts::BrowserExtension::actionSlotMapPtr();
  3698. KParts::BrowserExtension::ActionSlotMap::ConstIterator it = actionSlotMap->begin();
  3699. KParts::BrowserExtension::ActionSlotMap::ConstIterator itEnd = actionSlotMap->end();
  3700. TQStrList slotNames = ext->metaObject()->slotNames();
  3701. for ( ; it != itEnd ; ++it )
  3702. {
  3703. TDEAction * act = actionCollection()->action( static_cast<const char *>(it.key()) );
  3704. //kdDebug(1202) << it.key() << endl;
  3705. if ( act && slotNames.contains( it.key()+"()" ) )
  3706. {
  3707. //kdDebug(1202) << "disconnectExtension: " << act << " " << act->name() << endl;
  3708. act->disconnect( ext );
  3709. }
  3710. }
  3711. }
  3712. void KonqMainWindow::slotTrashActivated( TDEAction::ActivationReason reason, TQt::ButtonState state )
  3713. {
  3714. if ( !m_currentView )
  3715. return;
  3716. if ( reason == TDEAction::PopupMenuActivation && ( state & TQt::ShiftButton ) )
  3717. m_currentView->callExtensionMethod( "del()" );
  3718. else
  3719. m_currentView->callExtensionMethod( "trash()" );
  3720. }
  3721. void KonqMainWindow::enableAction( const char * name, bool enabled )
  3722. {
  3723. TDEAction * act = actionCollection()->action( name );
  3724. if (!act)
  3725. kdWarning(1202) << "Unknown action " << name << " - can't enable" << endl;
  3726. else
  3727. {
  3728. if ( m_bLocationBarConnected && (
  3729. act==m_paCopy || act==m_paCut || act==m_paPaste || act==m_paDelete || act==m_paTrash ) )
  3730. // Don't change action state while the location bar has focus.
  3731. return;
  3732. //kdDebug(1202) << "KonqMainWindow::enableAction " << name << " " << enabled << endl;
  3733. act->setEnabled( enabled );
  3734. }
  3735. // Update "copy files" and "move files" accordingly
  3736. if (m_paCopyFiles && !strcmp( name, "copy" ))
  3737. {
  3738. m_paCopyFiles->setEnabled( enabled );
  3739. }
  3740. else if (m_paMoveFiles && !strcmp( name, "cut" ))
  3741. {
  3742. m_paMoveFiles->setEnabled( enabled );
  3743. }
  3744. }
  3745. void KonqMainWindow::setActionText( const char * name, const TQString& text )
  3746. {
  3747. TDEAction * act = actionCollection()->action( name );
  3748. if (!act)
  3749. kdWarning(1202) << "Unknown action " << name << " - can't enable" << endl;
  3750. else
  3751. {
  3752. kdDebug(1202) << "KonqMainWindow::setActionText " << name << " " << text << endl;
  3753. act->setText( text );
  3754. }
  3755. }
  3756. void KonqMainWindow::currentProfileChanged()
  3757. {
  3758. bool enabled = !m_pViewManager->currentProfile().isEmpty();
  3759. m_paSaveViewProfile->setEnabled( enabled );
  3760. m_paSaveViewProfile->setText( enabled ? i18n("&Save View Profile \"%1\"...").arg(m_pViewManager->currentProfileText())
  3761. : i18n("&Save View Profile...") );
  3762. }
  3763. void KonqMainWindow::enableAllActions( bool enable )
  3764. {
  3765. kdDebug(1202) << "KonqMainWindow::enableAllActions " << enable << endl;
  3766. KParts::BrowserExtension::ActionSlotMap * actionSlotMap = KParts::BrowserExtension::actionSlotMapPtr();
  3767. TQValueList<TDEAction *> actions = actionCollection()->actions();
  3768. TQValueList<TDEAction *>::Iterator it = actions.begin();
  3769. TQValueList<TDEAction *>::Iterator end = actions.end();
  3770. for (; it != end; ++it )
  3771. {
  3772. TDEAction *act = *it;
  3773. if ( !TQString(act->name()).startsWith("options_configure") /* do not touch the configureblah actions */
  3774. && ( !enable || !actionSlotMap->contains( act->name() ) ) ) /* don't enable BE actions */
  3775. act->setEnabled( enable );
  3776. }
  3777. // This method is called with enable=false on startup, and
  3778. // then only once with enable=true when the first view is setup.
  3779. // So the code below is where actions that should initially be disabled are disabled.
  3780. if (enable)
  3781. {
  3782. setUpEnabled( m_currentView ? m_currentView->url() : KURL() );
  3783. // we surely don't have any history buffers at this time
  3784. m_paBack->setEnabled( false );
  3785. m_paForward->setEnabled( false );
  3786. // Load profile submenu
  3787. m_pViewManager->profileListDirty( false );
  3788. currentProfileChanged();
  3789. updateViewActions(); // undo, lock, link and other view-dependent actions
  3790. m_paStop->setEnabled( m_currentView && m_currentView->isLoading() );
  3791. toggleReloadStopButton( m_currentView && m_currentView->isLoading() );
  3792. if (m_toggleViewGUIClient)
  3793. {
  3794. TQPtrList<TDEAction> actions = m_toggleViewGUIClient->actions();
  3795. for ( TDEAction * it = actions.first(); it ; it = actions.next() )
  3796. it->setEnabled( true );
  3797. }
  3798. }
  3799. actionCollection()->action( "quit" )->setEnabled( true );
  3800. }
  3801. void KonqMainWindow::disableActionsNoView()
  3802. {
  3803. // No view -> there are some things we can't do
  3804. m_paUp->setEnabled( false );
  3805. m_paReload->setEnabled( false );
  3806. m_paReloadAllTabs->setEnabled( false );
  3807. m_paBack->setEnabled( false );
  3808. m_paForward->setEnabled( false );
  3809. m_ptaUseHTML->setEnabled( false );
  3810. m_pMenuNew->setEnabled( false );
  3811. m_paLockView->setEnabled( false );
  3812. m_paLockView->setChecked( false );
  3813. m_paSplitViewVer->setEnabled( false );
  3814. m_paSplitViewHor->setEnabled( false );
  3815. m_paRemoveView->setEnabled( false );
  3816. m_paLinkView->setEnabled( false );
  3817. if (m_toggleViewGUIClient)
  3818. {
  3819. TQPtrList<TDEAction> actions = m_toggleViewGUIClient->actions();
  3820. for ( TDEAction * it = actions.first(); it ; it = actions.next() )
  3821. it->setEnabled( false );
  3822. }
  3823. // There are things we can do, though : bookmarks, view profile, location bar, new window,
  3824. // settings, etc.
  3825. m_paHome->setEnabled( true );
  3826. m_pamBookmarks->setEnabled( true );
  3827. static const char* const s_enActions[] = { "new_window", "duplicate_window", "open_location",
  3828. "toolbar_url_combo", "clear_location", "animated_logo",
  3829. "konqintro", "go_most_often", "go_applications", "go_dirtree",
  3830. "go_trash", "go_settings", "go_network_folders", "go_autostart",
  3831. "go_url", "go_media", "go_history", "options_configure_extensions", 0 };
  3832. for ( int i = 0 ; s_enActions[i] ; ++i )
  3833. {
  3834. TDEAction * act = action(s_enActions[i]);
  3835. if (act)
  3836. act->setEnabled( true );
  3837. }
  3838. m_pamLoadViewProfile->setEnabled( true );
  3839. m_paSaveViewProfile->setEnabled( true );
  3840. m_paSaveRemoveViewProfile->setEnabled( true );
  3841. m_combo->clearTemporary();
  3842. updateLocalPropsActions();
  3843. }
  3844. void KonqExtendedBookmarkOwner::openBookmarkURL( const TQString & /*url*/ )
  3845. {
  3846. // Do nothing, we catch the signal
  3847. }
  3848. void KonqMainWindow::setCaption( const TQString &caption )
  3849. {
  3850. // KParts sends us empty captions when activating a brand new part
  3851. // We can't change it there (in case of apps removing all parts altogether)
  3852. // but here we never do that.
  3853. if ( !caption.isEmpty() && m_currentView )
  3854. {
  3855. kdDebug(1202) << "KonqMainWindow::setCaption(" << caption << ")" << endl;
  3856. // Keep an unmodified copy of the caption (before kapp->makeStdCaption is applied)
  3857. m_currentView->setCaption( caption );
  3858. KParts::MainWindow::setCaption( m_currentView->caption() );
  3859. }
  3860. }
  3861. void KonqMainWindow::show()
  3862. {
  3863. // We need to check if our toolbars are shown/hidden here, and set
  3864. // our menu items accordingly. We can't do it in the constructor because
  3865. // view profiles store toolbar info, and that info is read after
  3866. // construct time.
  3867. m_paShowMenuBar->setChecked( !menuBar()->isHidden() );
  3868. updateBookmarkBar(); // hide if empty
  3869. // Call parent method
  3870. KParts::MainWindow::show();
  3871. }
  3872. TQString KonqExtendedBookmarkOwner::currentURL() const
  3873. {
  3874. return m_pKonqMainWindow->currentURL();
  3875. }
  3876. TQString KonqMainWindow::currentProfile() const
  3877. {
  3878. return m_pViewManager->currentProfile();
  3879. }
  3880. TQString KonqMainWindow::currentURL() const
  3881. {
  3882. if ( !m_currentView )
  3883. return TQString::null;
  3884. TQString url = m_currentView->url().prettyURL();
  3885. if ( m_currentView->part() && m_currentView->part()->inherits("KonqDirPart") )
  3886. {
  3887. TQString nameFilter = static_cast<KonqDirPart *>(m_currentView->part())->nameFilter();
  3888. if ( !nameFilter.isEmpty() )
  3889. {
  3890. if (!url.endsWith("/"))
  3891. url += '/';
  3892. url += nameFilter;
  3893. }
  3894. }
  3895. return url;
  3896. }
  3897. void KonqExtendedBookmarkOwner::slotFillBookmarksList( KExtendedBookmarkOwner::QStringPairList & list )
  3898. {
  3899. KonqFrameBase *docContainer = m_pKonqMainWindow->viewManager()->docContainer();
  3900. if (docContainer == 0L) return;
  3901. if (docContainer->frameType() != "Tabs") return;
  3902. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(docContainer);
  3903. TQPtrList<KonqFrameBase> frameList = *tabContainer->childFrameList();
  3904. TQPtrListIterator<KonqFrameBase> it( frameList );
  3905. for ( it.toFirst(); it != 0L; ++it )
  3906. {
  3907. if ( !it.current()->activeChildView() )
  3908. continue;
  3909. if( it.current()->activeChildView()->locationBarURL().isEmpty() )
  3910. continue;
  3911. list << qMakePair( it.current()->activeChildView()->caption(),
  3912. it.current()->activeChildView()->url().url() );
  3913. }
  3914. }
  3915. TQString KonqExtendedBookmarkOwner::currentTitle() const
  3916. {
  3917. return m_pKonqMainWindow->currentTitle();
  3918. }
  3919. TQString KonqMainWindow::currentTitle() const
  3920. {
  3921. return m_currentView ? m_currentView->caption() : TQString::null;
  3922. }
  3923. void KonqMainWindow::slotPopupMenu( const TQPoint &_global, const KURL &url, const TQString &_mimeType, mode_t _mode )
  3924. {
  3925. slotPopupMenu( 0L, _global, url, _mimeType, _mode );
  3926. }
  3927. void KonqMainWindow::slotPopupMenu( KXMLGUIClient *client, const TQPoint &_global, const KURL &url, const TQString &_mimeType, mode_t _mode )
  3928. {
  3929. KFileItem item( url, _mimeType, _mode );
  3930. KFileItemList items;
  3931. items.append( &item );
  3932. slotPopupMenu( client, _global, items, KParts::URLArgs(), KParts::BrowserExtension::DefaultPopupItems, false ); //BE CAREFUL WITH sender() !
  3933. }
  3934. void KonqMainWindow::slotPopupMenu( KXMLGUIClient *client, const TQPoint &_global, const KURL &url, const KParts::URLArgs &_args, KParts::BrowserExtension::PopupFlags f, mode_t _mode )
  3935. {
  3936. KFileItem item( url, _args.serviceType, _mode );
  3937. KFileItemList items;
  3938. items.append( &item );
  3939. slotPopupMenu( client, _global, items, _args, f, false ); //BE CAREFUL WITH sender() !
  3940. }
  3941. void KonqMainWindow::slotPopupMenu( const TQPoint &_global, const KFileItemList &_items )
  3942. {
  3943. slotPopupMenu( 0L, _global, _items );
  3944. }
  3945. void KonqMainWindow::slotPopupMenu( KXMLGUIClient *client, const TQPoint &_global, const KFileItemList &_items )
  3946. {
  3947. slotPopupMenu( client, _global, _items, KParts::URLArgs(), KParts::BrowserExtension::DefaultPopupItems, true );
  3948. }
  3949. void KonqMainWindow::slotPopupMenu( KXMLGUIClient *client, const TQPoint &_global, const KFileItemList &_items, const KParts::URLArgs &_args, KParts::BrowserExtension::PopupFlags _flags )
  3950. {
  3951. slotPopupMenu( client, _global, _items, _args, _flags, true );
  3952. }
  3953. void KonqMainWindow::slotPopupMenu( KXMLGUIClient *client, const TQPoint &_global, const KFileItemList &_items, const KParts::URLArgs &_args, KParts::BrowserExtension::PopupFlags itemFlags, bool showProperties )
  3954. {
  3955. KonqView * m_oldView = m_currentView;
  3956. KonqView * currentView = childView( static_cast<KParts::ReadOnlyPart *>( TQT_TQOBJECT_CONST(sender())->parent() ) );
  3957. //kdDebug() << "KonqMainWindow::slotPopupMenu m_oldView=" << m_oldView << " new currentView=" << currentView << " passive:" << currentView->isPassiveMode() << endl;
  3958. if ( (m_oldView != currentView) && currentView->isPassiveMode() )
  3959. {
  3960. // Make this view active only temporarily (because it's passive)
  3961. m_currentView = currentView;
  3962. if ( m_oldView && m_oldView->browserExtension() )
  3963. disconnectExtension( m_oldView->browserExtension() );
  3964. if ( m_currentView->browserExtension() )
  3965. connectExtension( m_currentView->browserExtension() );
  3966. }
  3967. // Note that if m_oldView!=currentView and currentView isn't passive,
  3968. // then the KParts mechanism has already noticed the click in it,
  3969. // but KonqViewManager delays the GUI-rebuilding with a single-shot timer.
  3970. // Right after the popup shows up, currentView _will_ be m_currentView.
  3971. //kdDebug(1202) << "KonqMainWindow::slotPopupMenu( " << client << "...)" << " current view=" << m_currentView << " " << m_currentView->part()->className() << endl;
  3972. // This action collection is used to pass actions to KonqPopupMenu.
  3973. // It has to be a TDEActionCollection instead of a TDEActionPtrList because we need
  3974. // the actionStatusText signal...
  3975. TDEActionCollection popupMenuCollection( (TQWidget*)0 );
  3976. popupMenuCollection.insert( m_paBack );
  3977. popupMenuCollection.insert( m_paForward );
  3978. popupMenuCollection.insert( m_paUp );
  3979. popupMenuCollection.insert( m_paReload );
  3980. popupMenuCollection.insert( m_paFindFiles );
  3981. popupMenuCollection.insert( m_paUndo );
  3982. popupMenuCollection.insert( m_paCut );
  3983. popupMenuCollection.insert( m_paCopy );
  3984. popupMenuCollection.insert( m_paPaste );
  3985. popupMenuCollection.insert( m_paTrash );
  3986. popupMenuCollection.insert( m_paRename );
  3987. popupMenuCollection.insert( m_paDelete );
  3988. // The pasteto action is used when clicking on a dir, to paste into it.
  3989. TDEAction *actPaste = KStdAction::paste( TQT_TQOBJECT(this), TQT_SLOT( slotPopupPasteTo() ), &popupMenuCollection, "pasteto" );
  3990. actPaste->setEnabled( m_paPaste->isEnabled() );
  3991. popupMenuCollection.insert( actPaste );
  3992. bool sReading = false;
  3993. if ( _items.count() > 0 )
  3994. {
  3995. m_popupURL = _items.getFirst()->url();
  3996. sReading = KProtocolInfo::supportsReading( m_popupURL );
  3997. if (sReading)
  3998. m_popupServiceType = _items.getFirst()->mimetype();
  3999. }
  4000. else
  4001. {
  4002. m_popupURL = KURL();
  4003. m_popupServiceType = TQString::null;
  4004. }
  4005. if ( (_items.count() == 1) && !m_popupServiceType.isEmpty() ) {
  4006. TQString currentServiceName = currentView->service()->desktopEntryName();
  4007. // List of services for the "Preview In" submenu.
  4008. m_popupEmbeddingServices = TDETrader::self()->query(
  4009. m_popupServiceType,
  4010. "KParts/ReadOnlyPart",
  4011. // Obey "HideFromMenus". It defaults to false so we want "absent or true"
  4012. // (wow, testing for 'true' if absent doesn't work, so order matters)
  4013. "(not exist [X-TDE-BrowserView-HideFromMenus] or not [X-TDE-BrowserView-HideFromMenus]) "
  4014. "and DesktopEntryName != '"+currentServiceName+"' "
  4015. // I had an old local dirtree.desktop without lib, no need for invalid entries
  4016. "and exist [Library]",
  4017. TQString::null );
  4018. }
  4019. // Don't set the view URL for a toggle view.
  4020. // (This is a bit of a hack for the directory tree....)
  4021. // ## should use the new currentView->isHierarchicalView() instead?
  4022. // Would this be correct for the konqlistview tree view?
  4023. KURL viewURL = currentView->isToggleView() ? KURL() : currentView->url();
  4024. bool openedForViewURL = false;
  4025. //bool dirsSelected = false;
  4026. bool devicesFile = false;
  4027. if ( _items.count() == 1 )
  4028. {
  4029. KURL firstURL = _items.getFirst()->url();
  4030. if ( !viewURL.isEmpty() )
  4031. {
  4032. //firstURL.cleanPath();
  4033. openedForViewURL = firstURL.equals( viewURL, true );
  4034. }
  4035. devicesFile = firstURL.protocol().find("device", 0, false) == 0;
  4036. //dirsSelected = S_ISDIR( _items.getFirst()->mode() );
  4037. }
  4038. //check if current url is trash
  4039. KURL url = viewURL;
  4040. url.cleanPath();
  4041. bool isIntoTrash = url.protocol() == "trash" || url.url().startsWith( "system:/trash" );
  4042. bool doTabHandling = !openedForViewURL && !isIntoTrash && sReading;
  4043. bool showEmbeddingServices = !isIntoTrash && !devicesFile && (itemFlags & KParts::BrowserExtension::ShowTextSelectionItems) == 0;
  4044. PopupMenuGUIClient *konqyMenuClient = new PopupMenuGUIClient( this, m_popupEmbeddingServices,
  4045. showEmbeddingServices, doTabHandling );
  4046. //kdDebug(1202) << "KonqMainWindow::slotPopupMenu " << viewURL.prettyURL() << endl;
  4047. // Those actions go into the PopupMenuGUIClient, since that's the one defining them.
  4048. TDEAction *actNewWindow = 0L;
  4049. if (doTabHandling)
  4050. {
  4051. if (_args.forcesNewWindow()) {
  4052. actNewWindow = new TDEAction( i18n( "Open in T&his Window" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupThisWindow() ), konqyMenuClient->actionCollection(), "sameview" );
  4053. actNewWindow->setToolTip( i18n( "Open the document in current window" ) );
  4054. }
  4055. actNewWindow = new TDEAction( i18n( "Open in New &Window" ), "window-new", 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupNewWindow() ), konqyMenuClient->actionCollection(), "newview" );
  4056. actNewWindow->setToolTip( i18n( "Open the document in a new window" ) );
  4057. //Set tab_new_x to point to the correct icon based on NewTabsInFront
  4058. bool newtabsinfront = KonqSettings::newTabsInFront();
  4059. TQString tab_new_x ;
  4060. if ( newtabsinfront )
  4061. tab_new_x = "tab_new" ;
  4062. else
  4063. tab_new_x = "tab_new_bg" ;
  4064. TDEAction *actNewTab = new TDEAction( i18n( "Open in &Background Tab" ), "tab_new_bg", 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupNewTab() ), actionCollection(), "openintab" );
  4065. actNewTab->setStatusText( i18n( "Open the document in a new background tab" ) );
  4066. TDEAction *actNewTabFront = new TDEAction( i18n( "Open in &New Tab" ), "tab_new", 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupNewTabAtFront() ), actionCollection(), "openintabfront" );
  4067. actNewTabFront->setStatusText( i18n( "Open the document in a new foreground tab" ) );
  4068. actNewTab = new TDEAction( i18n( "Open in &Background Tab" ), tab_new_x, 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupNewTab() ), konqyMenuClient->actionCollection(), "openintab" );
  4069. actNewTabFront = new TDEAction( i18n( "Open in &New Tab" ), tab_new_x, 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupNewTabAtFront() ), konqyMenuClient->actionCollection(), "openintabfront" );
  4070. actNewTab->setToolTip( i18n( "Open the document in a new background tab" ) );
  4071. actNewTabFront->setToolTip( i18n( "Open the document in a new foreground tab" ) );
  4072. doTabHandling = true;
  4073. }
  4074. if (currentView->isHierarchicalView())
  4075. itemFlags |= KParts::BrowserExtension::ShowCreateDirectory;
  4076. KonqPopupMenu::KonqPopupFlags kpf = 0;
  4077. if ( showProperties )
  4078. kpf |= KonqPopupMenu::ShowProperties;
  4079. else
  4080. kpf |= KonqPopupMenu::IsLink; // HACK
  4081. TQGuardedPtr<KonqPopupMenu> pPopupMenu = new KonqPopupMenu(
  4082. KonqBookmarkManager::self(), _items,
  4083. viewURL,
  4084. popupMenuCollection,
  4085. m_pMenuNew,
  4086. // This parent ensures that if the part destroys itself (e.g. TDEHTML redirection),
  4087. // it will close the popupmenu
  4088. currentView->part()->widget(),
  4089. kpf,
  4090. itemFlags );
  4091. if ( openedForViewURL && !viewURL.isLocalFile() )
  4092. pPopupMenu->setURLTitle( currentView->caption() );
  4093. // We will need these if we call the newTab slot
  4094. popupItems = _items;
  4095. popupUrlArgs = _args;
  4096. popupUrlArgs.serviceType = TQString::null; // Reset so that Open in New Window/Tab does mimetype detection
  4097. connectActionCollection( pPopupMenu->actionCollection() );
  4098. pPopupMenu->factory()->addClient( konqyMenuClient );
  4099. if ( client )
  4100. pPopupMenu->factory()->addClient( client );
  4101. KParts::BrowserExtension *be = ::tqqt_cast<KParts::BrowserExtension *>(sender());
  4102. if ( be )
  4103. {
  4104. TQObject::connect( this, TQT_SIGNAL(popupItemsDisturbed()), pPopupMenu, TQT_SLOT(close()) );
  4105. TQObject::connect( be, TQT_SIGNAL(itemsRemoved(const KFileItemList &)),
  4106. this, TQT_SLOT(slotItemsRemoved(const KFileItemList &)) );
  4107. }
  4108. TQObject::disconnect( m_pMenuNew->popupMenu(), TQT_SIGNAL(aboutToShow()),
  4109. this, TQT_SLOT(slotFileNewAboutToShow()) );
  4110. TQGuardedPtr<TQObject> guard(TQT_TQOBJECT(this)); // #149736
  4111. pPopupMenu->exec( _global );
  4112. delete pPopupMenu;
  4113. // We're sort of misusing TDEActionCollection here, but we need it for the actionStatusText signal...
  4114. // Anyway. If the action belonged to the view, and the view got deleted, we don't want ~TDEActionCollection
  4115. // to iterate over those deleted actions
  4116. TDEActionPtrList lst = popupMenuCollection.actions();
  4117. TDEActionPtrList::iterator it = lst.begin();
  4118. for ( ; it != lst.end() ; ++it )
  4119. popupMenuCollection.take( *it );
  4120. if (guard.isNull()) { // the placement of this test is very important, double-check #149736 if moving stuff around
  4121. return;
  4122. }
  4123. TQObject::connect( m_pMenuNew->popupMenu(), TQT_SIGNAL(aboutToShow()),
  4124. this, TQT_SLOT(slotFileNewAboutToShow()) );
  4125. if ( be )
  4126. {
  4127. TQObject::disconnect( be, TQT_SIGNAL(itemsRemoved(const KFileItemList &)),
  4128. this, TQT_SLOT(slotItemsRemoved(const KFileItemList &)) );
  4129. }
  4130. delete konqyMenuClient;
  4131. m_popupEmbeddingServices.clear();
  4132. popupItems.clear();
  4133. // Deleted by konqyMenuClient's actioncollection
  4134. //delete actNewWindow;
  4135. delete actPaste;
  4136. //kdDebug(1202) << "-------- KonqMainWindow::slotPopupMenu() - m_oldView = " << m_oldView << ", currentView = " << currentView
  4137. //<< ", m_currentView = " << m_currentView << endl;
  4138. // Restore current view if current is passive
  4139. if ( (m_oldView != currentView) && (currentView == m_currentView) && currentView->isPassiveMode() )
  4140. {
  4141. //kdDebug() << "KonqMainWindow::slotPopupMenu restoring active view " << m_oldView << endl;
  4142. if ( m_currentView->browserExtension() )
  4143. disconnectExtension( m_currentView->browserExtension() );
  4144. if ( m_oldView )
  4145. {
  4146. if ( m_oldView->browserExtension() )
  4147. {
  4148. connectExtension( m_oldView->browserExtension() );
  4149. m_currentView = m_oldView;
  4150. }
  4151. // Special case: RMB + renaming in sidebar; setFocus would abort editing.
  4152. TQWidget* fw = focusWidget();
  4153. if ( !fw || !::tqqt_cast<TQLineEdit*>( fw ) )
  4154. m_oldView->part()->widget()->setFocus();
  4155. }
  4156. }
  4157. }
  4158. void KonqMainWindow::slotItemsRemoved( const KFileItemList &items )
  4159. {
  4160. TQPtrListIterator<KFileItem> it( items );
  4161. for ( ; it.current(); ++it )
  4162. {
  4163. if ( popupItems.contains( it.current() ) )
  4164. {
  4165. emit popupItemsDisturbed();
  4166. return;
  4167. }
  4168. }
  4169. }
  4170. void KonqMainWindow::slotOpenEmbedded()
  4171. {
  4172. TQCString name = TQT_TQOBJECT_CONST(sender())->name();
  4173. m_popupService = m_popupEmbeddingServices[ name.toInt() ]->desktopEntryName();
  4174. m_popupEmbeddingServices.clear();
  4175. TQTimer::singleShot( 0, this, TQT_SLOT( slotOpenEmbeddedDoIt() ) );
  4176. }
  4177. void KonqMainWindow::slotOpenEmbeddedDoIt()
  4178. {
  4179. m_currentView->stop();
  4180. m_currentView->setLocationBarURL(m_popupURL);
  4181. m_currentView->setTypedURL(TQString::null);
  4182. if ( m_currentView->changeViewMode( m_popupServiceType,
  4183. m_popupService ) )
  4184. m_currentView->openURL( m_popupURL, m_popupURL.pathOrURL() );
  4185. }
  4186. void KonqMainWindow::slotDatabaseChanged()
  4187. {
  4188. if ( KSycoca::isChanged("mimetypes") )
  4189. {
  4190. MapViews::ConstIterator it = m_mapViews.begin();
  4191. MapViews::ConstIterator end = m_mapViews.end();
  4192. for (; it != end; ++it )
  4193. (*it)->callExtensionMethod( "refreshMimeTypes()" );
  4194. }
  4195. }
  4196. void KonqMainWindow::slotPopupPasteTo()
  4197. {
  4198. if ( !m_currentView || m_popupURL.isEmpty() )
  4199. return;
  4200. m_currentView->callExtensionURLMethod( "pasteTo(const KURL&)", m_popupURL );
  4201. }
  4202. void KonqMainWindow::slotReconfigure()
  4203. {
  4204. reparseConfiguration();
  4205. }
  4206. void KonqMainWindow::reparseConfiguration()
  4207. {
  4208. kdDebug(1202) << "KonqMainWindow::reparseConfiguration() !" << endl;
  4209. KonqSettings::self()->readConfig();
  4210. m_bSaveViewPropertiesLocally = KonqSettings::saveViewPropertiesLocally();
  4211. m_bHTMLAllowed = KonqSettings::htmlAllowed();
  4212. MapViews::ConstIterator it = m_mapViews.begin();
  4213. MapViews::ConstIterator end = m_mapViews.end();
  4214. for (; it != end; ++it )
  4215. (*it)->reparseConfiguration();
  4216. // Push updates to KonqViewManager as well
  4217. viewManager()->reparseConfiguration();
  4218. }
  4219. void KonqMainWindow::saveProperties( TDEConfig *config )
  4220. {
  4221. m_pViewManager->saveViewProfile( *config, true /* save URLs */, false );
  4222. }
  4223. void KonqMainWindow::readProperties( TDEConfig *config )
  4224. {
  4225. kdDebug(1202) << "KonqMainWindow::readProperties( TDEConfig *config )" << endl;
  4226. m_pViewManager->loadViewProfile( *config, TQString::null /*no profile name*/ );
  4227. }
  4228. void KonqMainWindow::setInitialFrameName( const TQString &name )
  4229. {
  4230. m_initialFrameName = name;
  4231. }
  4232. void KonqMainWindow::slotActionStatusText( const TQString &text )
  4233. {
  4234. if ( !m_currentView )
  4235. return;
  4236. KonqFrameStatusBar *statusBar = m_currentView->frame()->statusbar();
  4237. if ( !statusBar )
  4238. return;
  4239. statusBar->message( text );
  4240. }
  4241. void KonqMainWindow::slotClearStatusText()
  4242. {
  4243. if ( !m_currentView )
  4244. return;
  4245. KonqFrameStatusBar *statusBar = m_currentView->frame()->statusbar();
  4246. if ( !statusBar )
  4247. return;
  4248. statusBar->slotClear();
  4249. }
  4250. void KonqMainWindow::updateOpenWithActions()
  4251. {
  4252. unplugActionList( "openwith" );
  4253. m_openWithActions.clear();
  4254. if (!kapp->authorizeTDEAction("openwith"))
  4255. return;
  4256. const TDETrader::OfferList & services = m_currentView->appServiceOffers();
  4257. TDETrader::OfferList::ConstIterator it = services.begin();
  4258. TDETrader::OfferList::ConstIterator end = services.end();
  4259. for (; it != end; ++it )
  4260. {
  4261. TDEAction *action = new TDEAction( i18n( "Open with %1" ).arg( (*it)->name() ), 0, 0, (*it)->desktopEntryName().latin1() );
  4262. action->setIcon( (*it)->icon() );
  4263. connect( action, TQT_SIGNAL( activated() ),
  4264. this, TQT_SLOT( slotOpenWith() ) );
  4265. m_openWithActions.append( action );
  4266. }
  4267. if ( services.count() > 0 )
  4268. {
  4269. m_openWithActions.append( new TDEActionSeparator );
  4270. plugActionList( "openwith", m_openWithActions );
  4271. }
  4272. }
  4273. TQString KonqMainWindow::viewModeActionKey( KService::Ptr service )
  4274. {
  4275. TQString library = service->library();
  4276. // Group all non-builtin views together
  4277. TQVariant builtIntoProp = service->property( "X-TDE-BrowserView-Built-Into" );
  4278. if ( !builtIntoProp.isValid() || builtIntoProp.toString() != "konqueror" )
  4279. library = "external";
  4280. return library;
  4281. }
  4282. void KonqMainWindow::updateViewModeActions()
  4283. {
  4284. unplugViewModeActions();
  4285. if ( m_viewModeMenu )
  4286. {
  4287. TQPtrListIterator<TDERadioAction> it( m_viewModeActions );
  4288. for (; it.current(); ++it )
  4289. it.current()->unplugAll();
  4290. delete m_viewModeMenu;
  4291. }
  4292. m_viewModeMenu = 0;
  4293. m_toolBarViewModeActions.clear();
  4294. m_viewModeActions.clear();
  4295. // if we changed the viewmode to something new, then we have to
  4296. // make sure to also clear our [libiconview,liblistview]->service-for-viewmode
  4297. // map
  4298. if ( m_viewModeToolBarServices.count() > 0 &&
  4299. !m_viewModeToolBarServices.begin().data()->serviceTypes().contains( m_currentView->serviceType() ) )
  4300. {
  4301. // Save the current map to the config file, for later reuse
  4302. saveToolBarServicesMap();
  4303. m_viewModeToolBarServices.clear();
  4304. }
  4305. TDETrader::OfferList services = m_currentView->partServiceOffers();
  4306. if ( services.count() <= 1 )
  4307. return;
  4308. m_viewModeMenu = new TDEActionMenu( i18n( "&View Mode" ), TQT_TQOBJECT(this) );
  4309. // a temporary map, just like the m_viewModeToolBarServices map, but
  4310. // mapping to a KonqViewModeAction object. It's just temporary as we
  4311. // of use it to group the viewmode actions (iconview,multicolumnview,
  4312. // treeview, etc.) into to two groups -> icon/list
  4313. // Although I wrote this now only of icon/listview it has to work for
  4314. // any view, that's why it's so general :)
  4315. TQMap<TQString,KonqViewModeAction*> groupedServiceMap;
  4316. // Another temporary map, the preferred service for each library (2 entries in our example)
  4317. TQMap<TQString,TQString> preferredServiceMap;
  4318. TDEConfig * config = TDEGlobal::config();
  4319. config->setGroup( "ModeToolBarServices" );
  4320. TDETrader::OfferList::ConstIterator it = services.begin();
  4321. TDETrader::OfferList::ConstIterator end = services.end();
  4322. for (; it != end; ++it )
  4323. {
  4324. TQVariant prop = (*it)->property( "X-TDE-BrowserView-Toggable" );
  4325. if ( prop.isValid() && prop.toBool() ) // No toggable views in view mode
  4326. continue;
  4327. TDERadioAction *action;
  4328. TQString itname = (*it)->genericName();
  4329. if (itname.isEmpty())
  4330. itname = (*it)->name();
  4331. TQString icon = (*it)->icon();
  4332. if ( icon != TQString::fromLatin1( "unknown" ) )
  4333. // we *have* to specify a parent qobject, otherwise the exclusive group stuff doesn't work!(Simon)
  4334. action = new TDERadioAction( itname, icon, 0, TQT_TQOBJECT(this), (*it)->desktopEntryName().ascii() );
  4335. else
  4336. action = new TDERadioAction( itname, 0, TQT_TQOBJECT(this), (*it)->desktopEntryName().ascii() );
  4337. action->setExclusiveGroup( "KonqMainWindow_ViewModes" );
  4338. connect( action, TQT_SIGNAL( toggled( bool ) ),
  4339. this, TQT_SLOT( slotViewModeToggle( bool ) ) );
  4340. m_viewModeActions.append( action );
  4341. action->plug( m_viewModeMenu->popupMenu() );
  4342. const TQString library = viewModeActionKey( *it );
  4343. // look if we already have a KonqViewModeAction (in the toolbar)
  4344. // for this component
  4345. TQMap<TQString,KonqViewModeAction*>::Iterator mapIt = groupedServiceMap.find( library );
  4346. // if we don't have -> create one
  4347. if ( mapIt == groupedServiceMap.end() )
  4348. {
  4349. // default service on this action: the current one (i.e. the first one)
  4350. TQString text = itname;
  4351. TQString icon = (*it)->icon();
  4352. TQCString name = (*it)->desktopEntryName().latin1();
  4353. //kdDebug(1202) << " Creating action for " << library << ". Default service " << itname << endl;
  4354. // if we previously changed the viewmode (see slotViewModeToggle!)
  4355. // then we will want to use the previously used settings (previous as
  4356. // in before the actions got deleted)
  4357. TQMap<TQString,KService::Ptr>::ConstIterator serviceIt = m_viewModeToolBarServices.find( library );
  4358. if ( serviceIt != m_viewModeToolBarServices.end() )
  4359. {
  4360. kdDebug(1202) << " Setting action for " << library << " to " << (*serviceIt)->name() << endl;
  4361. text = (*serviceIt)->genericName();
  4362. if (text.isEmpty())
  4363. text = (*serviceIt)->name();
  4364. icon = (*serviceIt)->icon();
  4365. name = (*serviceIt)->desktopEntryName().ascii();
  4366. } else
  4367. {
  4368. // if we don't have it in the map, we should look for a setting
  4369. // for this library in the config file.
  4370. TQString preferredService = config->readEntry( library );
  4371. if ( !preferredService.isEmpty() && name != preferredService.latin1() )
  4372. {
  4373. //kdDebug(1202) << " Inserting into preferredServiceMap(" << library << ") : " << preferredService << endl;
  4374. // The preferred service isn't the current one, so remember to set it later
  4375. preferredServiceMap[ library ] = preferredService;
  4376. }
  4377. }
  4378. KonqViewModeAction *tbAction = new KonqViewModeAction( text,
  4379. icon,
  4380. TQT_TQOBJECT(this),
  4381. name );
  4382. tbAction->setExclusiveGroup( "KonqMainWindow_ToolBarViewModes" );
  4383. tbAction->setChecked( action->isChecked() );
  4384. connect( tbAction, TQT_SIGNAL( toggled( bool ) ),
  4385. this, TQT_SLOT( slotViewModeToggle( bool ) ) );
  4386. m_toolBarViewModeActions.append( tbAction );
  4387. mapIt = groupedServiceMap.insert( library, tbAction );
  4388. }
  4389. // Check the actions (toolbar button and menu item) if they correspond to the current view
  4390. bool bIsCurrentView = (*it)->desktopEntryName() == m_currentView->service()->desktopEntryName();
  4391. if ( bIsCurrentView )
  4392. {
  4393. action->setChecked( true );
  4394. }
  4395. // Set the contents of the button from the current service, either if it's the current view
  4396. // or if it's our preferred service for this button (library)
  4397. if ( bIsCurrentView
  4398. || ( preferredServiceMap.contains( library ) && (*it)->desktopEntryName() == preferredServiceMap[ library ] ) )
  4399. {
  4400. //kdDebug(1202) << " Changing action for " << library << " into service " << (*it)->name() << endl;
  4401. TQString mapitname = (*it)->genericName();
  4402. if (mapitname.isEmpty())
  4403. mapitname = (*it)->name();
  4404. (*mapIt)->setText( mapitname );
  4405. (*mapIt)->setIcon( (*it)->icon() );
  4406. (*mapIt)->setName( (*it)->desktopEntryName().ascii() ); // tricky...
  4407. preferredServiceMap.remove( library ); // The current view has priority over the saved settings
  4408. }
  4409. // plug action also into the delayed popupmenu of appropriate toolbar action
  4410. action->plug( (*mapIt)->popupMenu() );
  4411. }
  4412. #ifndef NDEBUG
  4413. // Note that this can happen (map not empty) when a inode/directory view is removed,
  4414. // and remains in the TDEConfig file.
  4415. Q_ASSERT( preferredServiceMap.isEmpty() );
  4416. TQMap<TQString,TQString>::Iterator debugIt = preferredServiceMap.begin();
  4417. TQMap<TQString,TQString>::Iterator debugEnd = preferredServiceMap.end();
  4418. for ( ; debugIt != debugEnd ; ++debugIt )
  4419. kdDebug(1202) << " STILL IN preferredServiceMap : " << debugIt.key() << " | " << debugIt.data() << endl;
  4420. #endif
  4421. if ( !m_currentView->isToggleView() ) // No view mode for toggable views
  4422. // (The other way would be to enforce a better servicetype for them, than Browser/View)
  4423. if ( /* already tested: services.count() > 1 && */ m_viewModeMenu )
  4424. plugViewModeActions();
  4425. }
  4426. void KonqMainWindow::saveToolBarServicesMap()
  4427. {
  4428. TQMap<TQString,KService::Ptr>::ConstIterator serviceIt = m_viewModeToolBarServices.begin();
  4429. TQMap<TQString,KService::Ptr>::ConstIterator serviceEnd = m_viewModeToolBarServices.end();
  4430. TDEConfig * config = TDEGlobal::config();
  4431. config->setGroup( "ModeToolBarServices" );
  4432. for ( ; serviceIt != serviceEnd ; ++serviceIt )
  4433. config->writeEntry( serviceIt.key(), serviceIt.data()->desktopEntryName() );
  4434. config->sync();
  4435. }
  4436. void KonqMainWindow::plugViewModeActions()
  4437. {
  4438. TQPtrList<TDEAction> lst;
  4439. lst.append( m_viewModeMenu );
  4440. plugActionList( "viewmode", lst );
  4441. // display the toolbar viewmode icons only for inode/directory, as here we have dedicated icons
  4442. if ( m_currentView && m_currentView->supportsServiceType( "inode/directory" ) )
  4443. plugActionList( "viewmode_toolbar", m_toolBarViewModeActions );
  4444. }
  4445. void KonqMainWindow::unplugViewModeActions()
  4446. {
  4447. unplugActionList( "viewmode" );
  4448. unplugActionList( "viewmode_toolbar" );
  4449. }
  4450. KonqMainWindowIface* KonqMainWindow::dcopObject()
  4451. {
  4452. return m_dcopObject;
  4453. }
  4454. void KonqMainWindow::updateBookmarkBar()
  4455. {
  4456. TDEToolBar * bar = static_cast<TDEToolBar *>( TQT_TQWIDGET(child( "bookmarkToolBar", "TDEToolBar" )) );
  4457. if (!bar) return;
  4458. // hide if empty
  4459. if (m_paBookmarkBar && bar->count() == 0 )
  4460. bar->hide();
  4461. }
  4462. void KonqMainWindow::closeEvent( TQCloseEvent *e )
  4463. {
  4464. kdDebug(1202) << "KonqMainWindow::closeEvent begin" << endl;
  4465. // This breaks session management (the window is withdrawn in twin)
  4466. // so let's do this only when closed by the user.
  4467. if ( static_cast<KonquerorApplication *>(kapp)->closedByUser() )
  4468. {
  4469. if ( viewManager()->docContainer() && viewManager()->docContainer()->frameType()=="Tabs" )
  4470. {
  4471. KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(viewManager()->docContainer());
  4472. if ( tabContainer->count() > 1 )
  4473. {
  4474. TDEConfig *config = TDEGlobal::config();
  4475. TDEConfigGroupSaver cs( config, TQString::fromLatin1("Notification Messages") );
  4476. if ( !config->hasKey( "MultipleTabConfirm" ) )
  4477. {
  4478. switch (
  4479. KMessageBox::warningYesNoCancel(
  4480. this,
  4481. i18n("You have multiple tabs open in this window, "
  4482. "are you sure you want to quit?"),
  4483. i18n("Confirmation"),
  4484. KStdGuiItem::quit(),
  4485. KGuiItem(i18n( "C&lose Current Tab" ), "tab_remove"),
  4486. "MultipleTabConfirm"
  4487. )
  4488. ) {
  4489. case KMessageBox::Yes :
  4490. break;
  4491. case KMessageBox::No :
  4492. {
  4493. e->ignore();
  4494. slotRemoveTab();
  4495. return;
  4496. }
  4497. break;
  4498. case KMessageBox::Cancel :
  4499. {
  4500. e->ignore();
  4501. return;
  4502. }
  4503. }
  4504. }
  4505. }
  4506. KonqView *originalView = m_currentView;
  4507. MapViews::ConstIterator it = m_mapViews.begin();
  4508. MapViews::ConstIterator end = m_mapViews.end();
  4509. for (; it != end; ++it ) {
  4510. KonqView *view = it.data();
  4511. if (view && view->part() && (view->part()->metaObject()->findProperty("modified") != -1) ) {
  4512. TQVariant prop = view->part()->property("modified");
  4513. if (prop.isValid() && prop.toBool()) {
  4514. m_pViewManager->showTab( view );
  4515. if ( KMessageBox::warningContinueCancel( this,
  4516. i18n("This tab contains changes that have not been submitted.\nClosing the window will discard these changes."),
  4517. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"system-log-out"), "discardchangesclose") != KMessageBox::Continue )
  4518. {
  4519. e->ignore();
  4520. m_pViewManager->showTab( originalView );
  4521. return;
  4522. }
  4523. }
  4524. }
  4525. }
  4526. // m_pViewManager->showTab( originalView );
  4527. }
  4528. else if ( m_currentView && m_currentView->part() &&
  4529. (m_currentView->part()->metaObject()->findProperty("modified") != -1) )
  4530. {
  4531. TQVariant prop = m_currentView->part()->property("modified");
  4532. if (prop.isValid() && prop.toBool())
  4533. if ( KMessageBox::warningContinueCancel( this,
  4534. i18n("This page contains changes that have not been submitted.\nClosing the window will discard these changes."),
  4535. i18n("Discard Changes?"), KGuiItem(i18n("&Discard Changes"),"system-log-out"), "discardchangesclose") != KMessageBox::Continue )
  4536. {
  4537. e->ignore();
  4538. return;
  4539. }
  4540. }
  4541. // save size to have something to restore if the profile does not contain size
  4542. saveWindowSize();
  4543. hide();
  4544. tqApp->flushX();
  4545. }
  4546. // We're going to close - tell the parts
  4547. MapViews::ConstIterator it = m_mapViews.begin();
  4548. MapViews::ConstIterator end = m_mapViews.end();
  4549. for (; it != end; ++it )
  4550. {
  4551. if ( (*it)->part() && (*it)->part()->widget() )
  4552. TQApplication::sendEvent( (*it)->part()->widget(), e );
  4553. }
  4554. KParts::MainWindow::closeEvent( e );
  4555. if( isPreloaded() && !kapp->sessionSaving())
  4556. { // queryExit() refused closing, hide instead
  4557. hide();
  4558. }
  4559. kdDebug(1202) << "KonqMainWindow::closeEvent end" << endl;
  4560. }
  4561. bool KonqMainWindow::queryExit()
  4562. {
  4563. if( kapp->sessionSaving()) // *sigh*
  4564. return true;
  4565. return !stayPreloaded();
  4566. }
  4567. void KonqMainWindow::setIcon( const TQPixmap& pix )
  4568. {
  4569. KParts::MainWindow::setIcon( pix );
  4570. TQPixmap big = pix;
  4571. TQString url = m_combo->currentText();
  4572. if ( !url.isEmpty() )
  4573. big = KonqPixmapProvider::self()->pixmapFor( url, TDEIcon::SizeMedium );
  4574. KWin::setIcons( winId(), big, pix );
  4575. }
  4576. void KonqMainWindow::slotIntro()
  4577. {
  4578. openURL( 0L, KURL("about:konqueror") );
  4579. }
  4580. void KonqMainWindow::goURL()
  4581. {
  4582. TQLineEdit *lineEdit = m_combo->lineEdit();
  4583. if ( !lineEdit )
  4584. return;
  4585. TQKeyEvent event( TQEvent::KeyPress, Key_Return, '\n', 0 );
  4586. TQApplication::sendEvent( lineEdit, &event );
  4587. }
  4588. void KonqMainWindow::slotLocationLabelActivated()
  4589. {
  4590. focusLocationBar();
  4591. m_combo->lineEdit()->selectAll();
  4592. }
  4593. void KonqMainWindow::slotOpenURL( const KURL& url )
  4594. {
  4595. openURL( 0L, url );
  4596. }
  4597. bool KonqMainWindow::sidebarVisible() const
  4598. {
  4599. TDEAction *a = m_toggleViewGUIClient->action("konq_sidebartng");
  4600. return (a && static_cast<TDEToggleAction*>(a)->isChecked());
  4601. }
  4602. void KonqMainWindow::slotAddWebSideBar(const KURL& url, const TQString& name)
  4603. {
  4604. if (url.url().isEmpty() && name.isEmpty())
  4605. return;
  4606. kdDebug(1202) << "Requested to add URL " << url << " [" << name << "] to the sidebar!" << endl;
  4607. TDEAction *a = m_toggleViewGUIClient->action("konq_sidebartng");
  4608. if (!a) {
  4609. KMessageBox::sorry(0L, i18n("Your sidebar is not functional or unavailable. A new entry cannot be added."), i18n("Web Sidebar"));
  4610. return;
  4611. }
  4612. int rc = KMessageBox::questionYesNo(0L,
  4613. i18n("Add new web extension \"%1\" to your sidebar?")
  4614. .arg(name.isEmpty() ? name : url.prettyURL()),
  4615. i18n("Web Sidebar"),i18n("Add"),i18n("Do Not Add"));
  4616. if (rc == KMessageBox::Yes) {
  4617. // Show the sidebar
  4618. if (!static_cast<TDEToggleAction*>(a)->isChecked()) {
  4619. a->activate();
  4620. }
  4621. // Tell it to add a new panel
  4622. MapViews::ConstIterator it;
  4623. for (it = viewMap().begin(); it != viewMap().end(); ++it) {
  4624. KonqView *view = it.data();
  4625. if (view) {
  4626. KService::Ptr svc = view->service();
  4627. if (svc->desktopEntryName() == "konq_sidebartng") {
  4628. emit view->browserExtension()->addWebSideBar(url, name);
  4629. break;
  4630. }
  4631. }
  4632. }
  4633. }
  4634. }
  4635. void KonqMainWindow::bookmarksIntoCompletion( const KBookmarkGroup& group )
  4636. {
  4637. static const TQString& http = TDEGlobal::staticQString( "http" );
  4638. static const TQString& ftp = TDEGlobal::staticQString( "ftp" );
  4639. if ( group.isNull() )
  4640. return;
  4641. for ( KBookmark bm = group.first();
  4642. !bm.isNull(); bm = group.next(bm) ) {
  4643. if ( bm.isGroup() ) {
  4644. bookmarksIntoCompletion( bm.toGroup() );
  4645. continue;
  4646. }
  4647. KURL url = bm.url();
  4648. if ( !url.isValid() )
  4649. continue;
  4650. TQString u = url.prettyURL();
  4651. s_pCompletion->addItem( u );
  4652. if ( url.isLocalFile() )
  4653. s_pCompletion->addItem( url.path() );
  4654. else if ( url.protocol() == http )
  4655. s_pCompletion->addItem( u.mid( 7 ));
  4656. else if ( url.protocol() == ftp &&
  4657. url.host().startsWith( ftp ) )
  4658. s_pCompletion->addItem( u.mid( 6 ) );
  4659. }
  4660. }
  4661. void KonqMainWindow::connectActionCollection( TDEActionCollection *coll )
  4662. {
  4663. connect( coll, TQT_SIGNAL( actionStatusText( const TQString & ) ),
  4664. this, TQT_SLOT( slotActionStatusText( const TQString & ) ) );
  4665. connect( coll, TQT_SIGNAL( clearStatusText() ),
  4666. this, TQT_SLOT( slotClearStatusText() ) );
  4667. }
  4668. void KonqMainWindow::disconnectActionCollection( TDEActionCollection *coll )
  4669. {
  4670. disconnect( coll, TQT_SIGNAL( actionStatusText( const TQString & ) ),
  4671. this, TQT_SLOT( slotActionStatusText( const TQString & ) ) );
  4672. disconnect( coll, TQT_SIGNAL( clearStatusText() ),
  4673. this, TQT_SLOT( slotClearStatusText() ) );
  4674. }
  4675. //
  4676. // the smart popup completion code , <l.lunak@kde.org>
  4677. //
  4678. // prepend http://www. or http:// if there's no protocol in 's'
  4679. // used only when there are no completion matches
  4680. static TQString hp_tryPrepend( const TQString& s )
  4681. {
  4682. if( s.isEmpty() || s[ 0 ] == '/' )
  4683. return TQString::null;
  4684. for( unsigned int pos = 0;
  4685. pos < s.length() - 2; // 4 = ://x
  4686. ++pos )
  4687. {
  4688. if( s[ pos ] == ':' && s[ pos + 1 ] == '/' && s[ pos + 2 ] == '/' )
  4689. return TQString::null;
  4690. if( !s[ pos ].isLetter() )
  4691. break;
  4692. }
  4693. return ( s.startsWith( "www." ) ? "http://" : "http://www." ) + s;
  4694. }
  4695. static void hp_removeDupe( TDECompletionMatches& l, const TQString& dupe,
  4696. TDECompletionMatches::Iterator it_orig )
  4697. {
  4698. for( TDECompletionMatches::Iterator it = l.begin();
  4699. it != l.end();
  4700. ) {
  4701. if( it == it_orig ) {
  4702. ++it;
  4703. continue;
  4704. }
  4705. if( (*it).value() == dupe ) {
  4706. (*it_orig).first = kMax( (*it_orig).first, (*it).index());
  4707. it = l.remove( it );
  4708. continue;
  4709. }
  4710. ++it;
  4711. }
  4712. }
  4713. // remove duplicates like 'http://www.kde.org' and 'http://www.kde.org/'
  4714. // (i.e. the trailing slash)
  4715. // some duplicates are also created by prepending protocols
  4716. static void hp_removeDuplicates( TDECompletionMatches& l )
  4717. {
  4718. TQString http = "http://";
  4719. TQString ftp = "ftp://ftp.";
  4720. TQString file = "file:";
  4721. TQString file2 = "file://";
  4722. l.removeDuplicates();
  4723. for( TDECompletionMatches::Iterator it = l.begin();
  4724. it != l.end();
  4725. ++it ) {
  4726. TQString str = (*it).value();
  4727. if( str.startsWith( http )) {
  4728. if( str.find( '/', 7 ) < 0 ) { // http://something<noslash>
  4729. hp_removeDupe( l, str + '/', it );
  4730. hp_removeDupe( l, str.mid( 7 ) + '/', it );
  4731. } else if( str[ str.length() - 1 ] == '/' ) {
  4732. hp_removeDupe( l, str.left( str.length() - 1 ), it );
  4733. hp_removeDupe( l, str.left( str.length() - 1 ).mid( 7 ), it );
  4734. }
  4735. hp_removeDupe( l, str.mid( 7 ), it );
  4736. }
  4737. else if( str.startsWith( ftp )) // ftp://ftp.
  4738. hp_removeDupe( l, str.mid( 6 ), it ); // remove dupes without ftp://
  4739. else if( str.startsWith( file2 ))
  4740. hp_removeDupe( l, str.mid( 7 ), it ); // remove dupes without file://
  4741. else if( str.startsWith( file ))
  4742. hp_removeDupe( l, str.mid( 5 ), it ); // remove dupes without file:
  4743. }
  4744. }
  4745. static void hp_removeCommonPrefix( TDECompletionMatches& l, const TQString& prefix )
  4746. {
  4747. for( TDECompletionMatches::Iterator it = l.begin();
  4748. it != l.end();
  4749. ) {
  4750. if( (*it).value().startsWith( prefix )) {
  4751. it = l.remove( it );
  4752. continue;
  4753. }
  4754. ++it;
  4755. }
  4756. }
  4757. // don't include common prefixes like 'http://', i.e. when s == 'h', include
  4758. // http://hotmail.com but don't include everything just starting with 'http://'
  4759. static void hp_checkCommonPrefixes( TDECompletionMatches& matches, const TQString& s )
  4760. {
  4761. static const char* const prefixes[] = {
  4762. "http://",
  4763. "https://",
  4764. "www.",
  4765. "ftp://",
  4766. "http://www.",
  4767. "https://www.",
  4768. "ftp://ftp.",
  4769. "file:",
  4770. "file://",
  4771. NULL };
  4772. for( const char* const *pos = prefixes;
  4773. *pos != NULL;
  4774. ++pos ) {
  4775. TQString prefix = *pos;
  4776. if( prefix.startsWith( s )) {
  4777. hp_removeCommonPrefix( matches, prefix );
  4778. }
  4779. }
  4780. }
  4781. TQStringList KonqMainWindow::historyPopupCompletionItems( const TQString& s)
  4782. {
  4783. const TQString http = "http://";
  4784. const TQString https = "https://";
  4785. const TQString www = "http://www.";
  4786. const TQString wwws = "https://www.";
  4787. const TQString ftp = "ftp://";
  4788. const TQString ftpftp = "ftp://ftp.";
  4789. const TQString file = "file:"; // without /, because people enter /usr etc.
  4790. const TQString file2 = "file://";
  4791. if( s.isEmpty())
  4792. return TQStringList();
  4793. TDECompletionMatches matches= s_pCompletion->allWeightedMatches( s );
  4794. hp_checkCommonPrefixes( matches, s );
  4795. bool checkDuplicates = false;
  4796. if ( !s.startsWith( ftp ) ) {
  4797. matches += s_pCompletion->allWeightedMatches( ftp + s );
  4798. if( TQString( "ftp." ).startsWith( s ))
  4799. hp_removeCommonPrefix( matches, ftpftp );
  4800. checkDuplicates = true;
  4801. }
  4802. if ( !s.startsWith( https ) ) {
  4803. matches += s_pCompletion->allWeightedMatches( https + s );
  4804. if( TQString( "www." ).startsWith( s ))
  4805. hp_removeCommonPrefix( matches, wwws );
  4806. checkDuplicates = true;
  4807. }
  4808. if ( !s.startsWith( http )) {
  4809. matches += s_pCompletion->allWeightedMatches( http + s );
  4810. if( TQString( "www." ).startsWith( s ))
  4811. hp_removeCommonPrefix( matches, www );
  4812. checkDuplicates = true;
  4813. }
  4814. if ( !s.startsWith( www ) ) {
  4815. matches += s_pCompletion->allWeightedMatches( www + s );
  4816. checkDuplicates = true;
  4817. }
  4818. if ( !s.startsWith( wwws ) ) {
  4819. matches += s_pCompletion->allWeightedMatches( wwws + s );
  4820. checkDuplicates = true;
  4821. }
  4822. if ( !s.startsWith( ftpftp ) ) {
  4823. matches += s_pCompletion->allWeightedMatches( ftpftp + s );
  4824. checkDuplicates = true;
  4825. }
  4826. if ( !s.startsWith( file ) ) {
  4827. matches += s_pCompletion->allWeightedMatches( file + s );
  4828. checkDuplicates = true;
  4829. }
  4830. if ( !s.startsWith( file2 ) ) {
  4831. matches += s_pCompletion->allWeightedMatches( file2 + s );
  4832. checkDuplicates = true;
  4833. }
  4834. if( checkDuplicates )
  4835. hp_removeDuplicates( matches );
  4836. TQStringList items = matches.list();
  4837. if( items.count() == 0
  4838. && !s.contains( ':' ) && s[ 0 ] != '/' )
  4839. {
  4840. TQString pre = hp_tryPrepend( s );
  4841. if( !pre.isNull())
  4842. items += pre;
  4843. }
  4844. return items;
  4845. }
  4846. #ifndef NDEBUG
  4847. void KonqMainWindow::dumpViewList()
  4848. {
  4849. MapViews::Iterator end = m_mapViews.end();
  4850. kdDebug(1202) << m_mapViews.count() << "Views" << endl;
  4851. for (MapViews::Iterator it = m_mapViews.begin(); it != end; it++)
  4852. {
  4853. kdDebug(1202) << it.data() << endl;
  4854. }
  4855. }
  4856. #endif
  4857. // KonqFrameContainerBase implementation BEGIN
  4858. /**
  4859. * Call this after inserting a new frame into the splitter.
  4860. */
  4861. void KonqMainWindow::insertChildFrame( KonqFrameBase * frame, int /*index*/ )
  4862. {
  4863. m_pChildFrame = frame;
  4864. m_pActiveChild = frame;
  4865. frame->setParentContainer(this);
  4866. setCentralWidget( frame->widget() );
  4867. }
  4868. /**
  4869. * Call this before deleting one of our children.
  4870. */
  4871. void KonqMainWindow::removeChildFrame( KonqFrameBase * /*frame*/ )
  4872. {
  4873. m_pChildFrame = 0L;
  4874. m_pActiveChild = 0L;
  4875. }
  4876. void KonqMainWindow::saveConfig( TDEConfig* config, const TQString &prefix, bool saveURLs, KonqFrameBase* docContainer, int id, int depth ) { if( m_pChildFrame ) m_pChildFrame->saveConfig( config, prefix, saveURLs, docContainer, id, depth); }
  4877. void KonqMainWindow::copyHistory( KonqFrameBase *other ) { if( m_pChildFrame ) m_pChildFrame->copyHistory( other ); }
  4878. void KonqMainWindow::printFrameInfo( const TQString &spaces ) { if( m_pChildFrame ) m_pChildFrame->printFrameInfo( spaces ); }
  4879. void KonqMainWindow::reparentFrame( TQWidget* /*parent*/,
  4880. const TQPoint & /*p*/, bool /*showIt*/ ) { return; }
  4881. KonqFrameContainerBase* KonqMainWindow::parentContainer()const { return 0L; }
  4882. void KonqMainWindow::setParentContainer(KonqFrameContainerBase* /*parent*/) { return; }
  4883. void KonqMainWindow::setTitle( const TQString &/*title*/ , TQWidget* /*sender*/) { return; }
  4884. void KonqMainWindow::setTabIcon( const KURL &/*url*/, TQWidget* /*sender*/ ) { return; }
  4885. TQWidget* KonqMainWindow::widget() { return this; }
  4886. void KonqMainWindow::listViews( ChildViewList *viewList ) { if( m_pChildFrame ) m_pChildFrame->listViews( viewList ); }
  4887. TQCString KonqMainWindow::frameType() { return TQCString("MainWindow"); }
  4888. KonqFrameBase* KonqMainWindow::childFrame()const { return m_pChildFrame; }
  4889. void KonqMainWindow::setActiveChild( KonqFrameBase* /*activeChild*/ ) { return; }
  4890. bool KonqMainWindow::isMimeTypeAssociatedWithSelf( const TQString &mimeType )
  4891. {
  4892. return isMimeTypeAssociatedWithSelf( mimeType, KServiceTypeProfile::preferredService( mimeType, "Application" ) );
  4893. }
  4894. bool KonqMainWindow::isMimeTypeAssociatedWithSelf( const TQString &/*mimeType*/, const KService::Ptr &offer )
  4895. {
  4896. // Prevention against user stupidity : if the associated app for this mimetype
  4897. // is konqueror/kfmclient, then we'll loop forever. So we have to
  4898. // 1) force embedding first, if that works we're ok
  4899. // 2) check what KRun is going to do before calling it.
  4900. return ( offer && ( offer->desktopEntryName() == "konqueror" ||
  4901. offer->exec().stripWhiteSpace().startsWith( "kfmclient" ) ) );
  4902. }
  4903. // KonqFrameContainerBase implementation END
  4904. void KonqMainWindow::setPreloadedFlag( bool preloaded )
  4905. {
  4906. if( s_preloaded == preloaded )
  4907. return;
  4908. s_preloaded = preloaded;
  4909. if( s_preloaded )
  4910. {
  4911. kapp->disableSessionManagement(); // dont restore preloaded konqy's
  4912. return; // was registered before calling this
  4913. }
  4914. delete s_preloadedWindow; // preloaded state was abandoned without reusing the window
  4915. s_preloadedWindow = NULL;
  4916. kapp->enableSessionManagement(); // enable SM again
  4917. DCOPRef ref( "kded", "konqy_preloader" );
  4918. ref.send( "unregisterPreloadedKonqy", kapp->dcopClient()->appId());
  4919. }
  4920. void KonqMainWindow::setPreloadedWindow( KonqMainWindow* window )
  4921. {
  4922. s_preloadedWindow = window;
  4923. if( window == NULL )
  4924. return;
  4925. window->viewManager()->clear();
  4926. TDEIO::Scheduler::unregisterWindow( TQT_TQOBJECT(window) );
  4927. }
  4928. // used by preloading - this KonqMainWindow will be reused, reset everything
  4929. // that won't be reset by loading a profile
  4930. void KonqMainWindow::resetWindow()
  4931. {
  4932. char data[ 1 ];
  4933. // empty append to get current X timestamp
  4934. TQWidget tmp_widget;
  4935. XChangeProperty( tqt_xdisplay(), tmp_widget.winId(), XA_WM_CLASS, XA_STRING, 8,
  4936. PropModeAppend, (unsigned char*) &data, 0 );
  4937. XEvent ev;
  4938. XWindowEvent( tqt_xdisplay(), tmp_widget.winId(), PropertyChangeMask, &ev );
  4939. long x_time = ev.xproperty.time;
  4940. // bad hack - without updating the _TDE_NET_WM_USER_CREATION_TIME property,
  4941. // KWin will apply don't_steal_focus to this window, and will not make it active
  4942. // (shows mainly with 'konqueror --preload')
  4943. static Atom atom = XInternAtom( tqt_xdisplay(), "_TDE_NET_WM_USER_CREATION_TIME", False );
  4944. XChangeProperty( tqt_xdisplay(), winId(), atom, XA_CARDINAL, 32,
  4945. PropModeReplace, (unsigned char *) &x_time, 1);
  4946. SET_QT_X_USER_TIME(CurrentTime); // won't have _NET_WM_USER_TIME set
  4947. #if !KDE_IS_VERSION( 3, 2, 90 ) // _KDE_NET_USER_TIME is obsolete
  4948. static Atom atom2 = XInternAtom( tqt_xdisplay(), "_KDE_NET_USER_TIME", False );
  4949. timeval tv;
  4950. gettimeofday( &tv, NULL );
  4951. unsigned long now = tv.tv_sec * 10 + tv.tv_usec / 100000;
  4952. XChangeProperty(tqt_xdisplay(), winId(), atom2, XA_CARDINAL,
  4953. 32, PropModeReplace, (unsigned char *)&now, 1);
  4954. #endif
  4955. static Atom atom3 = XInternAtom( tqt_xdisplay(), "_NET_WM_USER_TIME", False );
  4956. XDeleteProperty( tqt_xdisplay(), winId(), atom3 );
  4957. // Qt remembers the iconic state if the window was withdrawn while on another virtual desktop
  4958. clearWState( WState_Minimized );
  4959. ignoreInitialGeometry();
  4960. kapp->setTopWidget( this ); // set again the default window icon
  4961. }
  4962. bool KonqMainWindow::event( TQEvent* e )
  4963. {
  4964. if( e->type() == TQEvent::DeferredDelete )
  4965. {
  4966. // since the preloading code tries to reuse KonqMainWindow,
  4967. // the last window shouldn't be really deleted, but only hidden
  4968. // deleting WDestructiveClose windows is done using deleteLater(),
  4969. // so catch TQEvent::DefferedDelete and check if this window should stay
  4970. if( stayPreloaded())
  4971. {
  4972. setWFlags(WDestructiveClose); // was reset before deleteLater()
  4973. return true; // no deleting
  4974. }
  4975. }
  4976. return KParts::MainWindow::event( e );
  4977. }
  4978. bool KonqMainWindow::stayPreloaded()
  4979. {
  4980. // last window?
  4981. if( mainWindowList()->count() > 1 )
  4982. return false;
  4983. // not running in full KDE environment?
  4984. if( getenv( "TDE_FULL_SESSION" ) == NULL || getenv( "TDE_FULL_SESSION" )[ 0 ] == '\0' )
  4985. return false;
  4986. // not the same user like the one running the session (most likely we're run via sudo or something)
  4987. if( getenv( "TDE_SESSION_UID" ) != NULL && uid_t( atoi( getenv( "TDE_SESSION_UID" ))) != getuid())
  4988. return false;
  4989. if( KonqSettings::maxPreloadCount() == 0 )
  4990. return false;
  4991. viewManager()->clear(); // reduce resource usage before checking it
  4992. if( !checkPreloadResourceUsage())
  4993. return false;
  4994. DCOPRef ref( "kded", "konqy_preloader" );
  4995. if( !ref.callExt( "registerPreloadedKonqy", DCOPRef::NoEventLoop, 5000,
  4996. kapp->dcopClient()->appId(), tqt_xscreen()))
  4997. {
  4998. return false;
  4999. }
  5000. KonqMainWindow::setPreloadedFlag( true );
  5001. kdDebug(1202) << "Konqy kept for preloading :" << kapp->dcopClient()->appId() << endl;
  5002. KonqMainWindow::setPreloadedWindow( this );
  5003. return true;
  5004. }
  5005. // try to avoid staying running when leaking too much memory
  5006. // this is checked by using mallinfo() and comparing
  5007. // memory usage during konqy startup and now, if the difference
  5008. // is too large -> leaks -> quit
  5009. // also, if this process is running for too long, or has been
  5010. // already reused too many times -> quit, just in case
  5011. bool KonqMainWindow::checkPreloadResourceUsage()
  5012. {
  5013. if(
  5014. #ifndef NDEBUG
  5015. isatty( STDIN_FILENO ) ||
  5016. #endif
  5017. isatty( STDOUT_FILENO ) || isatty( STDERR_FILENO ))
  5018. {
  5019. kdDebug(1202) << "Running from tty, not keeping for preloading" << endl;
  5020. return false;
  5021. }
  5022. int limit;
  5023. int usage = current_memory_usage( &limit );
  5024. kdDebug(1202) << "Memory usage increase: " << ( usage - s_initialMemoryUsage )
  5025. << " (" << usage << "/" << s_initialMemoryUsage << "), increase limit: " << limit << endl;
  5026. int max_allowed_usage = s_initialMemoryUsage + limit;
  5027. if( usage > max_allowed_usage ) // too much memory used?
  5028. {
  5029. kdDebug(1202) << "Not keeping for preloading due to high memory usage" << endl;
  5030. return false;
  5031. }
  5032. // working memory usage test ( usage != 0 ) makes others less strict
  5033. if( ++s_preloadUsageCount > ( usage != 0 ? 100 : 10 )) // reused too many times?
  5034. {
  5035. kdDebug(1202) << "Not keeping for preloading due to high usage count" << endl;
  5036. return false;
  5037. }
  5038. if( time( NULL ) > s_startupTime + 60 * 60 * ( usage != 0 ? 4 : 1 )) // running for too long?
  5039. {
  5040. kdDebug(1202) << "Not keeping for preloading due to long usage time" << endl;
  5041. return false;
  5042. }
  5043. return true;
  5044. }
  5045. static int current_memory_usage( int* limit )
  5046. {
  5047. #ifdef __linux__
  5048. // Check whole memory usage - VmSize
  5049. TQFile f( TQCString().sprintf( "/proc/%i/statm", getpid()));
  5050. if( f.open( IO_ReadOnly ))
  5051. {
  5052. TQString line;
  5053. if( f.readLine( line, 1024 ) > 0 )
  5054. {
  5055. line = line.stripWhiteSpace();
  5056. int usage = line.section( ' ', 0, 0 ).toInt();
  5057. if( usage > 0 )
  5058. {
  5059. int pagesize = sysconf (_SC_PAGE_SIZE);
  5060. if( pagesize < 0 )
  5061. pagesize = 4096;
  5062. if( limit != NULL )
  5063. *limit = 16 * 1024 * 1024;
  5064. return usage * pagesize;
  5065. }
  5066. }
  5067. }
  5068. kdWarning() << "Couldn't read VmSize from /proc/*/statm." << endl;
  5069. #endif
  5070. // Check malloc() usage - very imprecise, but better than nothing.
  5071. int usage_sum = 0;
  5072. #if defined(KDE_MALLINFO_STDLIB) || defined(KDE_MALLINFO_MALLOC)
  5073. // ugly hack for tdecore/malloc
  5074. extern int kde_malloc_is_used;
  5075. free( calloc( 4, 4 )); // trigger setting kde_malloc_is_used
  5076. if( kde_malloc_is_used )
  5077. {
  5078. struct mallinfo m = mallinfo();
  5079. usage_sum = m.hblkhd + m.uordblks;
  5080. }
  5081. else
  5082. {
  5083. struct mallinfo m = mallinfo();
  5084. #ifdef KDE_MALLINFO_FIELD_hblkhd
  5085. usage_sum += m.hblkhd;
  5086. #endif
  5087. #ifdef KDE_MALLINFO_FIELD_uordblks
  5088. usage_sum += m.uordblks;
  5089. #endif
  5090. #ifdef KDE_MALLINFO_FIELD_usmblks
  5091. usage_sum += m.usmblks;
  5092. #endif
  5093. }
  5094. // unlike /proc , this doesn't include things like size of dlopened modules,
  5095. // and also doesn't include malloc overhead
  5096. if( limit != NULL )
  5097. *limit = 6 * 1024 * 1024;
  5098. #endif
  5099. return usage_sum;
  5100. }
  5101. void KonqMainWindow::saveWindowSize() const
  5102. {
  5103. TQString savedGroup = TDEGlobal::config()->group();
  5104. TDEGlobal::config()->setGroup( "KonqMainWindow_Size" );
  5105. KParts::MainWindow::saveWindowSize( TDEGlobal::config() );
  5106. TDEGlobal::config()->setGroup( savedGroup );
  5107. TDEGlobal::config()->sync();
  5108. }
  5109. void KonqMainWindow::restoreWindowSize()
  5110. {
  5111. TQString savedGroup = TDEGlobal::config()->group();
  5112. TDEGlobal::config()->setGroup( "KonqMainWindow_Size" );
  5113. KParts::MainWindow::restoreWindowSize( TDEGlobal::config() );
  5114. TDEGlobal::config()->setGroup( savedGroup );
  5115. }
  5116. #include "konq_mainwindow.moc"
  5117. #include "konq_mainwindow_p.moc"
  5118. /* vim: et sw=4 ts=4
  5119. */